Serialize light state across day and night transitions
authorNeil <neil@dip.sun.ac.za>
Sat, 10 Sep 2016 19:47:03 +0000 (21:47 +0200)
committerNeil <neil@dip.sun.ac.za>
Sat, 10 Sep 2016 19:47:11 +0000 (21:47 +0200)
tabakrolletjie/gamestate.py
tabakrolletjie/scenes/day.py
tabakrolletjie/scenes/night.py

index 9fe4fc85d3557ea0d991a48e664c3627b0912bf3..6f6725b8e0bda36ef5a031946306194d0496b0e2 100644 (file)
@@ -52,3 +52,6 @@ class GameState(object):
     @property
     def turnip_target(self):
         return self._state["station"]["config"]["turnip target"]
+
+    def update_lights(self, lights):
+        self._state["station"]["lights"] = lights.serialize_lights()
index be8642509d5a4418a74e53c550e3bfef09a12e7e..e2d1e19bcb6634b62366fb83efe1bad7fafbbb94 100644 (file)
@@ -129,6 +129,7 @@ class DayScene(BaseScene):
 
     def end_day(self, gamestate):
         self._battery.apply_recharge()
+        gamestate.update_lights(self._lights)
         from .night import NightScene
         SceneChangeEvent.post(scene=NightScene())
 
index 580d140a6941475cfeefc1f295e2b51ec82312b7..9459c0ed68668d6edb358879ca93917ab9c75a76 100644 (file)
@@ -108,7 +108,7 @@ class NightScene(BaseScene):
         if ev.type == pgl.KEYDOWN:
             if not self._do_ticks:
                 # Any keypress exits
-                self._to_day()
+                self._to_day(gamestate)
             if ev.key in (pgl.K_q, pgl.K_ESCAPE):
                 from .menu import MenuScene
                 SceneChangeEvent.post(scene=MenuScene())
@@ -119,7 +119,7 @@ class NightScene(BaseScene):
         elif ev.type == pgl.MOUSEBUTTONDOWN:
             if not self._do_ticks:
                 # Any mouse press exits
-                self._to_day()
+                self._to_day(gamestate)
             if ev.button == 1:
                 self._lights.toggle_nearest(ev.pos, surfpos=True)
 
@@ -132,7 +132,7 @@ class NightScene(BaseScene):
                             from .menu import MenuScene
                             SceneChangeEvent.post(scene=MenuScene())
                         elif tool.name == 'day':
-                            self._to_day()
+                            self._to_day(gamestate)
 
     def toggle_pause(self):
         self._paused = not self._paused
@@ -141,8 +141,9 @@ class NightScene(BaseScene):
             if tool.name == 'pause play':
                 tool.update_image("32", pause_img)
 
-    def _to_day(self):
+    def _to_day(self, gamestate):
         # End the night
+        gamestate.update_lights(self._lights)
         from .day import DayScene
         SceneChangeEvent.post(scene=DayScene())