From: Christian Heller Date: Thu, 26 Nov 2020 22:39:02 +0000 (+0100) Subject: Add thing name editing. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/cards/%7B%7Bcard_id%7D%7D/test?a=commitdiff_plain;h=800aca691b359f448599160ba3d8aef28174596d;p=plomrogue2 Add thing name editing. --- diff --git a/config.json b/config.json index 0e5c800..406f461 100644 --- a/config.json +++ b/config.json @@ -7,6 +7,7 @@ "switch_to_study": "?", "switch_to_edit": "E", "switch_to_write": "m", + "switch_to_name_thing": "N", "switch_to_admin": "A", "switch_to_control_pw_pw": "C", "switch_to_control_tile_type": "Q", diff --git a/plomrogue/commands.py b/plomrogue/commands.py index a9bd793..a2f98ed 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -269,9 +269,17 @@ def cmd_THING(game, big_yx, little_yx, thing_type, thing_id): game.changed = True cmd_THING.argtypes = 'yx_tuple yx_tuple:nonneg string:thing_type int:nonneg' -def cmd_THING_NAME(game, thing_id, name): +def cmd_THING_NAME(game, thing_id, name, connection_id): t = game.get_thing(thing_id) if not t: raise GameError('thing of ID %s not found' % thing_id) t.name = name + game.changed = True cmd_THING_NAME.argtypes = 'int:pos string' + +def cmd_GOD_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_GOD_THING_NAME.argtypes = 'int:pos string' diff --git a/plomrogue/game.py b/plomrogue/game.py index 45e23e1..49fdeeb 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -334,7 +334,7 @@ class Game(GameBase): write(f, 'THING %s %s %s %s' % (t.position[0], t.position[1], t.type_, t.id_)) if hasattr(t, 'name'): - write(f, 'THING_NAME %s %s' % (t.id_, quote(t.name))) + write(f, 'GOD_THING_NAME %s %s' % (t.id_, quote(t.name))) write(f, 'SPAWN_POINT %s %s' % (self.spawn_point[0], self.spawn_point[1])) diff --git a/rogue_chat.html b/rogue_chat.html index 68646f9..1ab5afc 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -63,6 +63,7 @@ keyboard input/control: + @@ -98,6 +99,7 @@ keyboard input/control:
  • +
  • @@ -122,8 +124,12 @@ let mode_helps = { 'short': 'study', 'long': 'This mode allows you to study the map and its tiles in detail. Move the question mark over a tile, and the right half of the screen will show detailed information on it. Toggle the map view to show or hide different information layers.'}, 'edit': { - 'short': 'map edit', - 'long': 'This mode allows you to change the map in various ways. Individual map tiles can be protected by "protection characters", which you can see by toggling into the protections map view. You can edit a tile if you set the map edit password that matches its protection character. The character "." marks the absence of protection: Such tiles can always be edited.' + 'short': 'world edit', + 'long': 'This mode allows you to change the game world in various ways. Individual map tiles can be protected by "protection characters", which you can see by toggling into the protections map view. You can edit a tile if you set the map edit password that matches its protection character. The character "." marks the absence of protection: Such tiles can always be edited.' + }, + 'name_thing': { + 'short': 'name thing', + 'long': 'Give name to/change name of thing here.' }, 'write': { 'short': 'change terrain', @@ -550,6 +556,7 @@ let tui = { mode_control_pw_type: new Mode('control_pw_type', true), mode_portal: new Mode('portal', true, true), mode_password: new Mode('password', true), + mode_name_thing: new Mode('name_thing', true, true), mode_admin_enter: new Mode('admin_enter', true), mode_admin: new Mode('admin'), mode_control_pw_pw: new Mode('control_pw_pw', true), @@ -562,7 +569,7 @@ let tui = { "control_tile_type", "chat", "study", "play", "edit"] this.mode_control_tile_draw.available_modes = ["admin_enter"] - this.mode_edit.available_modes = ["write", "annotate", "portal", + this.mode_edit.available_modes = ["write", "annotate", "portal", "name_thing", "password", "chat", "study", "play", "admin_enter"] this.mode = this.mode_waiting_for_server; @@ -615,6 +622,26 @@ let tui = { this.tile_draw = false; if (mode_name == 'admin_enter' && this.is_admin) { mode_name = 'admin'; + } else if (mode_name == 'name_thing') { + let player_position = game.things[game.player_id].position; + let thing_id = null; + for (let t_id in game.things) { + if (t_id == game.player_id) { + continue; + } + let t = game.things[t_id]; + if (player_position[0] == t.position[0] && player_position[1] == t.position[1]) { + thing_id = t_id; + break; + } + } + if (!thing_id) { + terminal.blink_screen(); + this.log_msg('? not standing over thing'); + return; + } else { + this.selected_thing_id = thing_id; + } }; this.mode = this['mode_' + mode_name]; if (["control_tile_draw", "control_tile_type", "control_pw_type"].includes(this.mode.name)) { @@ -681,6 +708,7 @@ let tui = { document.getElementById("switch_to_write").disabled = false; document.getElementById("switch_to_portal").disabled = false; document.getElementById("switch_to_password").disabled = false; + document.getElementById("switch_to_name_thing").disabled = false; document.getElementById("toggle_map_mode").disabled = false; } else if (this.mode.name == 'admin') { document.getElementById("switch_to_control_pw_type").disabled = false; @@ -729,6 +757,12 @@ let tui = { } else if (this.mode.name == 'password') { this.inputEl.value = this.password; this.recalc_input_lines(); + } else if (this.mode.name == 'name_thing') { + let t = game.get_thing(this.selected_thing_id); + if (t && t.name_) { + this.inputEl.value = t.name_; + this.recalc_input_lines(); + } } }, empty_input: function(str) { @@ -1260,6 +1294,12 @@ tui.inputEl.addEventListener('keydown', (event) => { } else if (tui.mode.name == 'portal' && event.key == 'Enter') { explorer.set_portal(tui.inputEl.value); tui.switch_mode('edit'); + } else if (tui.mode.name == 'name_thing' && event.key == 'Enter') { + if (tui.inputEl.value.length == 0) { + tui.inputEl.value = " "; + } + server.send(["THING_NAME", tui.selected_thing_id, tui.inputEl.value]); + tui.switch_mode('edit'); } else if (tui.mode.name == 'annotate' && event.key == 'Enter') { explorer.annotate(tui.inputEl.value); tui.switch_mode('edit'); diff --git a/rogue_chat.py b/rogue_chat.py index f4bc7cd..abdd027 100755 --- a/rogue_chat.py +++ b/rogue_chat.py @@ -7,6 +7,7 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN cmd_GOD_ANNOTATE, cmd_GOD_PORTAL, cmd_THING_TYPES, cmd_THING_NAME, cmd_TERRAINS, cmd_ADMIN_PASSWORD, cmd_BECOME_ADMIN, cmd_SET_TILE_CONTROL, + cmd_GOD_THING_NAME, cmd_SET_MAP_CONTROL_PASSWORD, cmd_SPAWN_POINT) from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP, Task_DROP, Task_FLATTEN_SURROUNDINGS) @@ -34,6 +35,7 @@ game.register_command(cmd_THING_TYPES) game.register_command(cmd_TERRAINS) game.register_command(cmd_THING) game.register_command(cmd_THING_NAME) +game.register_command(cmd_GOD_THING_NAME) game.register_command(cmd_ADMIN_PASSWORD) game.register_command(cmd_SET_TILE_CONTROL) game.register_command(cmd_SET_MAP_CONTROL_PASSWORD) diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 2adbe3b..c4fa349 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -20,8 +20,12 @@ mode_helps = { 'short': 'study', 'long': 'This mode allows you to study the map and its tiles in detail. Move the question mark over a tile, and the right half of the screen will show detailed information on it. Toggle the map view to show or hide different information layers.'}, 'edit': { - 'short': 'map edit', - 'long': 'This mode allows you to change the map in various ways. Individual map tiles can be protected by "protection characters", which you can see by toggling into the protections map view. You can edit a tile if you set the map edit password that matches its protection character. The character "." marks the absence of protection: Such tiles can always be edited.' + 'short': 'world edit', + 'long': 'This mode allows you to change the game world in various ways. Individual map tiles can be protected by "protection characters", which you can see by toggling into the protections map view. You can edit a tile if you set the map edit password that matches its protection character. The character "." marks the absence of protection: Such tiles can always be edited.' + }, + 'name_thing': { + 'short': 'name thing', + 'long': 'Give name to/change name of thing here.' }, 'write': { 'short': 'change terrain', @@ -363,6 +367,7 @@ class TUI: mode_login = Mode('login', has_input_prompt=True, is_intro=True) mode_post_login_wait = Mode('post_login_wait', is_intro=True) mode_password = Mode('password', has_input_prompt=True) + mode_name_thing = Mode('name_thing', has_input_prompt=True, shows_info=True) is_admin = False tile_draw = False @@ -375,7 +380,7 @@ class TUI: "control_tile_type", "chat", "study", "play", "edit"] self.mode_control_tile_draw.available_modes = ["admin_enter"] - self.mode_edit.available_modes = ["write", "annotate", "portal", + self.mode_edit.available_modes = ["write", "annotate", "portal", "name_thing", "password", "chat", "study", "play", "admin_enter"] self.mode = None @@ -399,6 +404,7 @@ class TUI: 'switch_to_study': '?', 'switch_to_edit': 'E', 'switch_to_write': 'm', + 'switch_to_name_thing': 'N', 'switch_to_admin_enter': 'A', 'switch_to_control_pw_type': 'C', 'switch_to_control_tile_type': 'Q', @@ -499,6 +505,9 @@ class TUI: self.input_ = self.game.portals[self.explorer] elif self.mode.name == 'password': self.input_ = self.password + elif self.mode.name == 'name_thing': + if hasattr(self.thing_selected, 'name'): + self.input_ = self.thing_selected.name def send_tile_control_command(self): self.send('SET_TILE_CONTROL %s %s' % @@ -518,6 +527,19 @@ class TUI: self.tile_draw = False if mode_name == 'admin_enter' and self.is_admin: mode_name = 'admin' + elif mode_name == 'name_thing': + player = self.game.get_thing(self.game.player_id) + thing = None + for t in [t for t in self.game.things if t.position == player.position + and t.id_ != player.id_]: + thing = t + break + if not thing: + self.flash = True + self.log_msg('? not standing over thing') + return + else: + self.thing_selected = thing self.mode = getattr(self, 'mode_' + mode_name) if self.mode.name == 'control_tile_draw': self.log_msg('@ finished tile protection drawing.') @@ -923,6 +945,12 @@ class TUI: else: self.send('ALL ' + quote(self.input_)) self.input_ = "" + elif self.mode.name == 'name_thing' and key == '\n': + if self.input_ == '': + self.input_ = ' ' + self.send('THING_NAME %s %s' % (self.thing_selected.id_, + quote(self.input_))) + self.switch_mode('edit') elif self.mode.name == 'annotate' and key == '\n': if self.input_ == '': self.input_ = ' '