Move turnip growth and related updates to the end of the night
[tabakrolletjie.git] / tabakrolletjie / scenes / night.py
index 593a03f5bed6292238349ec5851da9a01a07e411..9f86745a052aa142acb72654a6519b3a44bf9cc9 100644 (file)
@@ -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