Skip to content

Commit

Permalink
Complete refactor of repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Chirlin committed Feb 11, 2024
1 parent 552e7a6 commit 42b1099
Show file tree
Hide file tree
Showing 56 changed files with 3,821 additions and 4,183 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENV=dev
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ __pycache__/
# C extensions
*.so

# Intellij
.idea/

# Distribution / packaging
.Python
env/
Expand Down Expand Up @@ -70,7 +73,6 @@ audio/Menu/music
!audio/Joust/music/classical.wav

#other stuff
*.ini
*.yaml
*.DS_Store
apfiles/ap_active
Expand Down
File renamed without changes.
Binary file added audio/Commander/vox/aaron/power_ready.wav
Binary file not shown.
File renamed without changes.
Binary file added audio/Commander/vox/ivy/power_ready.wav
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file modified audio/Fight_Club/vox/aaron/game_over.wav
Binary file not shown.
Binary file modified audio/Fight_Club/vox/ivy/game_over.wav
Binary file not shown.
File renamed without changes.
Binary file added audio/Joust/sounds/wolfdown.wav
Binary file not shown.
Binary file added audio/Joust/vox/aaron/congratulations.wav
Binary file not shown.
Binary file added audio/Joust/vox/aaron/game_over.wav
Binary file not shown.
Binary file added audio/Joust/vox/aaron/traitor_intro.wav
Binary file not shown.
Binary file added audio/Joust/vox/aaron/werewolf intro_1.wav
Binary file not shown.
Binary file added audio/Joust/vox/ivy/congratulations.wav
Binary file not shown.
Binary file added audio/Joust/vox/ivy/game_over.wav
Binary file not shown.
Binary file added audio/Joust/vox/ivy/traitor_intro.wav
Binary file not shown.
Binary file added audio/Joust/vox/ivy/werewolf intro_1.wav
Binary file not shown.
Binary file modified audio/Zombie/vox/aaron/zombie_death.wav
Binary file not shown.
Binary file modified audio/Zombie/vox/ivy/zombie_death.wav
Binary file not shown.
Empty file added audio/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions audio/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# How fast/slow the music can go
SLOW_MUSIC_SPEED = 1.0
#this was 0.5
FAST_MUSIC_SPEED = 1.3

# The min and max timeframe in seconds for
# the speed change to trigger, randomly selected
MIN_MUSIC_FAST_TIME = 4
MAX_MUSIC_FAST_TIME = 8
MIN_MUSIC_SLOW_TIME = 10
MAX_MUSIC_SLOW_TIME = 23

END_MIN_MUSIC_FAST_TIME = 6
END_MAX_MUSIC_FAST_TIME = 10
END_MIN_MUSIC_SLOW_TIME = 8
END_MAX_MUSIC_SLOW_TIME = 12

#How long the speed change takes
INTERVAL_CHANGE = 1.5

#How long the winning moves shall sparkle
END_GAME_PAUSE = 8
KILL_GAME_PAUSE = 4
23 changes: 23 additions & 0 deletions base_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import logging
from logging import RotatingFileHandler

#TODO - Read logging level from file)

# Configure logging
log_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
log_file = 'piparty.log'

# Create a rotating file handler with a maximum file size of 1 MB and keep 3 backup copies
rotating_handler = RotatingFileHandler(log_file, maxBytes=1e6, backupCount=3)
rotating_handler.setFormatter(log_formatter)

logging.basicConfig(
level=logging.DEBUG, # Set the global logging level
format='%(asctime)s - %(levelname)s - %(message)s', # Specify the log message format
handlers=[
logging.StreamHandler(), # Output logs to the console
rotating_handler # Output logs to a rotating log file
]
)

logger = logging
17 changes: 11 additions & 6 deletions colors.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import psmove
import colorsys
import time
from enum import Enum
import random


color_range = 255

def darken_color(color_array, factor):
factor = max(0, min(factor, 1))

# Scale down each color channel
return tuple(int(channel * (1 - factor)) for channel in color_array)

def hsv2rgb(h, s, v):
return tuple(int(color * color_range) for color in colorsys.hsv_to_rgb(h, s, v))

Expand All @@ -26,7 +29,7 @@ def generate_team_colors(num_teams, color_lock=False, color_lock_choices=None):
if num_teams == 2:
team1 = random.choice(team_color_list)
team2 = random.choice(dual_teams[team1])
return [team1,team2]
return [team1, team2]
elif num_teams == 3:
team1 = random.choice(team_color_list)
team2 = random.choice(tri_teams[team1])
Expand Down Expand Up @@ -71,17 +74,19 @@ class Colors(Enum):
White60 = (150,150,150)
White40 = (100,100,100)
White20 = (50,50,50)
White10 = (10,10,10)
Red = (255,0,0)
Red60 = (150,0,0)
Red80 = (200,0,0)
Green80 = (0,200,0)
Green20 = (0,50,0)
Blue40 = (0,0,100)
LimeGreen = (100,255,0)
Zombie = (50,150,50)
Black = (0,0,0)
#stay fresh
SplatoonGreen = (255,50,120)
SplatoonPink = (30,220,0)
SplatoonGreen = (30,220,0)
SplatoonPink = (255,50,120)

team_color_list = [x for x in Colors][0:8]
ordered_color_list = [Colors.Blue,Colors.Yellow,Colors.Green,Colors.Orange,Colors.Purple,
Expand Down
106 changes: 54 additions & 52 deletions common.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,14 @@
import asyncio
import colorsys
import enum
from enum import Enum, Flag
import functools
import psmove
import time
import traceback
import random
import logging

SETTINGSFILE = 'joustsettings.yaml'

#Human speeds[slow, mid, fast]
#SLOW_WARNING = [0.1, 0.15, 0.28]
#SLOW_MAX = [0.25, 0.8, 1]
#FAST_WARNING = [0.5, 0.6, 0.8]
#FAST_MAX = [1, 1.4, 1.8]

SLOW_WARNING = [1.2, 1.3, 1.6, 2.0, 2.5]
SLOW_MAX = [1.3, 1.5, 1.8, 2.5, 3.2]
FAST_WARNING = [1.4, 1.6, 1.9, 2.7, 2.8]
FAST_MAX = [1.6, 1.8, 2.8, 3.2, 3.5]

#WERE_SLOW_WARNING = [0.2, 0.3, 0.4]
#WERE_SLOW_MAX = [0.7, 0.9, 1.1]
#WERE_FAST_WARNING = [0.6, 0.7, 0.9]
#WERE_FAST_MAX = [1.1, 1.5, 2.0]

WERE_SLOW_WARNING = [1.2, 1.4, 1.7, 2.1, 2.9]
WERE_SLOW_MAX = [1.3, 1.6, 1.9, 2.6, 3.9]
WERE_FAST_WARNING = [1.4, 1.7, 2.0, 2.8, 3.5]
WERE_FAST_MAX = [1.6, 1.9, 2.9, 3.3, 4.9]

#ZOMBIE_WARNING = [0.5, 0.6, 0.8]
#ZOMBIE_MAX = [0.8, 1, 1.4]

ZOMBIE_WARNING = [1.2, 1.5, 1.8, 2.6, 2.7]
ZOMBIE_MAX = [1.4, 1.7, 2.7, 3.1, 3.4]
logger = logging.getLogger(__name__)

SETTINGSFILE = 'joustsettings.yaml'

def get_move(serial, move_num):
time.sleep(0.02)
Expand All @@ -52,14 +25,14 @@ def get_move(serial, move_num):
return move

def lerp(a, b, p):
return a*(1 - p) + b*p
return a * (1 - p) + b * p

class Games(enum.Enum):
class Games(Enum):
JoustFFA = (0, 'Joust Free-for-All', 2)
JoustTeams = (1, 'Joust Teams', 3)
JoustRandomTeams = (2, 'Joust Random Teams', 3)
Traitor = (3, 'Traitors', 6)
WereJoust = (4, 'Werewolves', 3)
Traitor = (3, 'Traitors', 4)
Werewolf = (4, 'Werewolf', 3)
Zombies = (5, 'Zombies', 4)
Commander = (6, 'Commander', 4)
Swapper = (7, 'Swapper', 3)
Expand All @@ -69,7 +42,6 @@ class Games(enum.Enum):
Ninja = (11, 'Ninja Bomb', 2)
Random = (12, 'Random', 2)


def __new__(cls, value, pretty_name, min_players):
"""This odd constructor lets us keep Foo.value as an integer, but also
add some extra properties to each option."""
Expand All @@ -86,10 +58,40 @@ def next(self):
def previous(self):
"""Return the previous game mode after this one in the list. Wraps around after hitting bottom."""
return Games((self.value - 1) % len(Games))
class Status(Enum):
ALIVE = 0 # Tracking move and can be killed
DIED = 1 # Just died, will move to dead
DEAD = 2 # Dead, will revive if enabled
REVIVED = 3 # Just revived and will play sound
RUMBLE = 4 # Will rumble
ON = 5 # Team color and not polling
OFF = 6 # Black and not polling


# All common opts will be 0-5, custom opts should be 6+
class Opts(Enum):
BUTTON = 0 # Buttons that are currently pressed TODO - Not being used
HOLDING = 1 # Whether buttons are being held
SELECTION = 2 # What those buttons represent for this game
STATUS = 3 # Status of the move

# Sensitivity levels
class Sensitivity(Enum):
ULTRA_SLOW = 0
SLOW = 1
MID = 2
FAST = 3
ULTRA_FAST = 4

def get_game_name(value):
for game in Games:
if game.value == value:
return game.pretty_name
return None

#These buttons are based off of
#The mapping of PS Move controllers
class Button(enum.Flag):
class Button(Flag):
NONE = 0

TRIANGLE = psmove.Btn_TRIANGLE
Expand Down Expand Up @@ -122,7 +124,7 @@ class Button(enum.Flag):

# Common colors lifted from https://xkcd.com/color/rgb/
# TODO: Add more colors -- probably need to have 14 player colors at least.
class Color(enum.Enum):
class Color(Enum):
BLACK = 0x000000
WHITE = 0xffffff
RED = 0xff0000
Expand Down Expand Up @@ -178,18 +180,18 @@ def __str__(self):
FREEZE_PACE = GamePace(tempo=0, warn_threshold=1.1, death_threshold=1.2)

REQUIRED_SETTINGS = [
'play_audio',
'move_can_be_admin',
'current_game',
'enforce_minimum',
'sensitivity',
'play_instructions',
'random_modes',
'color_lock',
'color_lock_choices',
'red_on_kill',
'random_teams',
'menu_voice',
'random_team_size',
'force_all_start',
'play_audio',
'move_can_be_admin',
'current_game',
'enforce_minimum',
'sensitivity',
'play_instructions',
'random_modes',
'color_lock',
'color_lock_choices',
'red_on_kill',
'random_teams',
'menu_voice',
'random_team_size',
'force_all_start',
]
35 changes: 35 additions & 0 deletions conf/logging.dev.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[loggers]
keys=root,file

[handlers]
keys=console,file

[formatters]
keys=console,file

[logger_root]
level=DEBUG
handlers=console,file

[logger_file]
level=DEBUG
handlers=file
qualname=file

[handler_console]
class=StreamHandler
level=DEBUG
formatter=console
args=(sys.stdout,)

[handler_file]
class=FileHandler
level=DEBUG
formatter=file
args=('%(logfilename)s','w',)

[formatter_console]
format=%(asctime)s - %(levelname)s - %(name)s - %(message)s

[formatter_file]
format=%(asctime)s - %(levelname)s - %(name)s - %(funcName)s:%(lineno)d - %(message)s
Loading

0 comments on commit 42b1099

Please sign in to comment.