Refactor code structure for improved readability and maintainability

This commit is contained in:
John Doe
2026-05-09 16:35:25 +02:00
parent ac80210ba5
commit c7ff5ae4cf
12 changed files with 287 additions and 21 deletions
+28 -1
View File
@@ -196,6 +196,28 @@ def resolve_keybindings(preferred_profile=None, preferred_file=None, render_engi
class KeyBindings:
def _binding_sections_for_action(self):
game_end_active, game_end_reason = getattr(self, "game_end", (False, None))
if game_end_active:
if game_end_reason == "level_clear":
return ["keybinding_level_clear", "keybinding_paused"]
if game_end_reason == "defeat":
return ["keybinding_defeat", "keybinding_paused"]
if game_end_reason == "run_complete":
return ["keybinding_run_complete", "keybinding_paused"]
return ["keybinding_paused"]
if getattr(self, "game_status", None) == "start_menu":
if getattr(self, "menu_screen", None) == "level_intro":
return ["keybinding_level_intro", "keybinding_start_menu"]
return ["keybinding_start_menu"]
status = getattr(self, "game_status", None)
if status:
return [f"keybinding_{status}"]
return []
def initialize_keybindings(self):
preferred_profile = None
preferred_file = None
@@ -253,7 +275,12 @@ class KeyBindings:
if not hasattr(self, "bindings"):
self.initialize_keybindings()
value = self.bindings.get(f"keybinding_{self.game_status}", {}).get(action)
value = None
for section_name in self._binding_sections_for_action():
value = self.bindings.get(section_name, {}).get(action)
if value:
break
if not value:
return None