Skip to content
Snippets Groups Projects

Resolve "Beep on button for audio sync"

Merged Fabian Heinrich requested to merge 94-beep-on-button-for-audio-sync into 91-game-flow
4 files
+ 38
5
Compare changes
  • Side-by-side
  • Inline
Files
4
import argparse
import argparse
import dataclasses
import dataclasses
import glob
import json
import json
import logging
import logging
import random
import random
@@ -14,6 +13,7 @@ import numpy as np
@@ -14,6 +13,7 @@ import numpy as np
import pygame
import pygame
import pygame_gui
import pygame_gui
import requests
import requests
 
import simpleaudio
import yaml
import yaml
from websockets.sync.client import connect
from websockets.sync.client import connect
@@ -155,6 +155,8 @@ class PyGameGUI:
@@ -155,6 +155,8 @@ class PyGameGUI:
self.sub_processes = []
self.sub_processes = []
 
self.beeped_once = False
 
def get_window_sizes_from_state(self, state: dict):
def get_window_sizes_from_state(self, state: dict):
self.kitchen_width = state["kitchen"]["width"]
self.kitchen_width = state["kitchen"]["width"]
self.kitchen_height = state["kitchen"]["height"]
self.kitchen_height = state["kitchen"]["height"]
@@ -382,7 +384,12 @@ class PyGameGUI:
@@ -382,7 +384,12 @@ class PyGameGUI:
self.layout_file_paths = {
self.layout_file_paths = {
str(p.name): p
str(p.name): p
for p in [Path(f) for f in sorted((ROOT_DIR / "game_content" / "layouts").rglob("*.layout"))]
for p in [
 
Path(f)
 
for f in sorted(
 
(ROOT_DIR / "game_content" / "layouts").rglob("*.layout")
 
)
 
]
}
}
assert len(self.layout_file_paths) != 0, "No layout files."
assert len(self.layout_file_paths) != 0, "No layout files."
@@ -1016,6 +1023,13 @@ class PyGameGUI:
@@ -1016,6 +1023,13 @@ class PyGameGUI:
for websocket in self.websockets.values():
for websocket in self.websockets.values():
websocket.close()
websocket.close()
 
def play_bell_sound(self):
 
wave_obj = simpleaudio.WaveObject.from_wave_file(
 
str(ROOT_DIR / "gui_2d_vis" / "sync_bell_project.wav")
 
)
 
wave_obj.play()
 
log.log(logging.INFO, "Started game, played bell sound")
 
def start_pygame(self):
def start_pygame(self):
"""Starts pygame and the gui loop. Each frame the game state is visualized and keyboard inputs are read."""
"""Starts pygame and the gui loop. Each frame the game state is visualized and keyboard inputs are read."""
log.debug(f"Starting pygame gui at {self.FPS} fps")
log.debug(f"Starting pygame gui at {self.FPS} fps")
@@ -1143,6 +1157,10 @@ class PyGameGUI:
@@ -1143,6 +1157,10 @@ class PyGameGUI:
case MenuStates.Game:
case MenuStates.Game:
state = self.request_state()
state = self.request_state()
 
if not self.beeped_once and state["play_beep"]:
 
self.beeped_once = True
 
self.play_bell_sound()
 
self.handle_keys()
self.handle_keys()
if state["ended"]:
if state["ended"]:
Loading