Bit shifts!
[naja.git] / naja / actions.py
index 7ed4c6b7fae55a7d49d2ec2d229ff0a05d36c422..0ada21be372024131d2175ce54b92fce58933ddb 100644 (file)
@@ -19,7 +19,10 @@ class LocationAction(object):
     def get_text(self, location=None):
         substitutions = self.data.copy()
 
-        if 'direction' in self.data:
+        if 'shift' in self.data:
+            substitutions['shift'] = self.data['shift']
+            substitutions['direction'] = self.data['direction']
+        elif 'direction' in self.data:
             substitutions['rowcol'] = {
                 'NORTH': 'column',
                 'SOUTH': 'column',
@@ -97,6 +100,18 @@ class ToggleBits(LocationAction):
         board.player.bits.toggle_bits(location.bitwise_operand)
 
 
+class ShiftBits(LocationAction):
+    TEXT = "Barrel-shift player %(shift)s bits %(direction)s."
+    GLYPHS = (ACTION_GLYPHS.CHANGE_BOARD,)
+
+    def perform_action(self, board, location):
+        shift = self.data['shift']
+        if self.data['direction'] == 'left':
+            board.player.bits.shift_bits_left(shift)
+        else:
+            board.player.bits.shift_bits_right(shift)
+
+
 class LoseHealthOrMSBAndSetBits(LocationAction):
     TEXT = "Lose {HEALTH} or {MSB}, then set %(location_bits)s."
     GLYPHS = (ACTION_GLYPHS.SET_BITS,)