glyph for return
[naja.git] / naja / utils.py
1 import pygame
2
3 from naja.constants import BITS
4
5
6 def convert_colour(colour):
7     if isinstance(colour, pygame.Color):
8         return colour
9     if isinstance(colour, tuple):
10         return pygame.Color(*colour)
11     if isinstance(colour, basestring):
12         return pygame.Color(colour)
13     raise ValueError()
14
15
16 def bit_glyphs(bits):
17     bit_names = dict((v, k) for k, v in BITS.items())
18     return '{%s}' % ','.join(bit_names[bit] for bit in reversed(range(8))
19                              if bit in bits)
20
21
22 def move_glyph(move_name):
23     return {
24         'CASTLE': u'\u265c',
25         'BISHOP': u'\u265d',
26         'KNIGHT': u'\u265e',
27     }.get(move_name, move_name.lower())
28
29
30 def parse_bits(bit_list):
31     # Convert names to numbers if applicable.
32     return frozenset(BITS.get(bit, bit) for bit in bit_list)
33
34
35 def warp_to_game_state(game_state):
36     from naja.events import LoadGameEvent, SceneChangeEvent
37     from naja.scenes.game import GameScene
38     LoadGameEvent.post(game_state)
39     SceneChangeEvent.post(GameScene)