From 6f2903d031718b0c61cac95550721818a094238d Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 11 Sep 2016 00:48:05 +0200 Subject: [PATCH] Move turnip growth and related updates to the end of the night --- tabakrolletjie/scenes/day.py | 21 ++++++--------------- tabakrolletjie/scenes/night.py | 22 ++++++++++++++++------ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index 8c42b06..2a1cc35 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -40,8 +40,10 @@ class DayScene(BaseScene): self._tool = None self._light_colors = None self._dragging = None - # Turnip - self.grow_turnips(gamestate) + # Create Turnips + for turnip_data in gamestate.turnips: + turnip = Turnip(space=self._space, **turnip_data) + self._turnips.append(turnip) # Tools self._light_toolbar = [] self._tools = self.create_tools(gamestate) @@ -89,17 +91,6 @@ class DayScene(BaseScene): (shadowed_text("Press a key to return to the menu", FONTS["sans"], 24), (350, 400))) - def grow_turnips(self, gamestate): - for turnip_data in gamestate.turnips: - turnip = Turnip(space=self._space, **turnip_data) - # Turnips grow at dawn - seeds = turnip.grow() - if seeds: - gamestate.seeds += seeds - gamestate.harvested += 1 - else: - self._turnips.append(turnip) - def create_tools(self, gamestate): tools = [] @@ -132,14 +123,14 @@ class DayScene(BaseScene): def exit(self, gamestate): self._unset_cursor() - turnip_data = [turnip.serialize() for turnip in self._turnips] - gamestate.turnips = turnip_data def end_day(self, gamestate): if self._ending: return self._battery.apply_recharge() gamestate.update_lights(self._lights) + turnip_data = [turnip.serialize() for turnip in self._turnips] + gamestate.turnips = turnip_data self._ending = True from .night import NightScene SceneChangeEvent.post(scene=NightScene()) diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index 593a03f..9f86745 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -153,6 +153,12 @@ class NightScene(BaseScene): if self._ending: return gamestate.update_lights(self._lights) + # Turnip + self.grow_turnips(gamestate) + turnip_data = [turnip.serialize() for turnip in self._turnips] + gamestate.turnips = turnip_data + gamestate.days += 1 + self._mould.update_resistances(gamestate) self._ending = True from .day import DayScene SceneChangeEvent.post(scene=DayScene()) @@ -202,9 +208,13 @@ class NightScene(BaseScene): if not self.turnip_count and not self._battery.current: self._end_night() - def exit(self, gamestate): - turnip_data = [turnip.serialize() for turnip in self._turnips] - gamestate.turnips = turnip_data - # TODO: Move this into the end_night function - gamestate.days += 1 - self._mould.update_resistances(gamestate) + def grow_turnips(self, gamestate): + """ Turnips grow at the end of the night """ + for turnip in self._turnips[:]: + # Turnips grow at dawn + seeds = turnip.grow() + if seeds: + gamestate.seeds += seeds + gamestate.harvested += 1 + self._turnips.remove(turnip) + # We ignore the body cleanup, since the space is going away -- 2.34.1