From: Jeremy Thurgood Date: Fri, 16 May 2014 10:28:58 +0000 (+0200) Subject: Tweak markup, add chesspiece glyphs. X-Git-Tag: 0.1~232 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=5fe12b55d1908f850145eec16a1ee2c8e61ba6ef;p=naja.git Tweak markup, add chesspiece glyphs. --- diff --git a/naja/actions.py b/naja/actions.py index 34c84f6..35f4342 100644 --- a/naja/actions.py +++ b/naja/actions.py @@ -1,5 +1,5 @@ from naja.constants import BITS, CHESS_PIECES -from naja.utils import bit_glyphs +from naja.utils import bit_glyphs, move_glyph class LocationAction(object): @@ -24,9 +24,11 @@ class LocationAction(object): 'EAST': 'row', 'WEST': 'row', }[self.data['direction']] + substitutions['direction'] = '{%s}' % (substitutions['direction'],) if 'chesspiece' in self.data: - substitutions['chesspiece_name'] = self.data['chesspiece'].lower() + substitutions['chesspiece_name'] = move_glyph( + self.data['chesspiece']) if location is None: substitutions['location_bits'] = 'bits specified by this location' @@ -64,7 +66,7 @@ class DoNothing(LocationAction): class LoseHealthOrMSB(LocationAction): - TEXT = "Lose HEALTH or MSB." + TEXT = "Lose {HEALTH} or {MSB}." USES_MSB = True def perform_action(self, board, location): @@ -87,7 +89,7 @@ class ToggleBits(LocationAction): class LoseHealthOrMSBAndSetBits(LocationAction): - TEXT = "Lose HEALTH or MSB, then set %(location_bits)s." + TEXT = "Lose {HEALTH} or {MSB}, then set %(location_bits)s." USES_MSB = True def perform_action(self, board, location): @@ -97,7 +99,7 @@ class LoseHealthOrMSBAndSetBits(LocationAction): class AcquireWinToken(LocationAction): - TEXT = "Gain WINTOKEN, then clear {RED,GREEN,BLUE}." + TEXT = "Gain {WINTOKEN}, then clear {RED,GREEN,BLUE}." def perform_action(self, board, location): board.acquire_win_token() @@ -107,7 +109,7 @@ class AcquireWinToken(LocationAction): class GainHealthAndClearBitsOrMSB(LocationAction): - TEXT = "Gain HEALTH, then clear %(location_bits)s or MSB." + TEXT = "Gain {HEALTH}, then clear %(location_bits)s or {MSB}." USES_MSB = True def perform_action(self, board, location): diff --git a/naja/utils.py b/naja/utils.py index c7fe2e3..d69cd4a 100644 --- a/naja/utils.py +++ b/naja/utils.py @@ -17,3 +17,11 @@ 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()) diff --git a/naja/widgets/text.py b/naja/widgets/text.py index 3b0827d..d8d2d47 100644 --- a/naja/widgets/text.py +++ b/naja/widgets/text.py @@ -97,8 +97,6 @@ class TextBoxWidget(TextWidget): subwords = word[1:-1].split(',') if all(subword in MARKUP_MAP for subword in subwords): return Glyph(word + suffix, subwords, suffix) - elif word in MARKUP_MAP: - return Glyph(word + suffix, [word], suffix) return None