Serialize light state across day and night transitions
[tabakrolletjie.git] / tabakrolletjie / gamestate.py
index 6f7f5c45afe62ac586e7fae86e78876e8177e350..6f6725b8e0bda36ef5a031946306194d0496b0e2 100644 (file)
@@ -1,4 +1,57 @@
 """ The game state. """
 
+
 class GameState(object):
-    pass
+    def __init__(self):
+        self._state = {
+            "station": None,
+            "turnips": [],
+            "seeds": None,
+        }
+        self.harvested = 0
+        self.eaten = 0
+        self.days = 0
+        self.resistances = {}
+
+    @property
+    def station(self):
+        return self._state["station"]
+
+    @property
+    def turnips(self):
+        return self._state["turnips"]
+
+    @turnips.setter
+    def turnips(self, turnip_list):
+        self._state["turnips"] = turnip_list
+
+    @property
+    def seeds(self):
+        if self._state["seeds"] is None:
+            if (self._state["station"] and
+                    "seeds" in self._state["station"]["config"]):
+                self._state["seeds"] = (
+                    self._state["station"]["config"]["seeds"])
+            else:
+                self._state["seeds"] = 0
+        return self._state["seeds"]
+
+    @seeds.setter
+    def seeds(self, value):
+        self._state['seeds'] = value
+
+    def set_station(self, station):
+        self._state["station"] = station
+        self._state["turnips"] = []
+        self._state["seeds"] = None
+        self.resistances = {}
+
+    def get_spawn_positions(self):
+        return self._state["station"]["config"]["spawn positions"]
+
+    @property
+    def turnip_target(self):
+        return self._state["station"]["config"]["turnip target"]
+
+    def update_lights(self, lights):
+        self._state["station"]["lights"] = lights.serialize_lights()