X-Git-Url: https://plomlompom.com/repos/day?a=blobdiff_plain;f=rogue_chat.html;h=5338e9daf323f1f8aef596ea5634407d2182d391;hb=c3ada0bf213337ff2c97e2f33bbf6e6dbedaea38;hp=1847c0904ec9f7452efc718fa9265521e0bd7686;hpb=3b86e8effe9aa77fa87f86a1057d12d4c8019324;p=plomrogue2 diff --git a/rogue_chat.html b/rogue_chat.html index 1847c09..5338e9d 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -933,12 +933,15 @@ let tui = { this.log_msg(i + ': ' + direction); }; } else if (this.mode.name == 'enter_design') { - this.log_msg('@ The design you enter must be ' - + game.player.carrying.design[0][0] + ' lines of max ' - + game.player.carrying.design[0][1] + ' characters width each'); if (game.player.carrying.type_ == 'Hat') { + this.log_msg('@ The design you enter must be ' + + game.player.carrying.design[0][0] + ' lines of max ' + + game.player.carrying.design[0][1] + ' characters width each'); this.log_msg('@ Legal characters: ' + game.players_hat_chars); this.log_msg('@ (Eat cookies to extend the ASCII characters available for drawing.)'); + } else { + this.log_msg('@ Width of first line determines maximum width for remaining design') + this.log_msg('@ Finish design by entering an empty line (multiple space characters do not count as empty)') } } else if (this.mode.name == 'command_thing') { server.send(['TASK:COMMAND', 'HELP']); @@ -1078,31 +1081,55 @@ let tui = { this.inputEl.value = ""; this.switch_mode('play'); }, - enter_ascii_art: function(command, height, width, with_pw=false) { - if (this.inputEl.value.length > width) { - this.log_msg('? wrong input length, must be max ' + width + '; try again'); - return; - } else if (this.inputEl.value.length < width) { - while (this.inputEl.value.length < width) { - this.inputEl.value += ' '; - } - } - this.log_msg(' ' + this.inputEl.value); - this.full_ascii_draw += this.inputEl.value; - this.ascii_draw_stage += 1; - if (this.ascii_draw_stage < height) { - this.restore_input_values(); - } else { - if (with_pw) { - server.send([command, this.full_ascii_draw, this.password]); - } else { - server.send([command, this.full_ascii_draw]); - } - this.full_ascii_draw = ''; - this.ascii_draw_stage = 0; - this.inputEl.value = ''; - this.switch_mode('edit'); - } + enter_ascii_art: function(command, height, width, with_pw=false, with_size=false) { + if (with_size && this.ascii_draw_stage == 0) { + width = this.inputEl.value.length; + if (width > 36) { + this.log_msg('? wrong input length, must be max 36; try again'); + return; + } + if (width != game.player.carrying.design[0][1]) { + game.player.carrying.design[1] = ''; + game.player.carrying.design[0][1] = width; + } + } else if (this.inputEl.value.length > width) { + this.log_msg('? wrong input length, must be max ' + width + '; try again'); + return; + } + this.log_msg(' ' + this.inputEl.value); + if (with_size && ['', ' '].includes(this.inputEl.value) && this.ascii_draw_stage > 0) { + height = this.ascii_draw_stage; + } else { + if (with_size) { + height = this.ascii_draw_stage + 2; + } + while (this.inputEl.value.length < width) { + this.inputEl.value += ' '; + } + this.full_ascii_draw += this.inputEl.value; + } + if (with_size) { + game.player.carrying.design[0][0] = height; + } + this.ascii_draw_stage += 1; + if (this.ascii_draw_stage < height) { + this.restore_input_values(); + } else { + if (with_pw && with_size) { + server.send([command + '_SIZE', + unparser.to_yx(game.player.carrying.design[0]), + this.password]); + } + if (with_pw) { + server.send([command, this.full_ascii_draw, this.password]); + } 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) { @@ -1570,8 +1597,12 @@ let explorer = { if (t.design) { const line_length = t.design[0][1]; info += '-'.repeat(line_length + 4) + '\n'; - const regexp = RegExp('.{1,' + line_length + '}', 'g'); - const lines = t.design[1].match(regexp); + console.log(line_length) + let lines = [''] + if (line_length > 0) { + const regexp = RegExp('.{1,' + line_length + '}', 'g'); + lines = t.design[1].match(regexp); + } for (const line of lines) { info += '| ' + line + ' |\n'; } @@ -1644,9 +1675,15 @@ tui.inputEl.addEventListener('keydown', (event) => { } else if (tui.mode.name == 'enter_face' && event.key == 'Enter') { tui.enter_ascii_art('PLAYER_FACE', 3, 6); } else if (tui.mode.name == 'enter_design' && event.key == 'Enter') { - tui.enter_ascii_art('THING_DESIGN', - game.player.carrying.design[0][0], - game.player.carrying.design[0][1], true); + if (game.player.carrying.type_ == 'Hat') { + tui.enter_ascii_art('THING_DESIGN', + game.player.carrying.design[0][0], + game.player.carrying.design[0][1], true); + } else { + tui.enter_ascii_art('THING_DESIGN', + game.player.carrying.design[0][0], + game.player.carrying.design[0][1], true, true); + } } else if (tui.mode.name == 'command_thing' && event.key == 'Enter') { server.send(['TASK:COMMAND', tui.inputEl.value]); tui.inputEl.value = "";