From: Christian Heller Date: Sat, 14 Nov 2020 00:36:30 +0000 (+0100) Subject: Add player-identifying meta characters next to @ symbols. X-Git-Url: https://plomlompom.com/repos/ledger?a=commitdiff_plain;h=884b4b8d9c18896569c5e741f90a6ee67f8db8b2;p=plomrogue2 Add player-identifying meta characters next to @ symbols. --- diff --git a/plomrogue/commands.py b/plomrogue/commands.py index 1c59abf..229285f 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -82,6 +82,7 @@ def cmd_LOGIN(game, nick, connection_id): t = game.thing_types['Player'](game) t.position = YX(game.map.size.y // 2, game.map.size.x // 2) game.things += [t] # TODO refactor into Thing.__init__? + t.player_char = game.get_next_player_char() game.sessions[connection_id] = t.id_ game.io.send('LOGIN_OK', connection_id) t.nickname = nick diff --git a/plomrogue/game.py b/plomrogue/game.py index 1ffbf1a..29e2de1 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -4,6 +4,7 @@ from plomrogue.errors import GameError, PlayError from plomrogue.io import GameIO from plomrogue.misc import quote from plomrogue.mapping import YX, MapGeometrySquare, Map +import string @@ -48,6 +49,8 @@ class Game(GameBase): self.map_control_passwords = {} self.annotations = {} self.portals = {} + self.player_chars = string.digits + string.ascii_letters + self.player_char_i = -1 if os.path.exists(self.io.save_file): if not os.path.isfile(self.io.save_file): raise GameError('save file path refers to non-file') @@ -76,7 +79,6 @@ class Game(GameBase): return True def get_string_options(self, string_option_type): - import string if string_option_type == 'direction': return self.map_geometry.get_directions() elif string_option_type == 'char': @@ -110,6 +112,9 @@ class Game(GameBase): if hasattr(t, 'nickname'): self.io.send('THING_NAME %s %s' % (t.id_, quote(t.nickname)), c_id) + if hasattr(t, 'player_char'): + self.io.send('THING_CHAR %s %s' % (t.id_, + quote(t.player_char)), c_id) for yx in [yx for yx in self.portals if player.fov_stencil[yx] == '.']: self.io.send('PORTAL %s %s' % (yx, quote(self.portals[yx])), c_id) @@ -187,6 +192,12 @@ class Game(GameBase): return 1 return max([t.id_ for t in self.things]) + 1 + def get_next_player_char(self): + self.player_char_i += 1 + if self.player_char_i >= len(self.player_chars): + self.player_char_i = 0 + return self.player_chars[self.player_char_i] + def save(self): def write(f, msg): diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 3b110ba..22ebc01 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -87,6 +87,12 @@ def cmd_THING_NAME(game, thing_id, name): t.name = name cmd_THING_NAME.argtypes = 'int:nonneg string' +def cmd_THING_CHAR(game, thing_id, c): + t = game.get_thing(thing_id) + if t: + t.player_char = c +cmd_THING_CHAR.argtypes = 'int:nonneg char' + def cmd_MAP(game, geometry, size, content): map_geometry_class = globals()['MapGeometry' + geometry] game.map_geometry = map_geometry_class(size) @@ -183,6 +189,7 @@ class Game(GameBase): self.register_command(cmd_THING) self.register_command(cmd_THING_TYPE) self.register_command(cmd_THING_NAME) + self.register_command(cmd_THING_CHAR) self.register_command(cmd_MAP) self.register_command(cmd_MAP_CONTROL) self.register_command(cmd_PORTAL) @@ -445,7 +452,10 @@ class TUI: info = 'TERRAIN: %s\n' % self.game.map_content[pos_i] for t in self.game.things: if t.position == self.explorer: - info += 'THING: %s' % t.type_ + info += 'THING: %s / %s' % (t.type_, + self.game.thing_types[t.type_]) + if hasattr(t, 'player_char'): + info += t.player_char if hasattr(t, 'name'): info += ' (name: %s)' % t.name info += '\n' @@ -497,10 +507,12 @@ class TUI: used_positions = [] for t in self.game.things: symbol = self.game.thing_types[t.type_] + meta_char = ' ' + if hasattr(t, 'player_char'): + meta_char = t.player_char if t.position in used_positions: - map_lines_split[t.position.y][t.position.x] = symbol + '+' - else: - map_lines_split[t.position.y][t.position.x] = symbol + ' ' + meta_char = '+' + map_lines_split[t.position.y][t.position.x] = symbol + meta_char used_positions += [t.position] if self.mode.shows_info: map_lines_split[self.explorer.y][self.explorer.x] = '??' diff --git a/rogue_chat_nocanvas_monochrome.html b/rogue_chat_nocanvas_monochrome.html index 4956cbd..c0ee072 100644 --- a/rogue_chat_nocanvas_monochrome.html +++ b/rogue_chat_nocanvas_monochrome.html @@ -214,6 +214,11 @@ let server = { if (t) { t.name_ = tokens[2]; }; + } else if (tokens[0] === 'THING_CHAR') { + let t = game.get_thing(tokens[1], false); + if (t) { + t.player_char = tokens[2]; + }; } else if (tokens[0] === 'TASKS') { game.tasks = tokens[1].split(',') } else if (tokens[0] === 'THING_TYPE') { @@ -453,11 +458,14 @@ let tui = { for (const thing_id in game.things) { let t = game.things[thing_id]; let symbol = game.thing_types[t.type_]; + let meta_char = ' '; + if (t.player_char) { + meta_char = t.player_char; + } if (used_positions.includes(t.position.toString())) { - map_lines_split[t.position[0]][t.position[1]] = symbol + '+'; - } else { - map_lines_split[t.position[0]][t.position[1]] = symbol + ' '; + meta_char = '+'; }; + map_lines_split[t.position[0]][t.position[1]] = symbol + meta_char; used_positions.push(t.position.toString()); }; } @@ -714,7 +722,11 @@ let explorer = { for (let t_id in game.things) { let t = game.things[t_id]; if (t.position[0] == this.position[0] && t.position[1] == this.position[1]) { - info += "THING: " + t.type_; + let symbol = game.thing_types[t.type_]; + info += "THING: " + t.type_ + " / " + symbol; + if (t.player_char) { + info += t.player_char; + }; if (t.name_) { info += " (name: " + t.name_ + ")"; }