From 7fce31b4c16b25ba1892fadcc8ef48ef25f73d39 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 10 Sep 2016 21:47:03 +0200 Subject: [PATCH] Serialize light state across day and night transitions --- tabakrolletjie/gamestate.py | 3 +++ tabakrolletjie/scenes/day.py | 1 + tabakrolletjie/scenes/night.py | 9 +++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tabakrolletjie/gamestate.py b/tabakrolletjie/gamestate.py index 9fe4fc8..6f6725b 100644 --- a/tabakrolletjie/gamestate.py +++ b/tabakrolletjie/gamestate.py @@ -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() diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index be86425..e2d1e19 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -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()) diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index 580d140..9459c0e 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -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()) -- 2.34.1