aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoltan Szabatin <[email protected]>2025-03-02 17:55:18 -0800
committerZoltan Szabatin <[email protected]>2025-03-02 17:55:18 -0800
commit4802f7f9d965c1014c710aeb024d090845a5b7bf (patch)
treec572d87616d6c82af35d829fc9fb2745552d29b8
parentrefactor: Move serial controller up hierarchy (diff)
downloadsplitscreen-duo-4802f7f9d965c1014c710aeb024d090845a5b7bf.tar.xz
splitscreen-duo-4802f7f9d965c1014c710aeb024d090845a5b7bf.zip
feat: Add proper command options
-rw-r--r--src/splitscreen_duo/__init__.py9
-rw-r--r--src/splitscreen_duo/command.py6
-rw-r--r--src/splitscreen_duo/menu.py18
3 files changed, 24 insertions, 9 deletions
diff --git a/src/splitscreen_duo/__init__.py b/src/splitscreen_duo/__init__.py
index 90d54ab..e47c7cb 100644
--- a/src/splitscreen_duo/__init__.py
+++ b/src/splitscreen_duo/__init__.py
@@ -1,4 +1,5 @@
from . import menu
+from .command import Command
import os
import logging
import pygame
@@ -32,8 +33,8 @@ def main() -> int:
message = json.loads(data)
- if message.get("action") == "QUIT_ALL":
- logger.info("received quit_all command from primary, shutting down")
+ if message.get("command") == Command.QUIT.value:
+ logger.info("received quit command from primary, shutting down")
pygame.quit()
return 0
@@ -49,8 +50,8 @@ def main() -> int:
if serial_command:
serial.write(json.dumps(serial_command).encode("utf-8"))
- if serial_command.get("action") == "QUIT_ALL":
- logger.info("primary sent quit_all, shutting down")
+ if serial_command.get("command") == Command.QUIT.value:
+ logger.info("primary sent quit, shutting down")
pygame.quit()
return 0
diff --git a/src/splitscreen_duo/command.py b/src/splitscreen_duo/command.py
new file mode 100644
index 0000000..df42a5a
--- /dev/null
+++ b/src/splitscreen_duo/command.py
@@ -0,0 +1,6 @@
+from enum import Enum
+
+
+class Command(Enum):
+ QUIT = 0
+ SELECT_GAME = 1
diff --git a/src/splitscreen_duo/menu.py b/src/splitscreen_duo/menu.py
index 7934696..76114e2 100644
--- a/src/splitscreen_duo/menu.py
+++ b/src/splitscreen_duo/menu.py
@@ -2,6 +2,7 @@ import sys
import pygame
import os
from .input import Input
+from .command import Command
import logging
import json
@@ -15,7 +16,6 @@ WIDTH = HEIGHT = FONT = screen = selected_index = None
def init_display():
global WIDTH, HEIGHT, FONT, screen, selected_index
-
WIDTH, HEIGHT = (
pygame.display.Info().current_w // 2,
pygame.display.Info().current_h // 2,
@@ -46,7 +46,7 @@ def process_events(serial, instance):
for event in pygame.event.get():
if event.type == pygame.QUIT:
- return {"command": 0, "action": "QUIT_ALL"}
+ return {"command": Command.QUIT.value, "action": None, "value": None}
action = input_handler.get_input(event)
@@ -57,13 +57,21 @@ def process_events(serial, instance):
elif action == "SELECT":
if OPTIONS[selected_index] == "Quit":
if instance == "primary":
- return {"command": 0, "action": "QUIT_ALL"}
+ return {
+ "command": Command.QUIT.value,
+ "action": None,
+ "value": None,
+ }
else:
pygame.quit()
sys.exit()
else:
- return {"command": 0, "action": OPTIONS[selected_index]}
+ return {
+ "command": Command.SELECT_GAME.value,
+ "action": None,
+ "value": OPTIONS[selected_index],
+ }
elif action == "QUIT":
- return {"command": 0, "action": "QUIT_ALL"}
+ return {"command": Command.QUIT.value, "action": None, "value": None}
return None