Update the menu.
authorSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 16:42:51 +0000 (18:42 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 16:42:51 +0000 (18:42 +0200)
koperkapel/scenes/menu.py
koperkapel/world.py

index a902d3ab3aa9be265a7c5f016ddf919132f0cc09..65128b9e49d3184028320914508063cbc727c877 100644 (file)
@@ -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())]
index befc1a0a6b6d22ac51c9a46133a01309315c42ae..7115194c87e57d6cc299eda89850714172615126 100644 (file)
@@ -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):