import pygame
+from naja.constants import BITS
+
def convert_colour(colour):
if isinstance(colour, pygame.Color):
if isinstance(colour, basestring):
return pygame.Color(colour)
raise ValueError()
+
+
+def bit_glyphs(bits):
+ bit_names = dict((v, k) for k, v in BITS.items())
+ return '{%s}' % ','.join(bit_names[bit] for bit in reversed(range(8))
+ if bit in bits)
+
+
+def move_glyph(move_name):
+ return {
+ 'CASTLE': u'\u265c',
+ 'BISHOP': u'\u265d',
+ 'KNIGHT': u'\u265e',
+ }.get(move_name, move_name.lower())
+
+
+def parse_bits(bit_list):
+ # Convert names to numbers if applicable.
+ return frozenset(BITS.get(bit, bit) for bit in bit_list)
+
+
+def warp_to_game_state(game_state):
+ from naja.events import LoadGameEvent, SceneChangeEvent
+ from naja.scenes.game import GameScene
+ LoadGameEvent.post(game_state)
+ SceneChangeEvent.post(GameScene)
+
+
+class Flashlight(object):
+ def __init__(self, rate):
+ self.rate = rate
+ self.ticks = 0
+ self.on = False
+
+ def tick(self):
+ self.ticks += 1
+ if self.ticks >= self.rate:
+ self.on = not self.on
+ self.ticks = 0
+ return True
+ return False