From fa0ff98d6c1a2966313684d8b4372167f3f8a2b2 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 5 Mar 2016 18:42:51 +0200 Subject: [PATCH] Update the menu. --- koperkapel/scenes/menu.py | 21 +++++++-------------- koperkapel/world.py | 13 +++++++++---- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/koperkapel/scenes/menu.py b/koperkapel/scenes/menu.py index a902d3a..65128b9 100644 --- a/koperkapel/scenes/menu.py +++ b/koperkapel/scenes/menu.py @@ -15,11 +15,8 @@ class MenuScene(Scene): self._title.pos = (300, 100) self._nav = ActorNavigator() self._menu = [ - TextButton("Play", action=self.change_to_level), - TextButton("View Last Generated Level", - action=self.change_to_viewer), - TextButton("Manage Roaches", - action=self.change_to_roach_management), + TextButton("New Game", action=self.change_to_new_game), + TextButton("Resume", action=self.change_to_resume), TextButton("Credits", action=self.change_to_credits), TextButton("Quit", action=self.quit), ] @@ -31,21 +28,17 @@ class MenuScene(Scene): wrap=True) self._nav.current.select() - def change_to_level(self): + def change_to_resume(self): from .level import GameLevelScene return [ChangeSceneEvent(GameLevelScene())] - def change_to_viewer(self): - from .viewlevel import ViewLevelScene + def change_to_new_game(self): + from .level import GameLevelScene return [ - WorldEvent("set", {"level.name": "map"}), - ChangeSceneEvent(ViewLevelScene()) + WorldEvent("reset"), + ChangeSceneEvent(GameLevelScene()) ] - def change_to_roach_management(self): - from .roach_management import RoachesScene - return [ChangeSceneEvent(RoachesScene())] - def change_to_credits(self): from .credits import CreditsScene return [ChangeSceneEvent(CreditsScene())] diff --git a/koperkapel/world.py b/koperkapel/world.py index befc1a0..7115194 100644 --- a/koperkapel/world.py +++ b/koperkapel/world.py @@ -80,7 +80,7 @@ class World: roach.update(kw) return roach - def _apply_set(self, updates): + def _apply_set(self, action, updates): for name, value in updates.items(): parts = name.split(".") obj = self._state @@ -93,6 +93,12 @@ class World: raise KeyError("%r not found in world" % (name,)) obj[parts[-1]] = value + def _apply_reset(self, action): + self._state = self._build_initial_state() + + def _apply_unknown(self, action, *args, **kw): + raise ValueError("Unknown world event action: %r" % (action,)) + def proxy(self): return WorldDictProxy(self._state) @@ -105,9 +111,8 @@ class World: break def apply_event(self, action, *args, **kw): - if action == "set": - return self._apply_set(*args, **kw) - raise ValueError("Unknown world event action: %r" % (action,)) + handler = getattr(self, "_apply_%s" % (action,)) + return handler(action, *args, **kw) def _maybe_subproxy(proxy, name, value): -- 2.34.1