Reset more thingS
[tabakrolletjie.git] / tabakrolletjie / gamestate.py
index 27762a6d7e086c3dae50bff4226cfe4ee085708a..0713537208ec63eb27572d634c127cd54f0fea73 100644 (file)
@@ -11,6 +11,7 @@ class GameState(object):
         self.harvested = 0
         self.eaten = 0
         self.days = 0
+        self.resistances = {}
 
     @property
     def station(self):
@@ -28,8 +29,9 @@ class GameState(object):
     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"]
+                    "seeds" in self._state["station"]["config"]):
+                self._state["seeds"] = (
+                    self._state["station"]["config"]["seeds"])
             else:
                 self._state["seeds"] = 0
         return self._state["seeds"]
@@ -42,9 +44,38 @@ class GameState(object):
         self._state["station"] = station
         self._state["turnips"] = []
         self._state["seeds"] = None
+        self.resistances = {}
+        self.harvested = 0
+        self.eaten = 0
+        self.days = 0
 
     def get_spawn_positions(self):
         return self._state["station"]["config"]["spawn positions"]
 
-    def get_target(self):
+    @property
+    def turnip_target(self):
         return self._state["station"]["config"]["turnip target"]
+
+    def update_lights(self, lights):
+        self._state["station"]["lights"] = lights.serialize_lights()
+
+    def serialize(self):
+        result = {
+            "station": self._state["station"],
+            "turnips": self._state["turnips"],
+            "seeds": self._state['seeds'],
+            "harvested": self.harvested,
+            "eaten": self.eaten,
+            "days": self.days,
+            "resistances": self.resistances,
+        }
+        return result
+
+    def load_from_json(self, json_data):
+        self._state["station"] = dict(**json_data["station"])
+        self._state["turnips"] = json_data["turnips"]
+        self._state["seeds"] = json_data["seeds"]
+        self.harvested = json_data["harvested"]
+        self.eaten = json_data["harvested"]
+        self.days = json_data["days"]
+        self.resistances = dict(**json_data["resistances"])