X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=plomrogue%2Fcommands.py;h=643988e63258a49480b185450a6d6632cfe86734;hb=c44edaea10aa907301a47f19e492f1d869d528d9;hp=229285fb8c7f291ff02458367b11e40f89cdb6a9;hpb=884b4b8d9c18896569c5e741f90a6ee67f8db8b2;p=plomrogue2 diff --git a/plomrogue/commands.py b/plomrogue/commands.py index 229285f..643988e 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -4,7 +4,7 @@ from plomrogue.mapping import YX, MapGeometrySquare, MapGeometryHex, Map -# TODO: instead of sending tasks and thing types on request, send them on connection +# TODO: instead of sending tasks, thing types etc. on request, send them on connection def cmd_TASKS(game, connection_id): tasks = [] @@ -13,10 +13,16 @@ cmd_TASKS.argtypes = '' def cmd_THING_TYPES(game, connection_id): for t_t in game.thing_types.values(): - game.io.send('THING_TYPE %s %s' % (t_t.get_type(), t_t.symbol_hint), + game.io.send('THING_TYPE %s %s' % (t_t.get_type(), quote(t_t.symbol_hint)), connection_id) cmd_THING_TYPES.argtypes = '' +def cmd_TERRAINS(game, connection_id): + for t in game.terrains.keys(): + game.io.send('TERRAIN %s %s' % (quote(t), quote(game.terrains[t])), + connection_id) +cmd_TERRAINS.argtypes = '' + def cmd_ALL(game, msg, connection_id): def lower_msg_by_volume(msg, volume): @@ -67,7 +73,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 +81,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 +91,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 +118,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) @@ -211,3 +217,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'