Add Ctrl+Return cheat to instantly win the current level
During gameplay, pressing Ctrl+Return triggers an immediate level clear: the current level is marked as won (level_clear, or run_complete on the last DAT level) and the state transitions to VICTORY, showing the normal 'Level Clear!' dialog so the player can then advance with Return. Implementation: - engine/sdl2.py: mainloop detects Ctrl+Return via SDLK_RETURN + KMOD_CTRL and dispatches a 'cheat_win_level' action (bypassing keybindings). - engine/controls.py: trigger() now also accepts direct action names that are registered in the dispatcher (not key-event names), and a new cheat_win_level handler forwards to the game. - rats.py: MiceMaze.cheat_win_level() performs the win, guarded so it only fires while a level is actively being played. No keybinding files need editing; the cheat is wired through the engine layer directly.
This commit is contained in:
@@ -211,6 +211,7 @@ class KeyBindings:
|
||||
"toggle_pause": self.toggle_pause,
|
||||
"toggle_full_screen": self.toggle_full_screen,
|
||||
"quit_game": self.quit_game,
|
||||
"cheat_win_level": self.cheat_win_level,
|
||||
"menu_up": self.game.menu_up,
|
||||
"menu_down": self.game.menu_down,
|
||||
"menu_left": self.game.menu_left,
|
||||
@@ -298,6 +299,17 @@ class KeyBindings:
|
||||
if not self.bindings:
|
||||
self.initialize_keybindings()
|
||||
|
||||
# Direct action dispatch: if the action name itself is a registered
|
||||
# dispatcher entry (e.g. cheat actions injected by the engine layer),
|
||||
# invoke it without requiring a keybinding entry.
|
||||
direct_method = self.action_dispatcher.get(action)
|
||||
if direct_method is not None and action not in ("spawn_rat",):
|
||||
# Only treat as direct when the action isn't also a normal key event
|
||||
# name. Key events look like "keydown_*" / "keyup_*" / etc.
|
||||
if not action.startswith(("keydown_", "keyup_", "joybutton", "joyhat", "controller", "mousemove")):
|
||||
direct_method()
|
||||
return None
|
||||
|
||||
value = None
|
||||
for section_name in self._binding_sections_for_action():
|
||||
value = self.bindings.get(section_name, {}).get(action)
|
||||
@@ -319,6 +331,11 @@ class KeyBindings:
|
||||
method()
|
||||
return None
|
||||
|
||||
def cheat_win_level(self):
|
||||
"""Cheat handler: win the current level instantly (Ctrl+Return)."""
|
||||
if hasattr(self.game, "cheat_win_level"):
|
||||
self.game.cheat_win_level()
|
||||
|
||||
def spawn_rat(self):
|
||||
self.game.unit_manager.spawn_rat()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user