From: Christian Heller Date: Sun, 13 Dec 2020 05:17:29 +0000 (+0100) Subject: In clients, enter ASCII art line by line. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/static/process?a=commitdiff_plain;h=0e37b2aedc1f83084d79df697e31722bd5c4c3c3;p=plomrogue2 In clients, enter ASCII art line by line. --- diff --git a/rogue_chat.html b/rogue_chat.html index d86eec5..45a8525 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -718,6 +718,8 @@ let tui = { }, offset: [0,0], map_lines: [], + ascii_draw_stage: 0, + full_ascii_draw: '', selectables: [], draw_face: false, init: function() { @@ -911,6 +913,8 @@ let tui = { for (let [i, direction] of this.selectables.entries()) { this.log_msg(i + ': ' + direction); }; + } else if (this.mode.name == 'enter_hat') { + this.log_msg('legal characters: ' + game.players_hat_chars); } else if (this.mode.name == 'command_thing') { server.send(['TASK:COMMAND', 'HELP']); } else if (this.mode.name == 'control_pw_pw') { @@ -953,10 +957,14 @@ let tui = { if (t && t.protection) { this.inputEl.value = t.protection; } - } else if (this.mode.name == 'enter_face' && game.player.face) { - this.inputEl.value = game.player.face; - } else if (this.mode.name == 'enter_hat' && game.player.hat) { - this.inputEl.value = game.player.hat; + } else if (['enter_face', 'enter_hat'].includes(this.mode.name)) { + const start = this.ascii_draw_stage * 6; + const end = (this.ascii_draw_stage + 1) * 6; + if (this.mode.name == 'enter_face') { + this.inputEl.value = game.player.face.slice(start, end); + } else if (this.mode.name == 'enter_hat') { + this.inputEl.value = game.player.hat.slice(start, end); + } } }, recalc_input_lines: function() { @@ -1045,6 +1053,24 @@ let tui = { this.inputEl.value = ""; this.switch_mode('play'); }, + enter_ascii_art: function(command) { + if (this.inputEl.value.length != 6) { + this.log_msg('? wrong input length, try again'); + return; + } + this.log_msg(' ' + this.inputEl.value); + this.full_ascii_draw += this.inputEl.value; + this.ascii_draw_stage += 1; + if (this.ascii_draw_stage < 3) { + this.restore_input_values(); + } else { + server.send([command, this.full_ascii_draw]); + this.full_ascii_draw = ''; + this.ascii_draw_stage = 0; + this.inputEl.value = ''; + this.switch_mode('edit'); + } + }, draw_map: function() { if (!game.turn_complete && this.map_lines.length == 0) { return; @@ -1552,21 +1578,9 @@ tui.inputEl.addEventListener('keydown', (event) => { server.send(['LOGIN', tui.inputEl.value]); tui.inputEl.value = ""; } else if (tui.mode.name == 'enter_face' && event.key == 'Enter') { - if (tui.inputEl.value.length != 18) { - tui.log_msg('? wrong input length, aborting'); - } else { - server.send(['PLAYER_FACE', tui.inputEl.value]); - } - tui.inputEl.value = ""; - tui.switch_mode('edit'); + tui.enter_ascii_art('PLAYER_FACE'); } else if (tui.mode.name == 'enter_hat' && event.key == 'Enter') { - if (tui.inputEl.value.length != 18) { - tui.log_msg('? wrong input length, aborting'); - } else { - server.send(['PLAYER_HAT', tui.inputEl.value]); - } - tui.inputEl.value = ""; - tui.switch_mode('edit'); + tui.enter_ascii_art('PLAYER_HAT'); } else if (tui.mode.name == 'command_thing' && event.key == 'Enter') { server.send(['TASK:COMMAND', tui.inputEl.value]); tui.inputEl.value = ""; diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 41ad640..ebefc10 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -582,6 +582,8 @@ class TUI: self.fov = '' self.flash = False self.map_lines = [] + self.ascii_draw_stage = 0 + self.full_ascii_draw = '' self.offset = YX(0,0) curses.wrapper(self.loop) @@ -652,10 +654,13 @@ class TUI: elif self.mode.name == 'admin_thing_protect': if hasattr(self.thing_selected, 'protection'): self.input_ = self.thing_selected.protection - elif self.mode.name == 'enter_face': - self.input_ = self.game.player.face - elif self.mode.name == 'enter_hat': - self.input_ = self.game.player.hat + elif self.mode.name in {'enter_face', 'enter_hat'}: + start = self.ascii_draw_stage * 6 + end = (self.ascii_draw_stage + 1) * 6 + if self.mode.name == 'enter_face': + self.input_ = self.game.player.face[start:end] + elif self.mode.name == 'enter_hat': + self.input_ = self.game.player.hat[start:end] def send_tile_control_command(self): self.send('SET_TILE_CONTROL %s %s' % @@ -1091,6 +1096,22 @@ class TUI: self.input_ = '' self.switch_mode('play') + def enter_ascii_art(command): + if len(self.input_) != 6: + self.log_msg('? wrong input length, try again') + return + self.log_msg(' ' + self.input_) + self.full_ascii_draw += self.input_ + self.ascii_draw_stage += 1 + if self.ascii_draw_stage < 3: + self.restore_input_values() + else: + self.send('%s %s' % (command, quote(self.full_ascii_draw))) + self.full_ascii_draw = "" + self.ascii_draw_stage = 0 + self.input_ = "" + self.switch_mode('edit') + action_descriptions = { 'move': 'move', 'flatten': 'flatten surroundings', @@ -1192,19 +1213,9 @@ class TUI: self.send('LOGIN ' + quote(self.input_)) self.input_ = "" elif self.mode.name == 'enter_face' and key == '\n': - if len(self.input_) != 18: - self.log_msg('? wrong input length, aborting') - else: - self.send('PLAYER_FACE %s' % quote(self.input_)) - self.input_ = "" - self.switch_mode('edit') + enter_ascii_art('PLAYER_FACE') elif self.mode.name == 'enter_hat' and key == '\n': - if len(self.input_) != 18: - self.log_msg('? wrong input length, aborting') - else: - self.send('PLAYER_HAT %s' % quote(self.input_)) - self.input_ = "" - self.switch_mode('edit') + enter_ascii_art('PLAYER_HAT') elif self.mode.name == 'take_thing' and key == '\n': pick_selectable('PICK_UP') elif self.mode.name == 'drop_thing' and key == '\n':