From: Christian Heller Date: Sat, 14 Nov 2020 01:04:18 +0000 (+0100) Subject: Persist Thing names, simplify their client info display. X-Git-Url: https://plomlompom.com/repos/balance?a=commitdiff_plain;h=06c3b773099e2264831d5f4b4650eadb9290b296;p=plomrogue2 Persist Thing names, simplify their client info display. --- diff --git a/plomrogue/commands.py b/plomrogue/commands.py index 3b2464b..8732bf3 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -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' diff --git a/plomrogue/game.py b/plomrogue/game.py index 483dd34..b138c56 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -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 diff --git a/plomrogue/parser.py b/plomrogue/parser.py index 6a6aaaa..a1b56b5 100644 --- a/plomrogue/parser.py +++ b/plomrogue/parser.py @@ -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) diff --git a/rogue_chat.py b/rogue_chat.py index e15ee24..93dee85 100755 --- a/rogue_chat.py +++ b/rogue_chat.py @@ -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) diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 22ebc01..d1541a7 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -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' diff --git a/rogue_chat_nocanvas_monochrome.html b/rogue_chat_nocanvas_monochrome.html index c0ee072..9716776 100644 --- a/rogue_chat_nocanvas_monochrome.html +++ b/rogue_chat_nocanvas_monochrome.html @@ -728,7 +728,7 @@ let explorer = { info += t.player_char; }; if (t.name_) { - info += " (name: " + t.name_ + ")"; + info += " (" + t.name_ + ")"; } info += "\n"; }