From: Neil Date: Sat, 10 Sep 2016 20:50:47 +0000 (+0200) Subject: Add ending flag to avoid many scene change events X-Git-Tag: tabakrolletjie-v1.0.0~39^2~1 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=cff2127fd334bfe5794b15857508699d2bcbd2d8;p=tabakrolletjie.git Add ending flag to avoid many scene change events --- diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index e2d1e19..7f73ad2 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -53,6 +53,7 @@ class DayScene(BaseScene): self._draw_you_lose(gamestate) elif gamestate.harvested >= gamestate.turnip_target: self._draw_you_win(gamestate) + self._ending = False def _draw_you_lose(self, gamestate): overlay = pygame.surface.Surface( @@ -128,8 +129,11 @@ class DayScene(BaseScene): gamestate.turnips = turnip_data def end_day(self, gamestate): + if self._ending: + return self._battery.apply_recharge() gamestate.update_lights(self._lights) + self._ending = True from .night import NightScene SceneChangeEvent.post(scene=NightScene()) @@ -226,12 +230,16 @@ class DayScene(BaseScene): self._lights.add_light(cfg) def event(self, ev, gamestate): + if self._ending: + return if self._game_over_text: if ev.type in (pgl.KEYDOWN, pgl.MOUSEBUTTONDOWN): + self._ending = True from .menu import MenuScene SceneChangeEvent.post(scene=MenuScene()) if ev.type == pgl.KEYDOWN: if ev.key in (pgl.K_q, pgl.K_ESCAPE): + self._ending = True from .menu import MenuScene SceneChangeEvent.post(scene=MenuScene()) elif ev.key == pgl.K_e: @@ -251,6 +259,7 @@ class DayScene(BaseScene): elif tool.name == 'start night': self.end_day(gamestate) elif tool.name == 'exit': + self._ending = True from .menu import MenuScene SceneChangeEvent.post(scene=MenuScene()) else: diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index 9459c0e..7813e32 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -47,6 +47,7 @@ class NightScene(BaseScene): self._paused = False self._eaten_tonight = 0 self._night_over_text = [] + self._ending = False def create_tools(self, gamestate): tools = [] @@ -105,11 +106,14 @@ class NightScene(BaseScene): surface.blit(text, text_pos, None) def event(self, ev, gamestate): + if self._ending: + return if ev.type == pgl.KEYDOWN: if not self._do_ticks: # Any keypress exits self._to_day(gamestate) if ev.key in (pgl.K_q, pgl.K_ESCAPE): + self._ending = True from .menu import MenuScene SceneChangeEvent.post(scene=MenuScene()) elif ev.key == pgl.K_e and DEBUG: @@ -129,6 +133,7 @@ class NightScene(BaseScene): if tool.name == 'pause play': self.toggle_pause() elif tool.name == 'exit': + self._ending = True from .menu import MenuScene SceneChangeEvent.post(scene=MenuScene()) elif tool.name == 'day': @@ -143,7 +148,10 @@ class NightScene(BaseScene): def _to_day(self, gamestate): # End the night + if self._ending: + return gamestate.update_lights(self._lights) + self._ending = True from .day import DayScene SceneChangeEvent.post(scene=DayScene())