From: Neil Date: Sat, 10 Sep 2016 19:47:03 +0000 (+0200) Subject: Serialize light state across day and night transitions X-Git-Tag: tabakrolletjie-v1.0.0~47 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=7fce31b4c16b25ba1892fadcc8ef48ef25f73d39;p=tabakrolletjie.git Serialize light state across day and night transitions --- 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())