Refactor code structure for improved readability and maintainability
This commit is contained in:
+28
-1
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user