From: Christian Heller Date: Sat, 14 Nov 2020 00:57:47 +0000 (+0100) Subject: Generalize ThingPlayer.nickname to Thing.name. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/%7B%7Bprefix%7D%7D/process?a=commitdiff_plain;h=2ce340a97606c970eb1d6dd8cccee7a2d12c6c05;p=plomrogue2 Generalize ThingPlayer.nickname to Thing.name. --- diff --git a/plomrogue/commands.py b/plomrogue/commands.py index 229285f..3b2464b 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -67,7 +67,7 @@ def cmd_ALL(game, msg, connection_id): listener_vol = dijkstra_map[game.map.get_position_index(listener.position)] volume = 1 / max(1, listener_vol) lowered_msg = lower_msg_by_volume(msg, volume) - lowered_nick = lower_msg_by_volume(speaker.nickname, volume) + lowered_nick = lower_msg_by_volume(speaker.name, volume) game.io.send('CHAT ' + quote('(volume: %.2f) %s: %s' % (volume, lowered_nick, lowered_msg)), @@ -75,7 +75,7 @@ def cmd_ALL(game, msg, connection_id): cmd_ALL.argtypes = 'string' def cmd_LOGIN(game, nick, connection_id): - for t in [t for t in game.things if t.type_ == 'Player' and t.nickname == nick]: + for t in [t for t in game.things if t.type_ == 'Player' and t.name == nick]: raise GameError('name already in use') if connection_id in game.sessions: raise GameError('cannot log in twice') @@ -85,21 +85,21 @@ def cmd_LOGIN(game, nick, connection_id): t.player_char = game.get_next_player_char() game.sessions[connection_id] = t.id_ game.io.send('LOGIN_OK', connection_id) - t.nickname = nick - game.io.send('CHAT ' + quote(t.nickname + ' entered the map.')) + t.name = nick + game.io.send('CHAT ' + quote(t.name + ' entered the map.')) game.io.send('PLAYER_ID %s' % t.id_, connection_id) game.changed = True cmd_LOGIN.argtypes = 'string' def cmd_NICK(game, nick, connection_id): - for t in [t for t in game.things if t.type_ == 'Player' and t.nickname == nick]: + for t in [t for t in game.things if t.type_ == 'Player' and t.name == nick]: raise GameError('name already in use') if not connection_id in game.sessions: raise GameError('can only rename when already logged in') t_id = game.sessions[connection_id] t = game.get_thing(t_id) - old_nick = t.nickname - t.nickname = nick + old_nick = t.name + t.name = nick game.io.send('CHAT ' + quote(old_nick + ' renamed themselves to ' + nick)) game.changed = True cmd_NICK.argtypes = 'string' @@ -112,8 +112,8 @@ cmd_GET_GAMESTATE.argtypes = '' # if not connection_id in game.sessions: # raise GameError('can only query when logged in') # t = game.get_thing(game.sessions[connection_id], False) -# source_nick = t.nickname -# for t in [t for t in game.things if t.type_ == 'Player' and t.nickname == target_nick]: +# source_nick = t.name +# for t in [t for t in game.things if t.type_ == 'Player' and t.name == target_nick]: # for c_id in game.sessions: # if game.sessions[c_id] == t.id_: # game.io.send('CHAT ' + quote(source_nick+ '->' + target_nick + ': ' + msg), c_id) diff --git a/plomrogue/game.py b/plomrogue/game.py index 29e2de1..483dd34 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -109,9 +109,8 @@ class Game(GameBase): for t in [t for t in self.things if player.fov_stencil[t.position] == '.']: self.io.send('THING %s %s %s' % (t.position, t.type_, t.id_), c_id) - if hasattr(t, 'nickname'): - self.io.send('THING_NAME %s %s' % (t.id_, - quote(t.nickname)), c_id) + if hasattr(t, 'name'): + self.io.send('THING_NAME %s %s' % (t.id_, quote(t.name)), c_id) if hasattr(t, 'player_char'): self.io.send('THING_CHAR %s %s' % (t.id_, quote(t.player_char)), c_id) @@ -130,8 +129,8 @@ class Game(GameBase): break if not connection_id_found: t = self.get_thing(self.sessions[connection_id]) - if hasattr(t, 'nickname'): - self.io.send('CHAT ' + quote(t.nickname + ' left the map.')) + if hasattr(t, 'name'): + self.io.send('CHAT ' + quote(t.name + ' left the map.')) self.things.remove(t) to_delete += [connection_id] for connection_id in to_delete: diff --git a/plomrogue/things.py b/plomrogue/things.py index b6fe5e1..98a5995 100644 --- a/plomrogue/things.py +++ b/plomrogue/things.py @@ -107,5 +107,4 @@ class Thing_Player(ThingAnimate): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.nickname = 'undefined' self.carrying = None