aboutsummaryrefslogtreecommitdiff
path: root/src/splitscreen_duo/menu.py
diff options
context:
space:
mode:
authorZoltan Szabatin <[email protected]>2025-03-02 17:41:20 -0800
committerZoltan Szabatin <[email protected]>2025-03-02 17:41:20 -0800
commit47ce41308a2c9ff65c8b59d641ddde19134fb167 (patch)
tree98ce7f3771dc7a6e5e8bf494090811576907cc06 /src/splitscreen_duo/menu.py
parentrefactor: Move serial and Pygame definitions up in hierarchy (diff)
downloadsplitscreen-duo-47ce41308a2c9ff65c8b59d641ddde19134fb167.tar.xz
splitscreen-duo-47ce41308a2c9ff65c8b59d641ddde19134fb167.zip
refactor: Move serial controller up hierarchy
Diffstat (limited to 'src/splitscreen_duo/menu.py')
-rw-r--r--src/splitscreen_duo/menu.py50
1 files changed, 21 insertions, 29 deletions
diff --git a/src/splitscreen_duo/menu.py b/src/splitscreen_duo/menu.py
index 8962c5d..7934696 100644
--- a/src/splitscreen_duo/menu.py
+++ b/src/splitscreen_duo/menu.py
@@ -10,6 +10,7 @@ BLACK = (0, 0, 0)
IS_DEVELOPMENT_MODE = os.getenv("DEVELOPMENT", "").lower() != ""
OPTIONS = ["Breakout", "Pong v.s. Computer", "Snake", "Quit"]
logger = logging.getLogger(__name__)
+WIDTH = HEIGHT = FONT = screen = selected_index = None
def init_display():
@@ -38,40 +39,31 @@ def draw_menu():
pygame.display.flip()
-def main_loop(serial, instance):
- init_display()
-
+def process_events(serial, instance):
global selected_index
- is_running = True
input_handler = Input(debug=IS_DEVELOPMENT_MODE)
- while is_running:
- draw_menu()
-
- if instance == "secondary":
- if serial.in_waiting() > 0:
- logger.debug(serial.readline().decode("utf-8").strip())
-
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ return {"command": 0, "action": "QUIT_ALL"}
- action = input_handler.get_input(event)
+ action = input_handler.get_input(event)
- if action == "UP":
- selected_index = (selected_index - 1) % len(OPTIONS)
- elif action == "DOWN":
- selected_index = (selected_index + 1) % len(OPTIONS)
- elif action == "SELECT":
- if OPTIONS[selected_index] == "Quit":
+ if action == "UP":
+ selected_index = (selected_index - 1) % len(OPTIONS)
+ elif action == "DOWN":
+ selected_index = (selected_index + 1) % len(OPTIONS)
+ elif action == "SELECT":
+ if OPTIONS[selected_index] == "Quit":
+ if instance == "primary":
+ return {"command": 0, "action": "QUIT_ALL"}
+ else:
pygame.quit()
sys.exit()
- else:
- serial.write(
- json.dumps({"command": 0, "action": action}).encode("utf-8")
- )
- elif action == "QUIT":
- pygame.quit()
- sys.exit()
+ else:
+ return {"command": 0, "action": OPTIONS[selected_index]}
+ elif action == "QUIT":
+ return {"command": 0, "action": "QUIT_ALL"}
+
+ return None