X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Futils.py;h=d69cd4ad73f42dfc71a28912a9e751deb3de3129;hb=172e2665331fba1bcda0a5b07774db8523076e66;hp=a40b8412f0adaba2389533f25445b998a79761b3;hpb=d7291141b604ffc7941074ae1adb9596c5f314ce;p=naja.git diff --git a/naja/utils.py b/naja/utils.py index a40b841..d69cd4a 100644 --- a/naja/utils.py +++ b/naja/utils.py @@ -1,5 +1,7 @@ import pygame +from naja.constants import BITS + def convert_colour(colour): if isinstance(colour, pygame.Color): @@ -9,3 +11,17 @@ def convert_colour(colour): 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())