Change how infobar updates work.
authorSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 16:47:43 +0000 (18:47 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 16:47:43 +0000 (18:47 +0200)
tabakrolletjie/infobar.py
tabakrolletjie/scenes/day.py

index 5a4d3ccc0aebde1cb0329fe775a44db318b1e31a..58aa3b6a27bdfe10932ea6f1283bbc2599999346 100644 (file)
@@ -32,9 +32,8 @@ class InfoBar(object):
         self._text = None
         self._infobar = None
 
-    def render(self, surface):
-        if self._infobar is None:
-            self._update_infobar()
+    def render(self, surface, gamestate):
+        self._update(gamestate)
         surface.blit(self._infobar, self.pos, None)
 
     def _update_infobar(self):
@@ -46,7 +45,7 @@ class InfoBar(object):
         self._infobar.fill((0, 0, 0, 64))
         self._infobar.blit(text_img, (5, 3), None)
 
-    def update(self, gamestate):
+    def _update(self, gamestate):
         options = {
             "gamestate": gamestate, "battery": self.battery,
             "scene": self.scene, "time_of_day": self.time_of_day,
@@ -54,4 +53,4 @@ class InfoBar(object):
         text = self.template.format(**options)
         if text != self._text:
             self._text = text
-            self._infobar = None
+            self._update_infobar()
index 17506fd1f04e1e828667f7958e644f7b91c079e1..4c3cbfe9759c01458be1c1bcb307f4d1ca74221c 100644 (file)
@@ -44,7 +44,6 @@ class DayScene(BaseScene):
         # Tools
         self._light_toolbar = []
         self._tools = self.create_tools(gamestate)
-        self._infobar.update(gamestate)
         # Background
         self._soil = loader.load_image(
             "textures", "soil.png", transform=self.BRIGHTNESS)
@@ -150,7 +149,7 @@ class DayScene(BaseScene):
         self._lights.render_light(surface)
         self._obstacles.render(surface)
         self._lights.render_fittings(surface)
-        self._infobar.render(surface)
+        self._infobar.render(surface, gamestate)
         for tool in self._tools:
             tool.render(surface)
         for light_tool in self._light_toolbar:
@@ -189,7 +188,6 @@ class DayScene(BaseScene):
                 turnip = Turnip(age=0, pos=pos, space=self._space)
                 self._turnips.append(turnip)
                 gamestate.seeds -= 1
-                self._infobar.update(gamestate)
             except TurnipInvalidPosition:
                 # TODO: Add error sound or something
                 pass
@@ -219,7 +217,6 @@ class DayScene(BaseScene):
             if self._lights.nearest(pos, max_distance=25):
                 return
             gamestate.seeds -= cost
-            self._infobar.update(gamestate)
             cfg["position"] = pos
             cfg["colours"] = colours
             gamestate.station["lights"].append(cfg)