Tweak markup, add chesspiece glyphs.
authorJeremy Thurgood <firxen@gmail.com>
Fri, 16 May 2014 10:28:58 +0000 (12:28 +0200)
committerJeremy Thurgood <firxen@gmail.com>
Fri, 16 May 2014 10:28:58 +0000 (12:28 +0200)
naja/actions.py
naja/utils.py
naja/widgets/text.py

index 34c84f6660e7ac343e0dc94de2c200c609198fed..35f4342a3afc40c74196ce516473599d0ab68ec2 100644 (file)
@@ -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):
index c7fe2e32f264c410b35b84eea533122c9f86c805..d69cd4ad73f42dfc71a28912a9e751deb3de3129 100644 (file)
@@ -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())
index 3b0827d3f997fc4ff37be515439da7b0fd867520..d8d2d47e51726c7ac58b3ed77cf7d3b6f5a582d8 100644 (file)
@@ -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