home · contact · privacy
Persist Thing names, simplify their client info display.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 14 Nov 2020 01:04:18 +0000 (02:04 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 14 Nov 2020 01:04:18 +0000 (02:04 +0100)
plomrogue/commands.py
plomrogue/game.py
plomrogue/parser.py
rogue_chat.py
rogue_chat_curses.py
rogue_chat_nocanvas_monochrome.html

index 3b2464b42baa6d7c429832ea34138c970d00570d..8732bf3f02eca9ccff649ec98d4316ab7e99153b 100644 (file)
@@ -211,3 +211,10 @@ def cmd_THING(game, yx, thing_type, thing_id):
         game.things += [t_new]
     game.changed = True
 cmd_THING.argtypes = 'yx_tuple:nonneg string:thing_type int:nonneg'
+
+def cmd_THING_NAME(game, thing_id, name):
+    t = game.get_thing(thing_id)
+    if not t:
+        raise GameError('thing of ID %s not found' % thing_id)
+    t.name = name
+cmd_THING_NAME.argtypes = 'int:pos string'
index 483dd346e2a837a1c61f65fa265f1f3b592faabb..b138c564f8032238285a9948edc0a95fd0756f28 100755 (executable)
@@ -220,6 +220,8 @@ class Game(GameBase):
                                                  self.map_control_passwords[tile_class]))
           for t in [t for t in self.things if not t.type_ == 'Player']:
               write(f, 'THING %s %s %s' % (t.position, t.type_, t.id_))
+              if hasattr(t, 'name'):
+                  write(f, 'THING_NAME %s %s' % (t.id_, quote(t.name)))
 
     def new_world(self, map_geometry):
         self.map_geometry = map_geometry
index 6a6aaaaa59087c2f5a240efbff92ec4025bbc752..a1b56b571b650431d297badf3f0e4573da731359 100644 (file)
@@ -106,6 +106,10 @@ class Parser:
                 if not arg.isdigit():
                     raise ArgError('Argument must be non-negative integer.')
                 args += [int(arg)]
+            elif tmpl == 'int:pos':
+                if not arg.isdigit() or int(arg) < 1:
+                    raise ArgError('Argument must be positive integer.')
+                args += [int(arg)]
             elif tmpl == 'char':
                 try:
                     ord(arg)
index e15ee242e92d71e9c9e3a637e7e989f65f75ac13..93dee854977223b0bc9c07ea21b9f2aabf611fd6 100755 (executable)
@@ -6,7 +6,8 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN
                                 cmd_MAP, cmd_TURN, cmd_MAP_LINE, cmd_GET_ANNOTATION,
                                 cmd_ANNOTATE, cmd_PORTAL, cmd_GET_GAMESTATE,
                                 cmd_TASKS, cmd_MAP_CONTROL_LINE, cmd_MAP_CONTROL_PW,
-                                cmd_GOD_ANNOTATE, cmd_GOD_PORTAL, cmd_THING_TYPES)
+                                cmd_GOD_ANNOTATE, cmd_GOD_PORTAL, cmd_THING_TYPES,
+                                cmd_THING_NAME)
 from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP,
                              Task_DROP, Task_FLATTEN_SURROUNDINGS)
 from plomrogue.things import Thing_Player, Thing_Stone
@@ -35,6 +36,7 @@ game.register_command(cmd_GET_GAMESTATE)
 game.register_command(cmd_TASKS)
 game.register_command(cmd_THING_TYPES)
 game.register_command(cmd_THING)
+game.register_command(cmd_THING_NAME)
 game.register_task(Task_WAIT)
 game.register_task(Task_MOVE)
 game.register_task(Task_WRITE)
index 22ebc01aa526831a9c077c1e7f49bb19e213982d..d1541a760b7576dd8b1054cd22091d17004d93a2 100755 (executable)
@@ -457,7 +457,7 @@ class TUI:
                         if hasattr(t, 'player_char'):
                             info += t.player_char
                         if hasattr(t, 'name'):
-                            info += ' (name: %s)' % t.name
+                            info += ' (%s)' % t.name
                         info += '\n'
                 if self.explorer in self.game.portals:
                     info += 'PORTAL: ' + self.game.portals[self.explorer] + '\n'
index c0ee072d7d634fcd2872cdf0c41f0b099a801b31..971677687357b5d54a51701005a4fed4ec0b6d08 100644 (file)
@@ -728,7 +728,7 @@ let explorer = {
                      info += t.player_char;
                  };
                  if (t.name_) {
-                     info += " (name: " + t.name_ + ")";
+                     info += " (" + t.name_ + ")";
                  }
                  info += "\n";
              }