Factor out flash light into utils.
[naja.git] / naja / widgets / info_area.py
index 1ff6bbbd92168e52ec12c4a489cf6f54638f95a7..fd470387e6b994a2d15eace94df7df8c22892274 100644 (file)
@@ -12,11 +12,11 @@ from naja.events import finish_event
 from naja.resources import resources
 from naja.resources.mutators import EIGHT_BIT, blender
 from naja.sound import sound
-from naja.utils import bit_glyphs
+from naja.utils import bit_glyphs, Flashlight
 
 from naja.widgets.base import Widget
 from naja.widgets.tile import BIT_MAP
-from naja.widgets.text import TextBoxWidget, TextWidget
+from naja.widgets.text import TextBoxWidget
 from naja import constants
 
 
@@ -44,8 +44,7 @@ class InfoAreaWidget(Widget):
         self.chosen = None
         self.card_position = state.player.position
         self.set_position(state.player.position)
-        self.flash_count = 0
-        self.flash_light = True
+        self.flash_light = Flashlight(constants.FPS // 2)
 
     def prepare(self):
         if self.state.gameboard.player_mode == ACT:
@@ -131,7 +130,7 @@ class InfoAreaWidget(Widget):
 
         border_colour = None
         if choice == self.chosen:
-            if self.flash_light:
+            if self.flash_light.on:
                 border_colour = (PALETTE.GREEN if action_viable else
                                  PALETTE.ORANGE)
             else:
@@ -188,10 +187,7 @@ class InfoAreaWidget(Widget):
             self.chosen = None
 
     def draw(self, surface):
-        self.flash_count += 1
-        if self.flash_count >= (constants.FPS // 2):
-            self.flash_light = not self.flash_light
-            self.flash_count = 0
+        if self.flash_light.tick():
             self.prepare()
         surface.blit(self.surface, self.pos)