diff --git a/libs/global_data.py b/libs/global_data.py index 94dcd05..850a621 100644 --- a/libs/global_data.py +++ b/libs/global_data.py @@ -52,23 +52,23 @@ class PathsConfig(TypedDict): video_path: list[Path] class KeysConfig(TypedDict): - exit_key: str - fullscreen_key: str - borderless_key: str - back_key: str - restart_key: str + exit_key: int + fullscreen_key: int + borderless_key: int + back_key: int + restart_key: int class Keys1PConfig(TypedDict): - left_kat: list[str] - left_don: list[str] - right_don: list[str] - right_kat: list[str] + left_kat: list[int] + left_don: list[int] + right_don: list[int] + right_kat: list[int] class Keys2PConfig(TypedDict): - left_kat: list[str] - left_don: list[str] - right_don: list[str] - right_kat: list[str] + left_kat: list[int] + left_don: list[int] + right_don: list[int] + right_kat: list[int] class GamepadConfig(TypedDict): left_kat: list[int] diff --git a/libs/utils.py b/libs/utils.py index bd72c99..37d9ad4 100644 --- a/libs/utils.py +++ b/libs/utils.py @@ -82,6 +82,16 @@ def get_config() -> Config: config_file = tomlkit.load(f) config: Config = json.loads(json.dumps(config_file)) + for key in config['keys']: + config[key] = get_key_code(config['keys'][key]) + for key in config['keys_1p']: + bindings = config['keys_1p'][key] + for i, bind in enumerate(bindings): + config['keys_1p'][key][i] = get_key_code(bind) + for key in config['keys_2p']: + bindings = config['keys_2p'][key] + for i, bind in enumerate(bindings): + config['keys_2p'][key][i] = get_key_code(bind) return config def save_config(config: Config) -> None: @@ -102,13 +112,11 @@ def get_key_code(key: str) -> int: raise ValueError(f"Invalid key: {key}") return key_code -def is_input_key_pressed(keys: list[str], gamepad_buttons: list[int]): +def is_input_key_pressed(keys: list[int], gamepad_buttons: list[int]): if global_data.input_locked: return False for key in keys: - key_code = get_key_code(key) - - if ray.is_key_pressed(key_code): + if ray.is_key_pressed(key): return True if ray.is_gamepad_available(0): diff --git a/scenes/game.py b/scenes/game.py index d34bc06..a7d9519 100644 --- a/scenes/game.py +++ b/scenes/game.py @@ -229,14 +229,14 @@ class GameScreen(Screen): self.start_ms = get_current_ms() - self.pause_time def global_keys(self): - if ray.is_key_pressed(get_key_code(global_data.config["keys"]["restart_key"])): + if ray.is_key_pressed(global_data.config["keys"]["restart_key"]): if self.song_music is not None: audio.stop_music_stream(self.song_music) self.init_tja(global_data.session_data[global_data.player_num].selected_song) audio.play_sound('restart', 'sound') self.song_started = False - if ray.is_key_pressed(get_key_code(global_data.config["keys"]["back_key"])): + if ray.is_key_pressed(global_data.config["keys"]["back_key"]): if self.song_music is not None: audio.stop_music_stream(self.song_music) return self.on_screen_end('SONG_SELECT') @@ -626,7 +626,7 @@ class Player: return if isinstance(self.current_notes_draw[0], Drumroll): - self.current_notes_draw[0].color = max(255, self.current_notes_draw[0].color + 1) + self.current_notes_draw[0].color = min(255, self.current_notes_draw[0].color + 1) note = self.current_notes_draw[0] if note.type in {NoteType.ROLL_HEAD, NoteType.ROLL_HEAD_L, NoteType.BALLOON_HEAD, NoteType.KUSUDAMA} and len(self.current_notes_draw) > 1: