home · contact · privacy
Add writable signs.
[plomrogue2] / plomrogue / commands.py
index 9cdab97a20963109c70460b6135c610b8cf94aaf..8422161b26c6b95bc372c51614acef6a3fc124e6 100644 (file)
@@ -383,6 +383,37 @@ def cmd_THING_HAT_DESIGN(game, thing_id, design):
     t.design = design
 cmd_THING_HAT_DESIGN.argtypes = 'int:pos string'
 
+def cmd_THING_DESIGN(game, design, pw, connection_id):
+    player = game.get_player(connection_id)
+    if not player:
+        raise GameError('need to be logged in for this')
+    if not player.carrying:
+        raise GameError('need to carry a thing to re-draw it')
+    if not game.can_do_thing_with_pw(player.carrying, pw):
+        raise GameError('wrong password for thing')
+    if not hasattr(player.carrying, 'design'):
+        raise GameError('carried thing not designable')
+    size = player.carrying.design_size
+    if len(design) != size.y * size.x:
+        raise GameError('design for carried thing of wrong length')
+    player.carrying.design = design
+    game.changed = True
+    game.record_change(player.carrying.position, 'other')
+cmd_THING_DESIGN.argtypes = 'string string'
+
+def cmd_GOD_THING_DESIGN(game, thing_id, design):
+    t = game.get_thing(thing_id)
+    if not t:
+        raise GameError('thing of ID %s not found' % thing_id)
+    if not hasattr(t, 'design'):
+        raise GameError('thing of ID %s not designable' % thing_id)
+    if len(design) != t.design_size.y * t.design_size.x:
+        raise GameError('design for thing of ID %s of wrong length' % thing_id)
+    t.design = design
+cmd_GOD_THING_DESIGN.argtypes = 'int:pos string'
+
+# TODO: refactor similar god and player commands
+
 def cmd_THING_DOOR_KEY(game, key_id, door_id):
     key = game.get_thing(key_id)
     if not key: