From: Christian Heller Date: Tue, 10 Nov 2020 05:49:03 +0000 (+0100) Subject: Don't lose input values by /help input. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/todos?a=commitdiff_plain;h=68ba631d7af62a416da8ff487534ec27b6a2d5c3;p=plomrogue2 Don't lose input values by /help input. --- diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 67f3c05..73c1a98 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -279,6 +279,16 @@ class TUI: def query_info(self): self.send('GET_ANNOTATION ' + str(self.explorer)) + def restore_input_values(self): + if self.mode.name == 'annotate' and self.explorer in self.game.info_db: + info = self.game.info_db[self.explorer] + if info != '(none)': + self.input_ = info + elif self.mode.name == 'portal' and self.explorer in self.game.portals: + self.input_ = self.game.portals[self.explorer] + elif self.mode.name == 'password': + self.input_ = self.password + def switch_mode(self, mode_name, keep_position = False): self.map_mode = 'terrain' self.mode = getattr(self, 'mode_' + mode_name) @@ -297,14 +307,7 @@ class TUI: elif self.mode.name == 'teleport': self.log_msg("@ May teleport to %s" % (self.teleport_target_host)), self.log_msg("@ Enter 'YES!' to enthusiastically affirm."); - elif self.mode.name == 'annotate' and self.explorer in self.game.info_db: - info = self.game.info_db[self.explorer] - if info != '(none)': - self.input_ = info - elif self.mode.name == 'portal' and self.explorer in self.game.portals: - self.input_ = self.game.portals[self.explorer] - elif self.mode.name == 'password': - self.input_ = self.password + self.restore_input_values() def loop(self, stdscr): import time @@ -586,6 +589,7 @@ class TUI: elif self.mode.has_input_prompt and key == '\n' and self.input_ == '/help': self.show_help = True self.input_ = "" + self.restore_input_values() elif self.mode.has_input_prompt and key != '\n': # Return key self.input_ += key max_length = self.window_width * self.size.y - len(input_prompt) - 1 diff --git a/rogue_chat_nocanvas_monochrome.html b/rogue_chat_nocanvas_monochrome.html index 6041871..8634959 100644 --- a/rogue_chat_nocanvas_monochrome.html +++ b/rogue_chat_nocanvas_monochrome.html @@ -355,13 +355,8 @@ let tui = { } this.mode = mode; this.empty_input(); - if (mode == mode_annotate && explorer.position in explorer.info_db) { - let info = explorer.info_db[explorer.position]; - if (info != "(none)") { - this.inputEl.value = info; - this.recalc_input_lines(); - } - } else if (mode == mode_login) { + this.restore_input_values(); + if (mode == mode_login) { if (this.login_name) { server.send(['LOGIN', this.login_name]); } else { @@ -369,19 +364,28 @@ let tui = { } } else if (mode == mode_edit) { this.show_help = true; - } else if (mode == mode_portal && explorer.position in game.portals) { - let portal = game.portals[explorer.position] - this.inputEl.value = portal; - this.recalc_input_lines(); - } else if (mode == mode_password) { - this.inputEl.value = this.password; - this.recalc_input_lines(); } else if (mode == mode_teleport) { tui.log_msg("@ May teleport to: " + tui.teleport_target); tui.log_msg("@ Enter 'YES!' to entusiastically affirm."); } this.full_refresh(); }, + restore_input_values: function() { + if (this.mode == mode_annotate && explorer.position in explorer.info_db) { + let info = explorer.info_db[explorer.position]; + if (info != "(none)") { + this.inputEl.value = info; + this.recalc_input_lines(); + } + } else if (this.mode == mode_portal && explorer.position in game.portals) { + let portal = game.portals[explorer.position] + this.inputEl.value = portal; + this.recalc_input_lines(); + } else if (this.mode == mode_password) { + this.inputEl.value = this.password; + this.recalc_input_lines(); + } + }, empty_input: function(str) { this.inputEl.value = ""; if (this.mode.has_input_prompt) { @@ -743,6 +747,7 @@ tui.inputEl.addEventListener('keydown', (event) => { if (tui.mode.has_input_prompt && event.key == 'Enter' && tui.inputEl.value == '/help') { tui.show_help = true; tui.empty_input(); + tui.restore_input_values(); tui.full_refresh(); } else if (!tui.mode.has_input_prompt && event.key == tui.keys.help) { tui.show_help = true;