X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/static/gitweb.css?a=blobdiff_plain;ds=sidebyside;f=rogue_chat.html;h=0e20ebca41b1bc563a7bc3481247b557fd4ad8ed;hb=0f1e35f5f1a318d6e3e610085babd46946ad3600;hp=3c6fe00851e7c8c2454fa49d49de170782c52508;hpb=c99f3476d21b7416d584c33bfe3b1010ada523e2;p=plomrogue2 diff --git a/rogue_chat.html b/rogue_chat.html index 3c6fe00..0e20ebc 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -664,6 +664,7 @@ let tui = { }, offset: [0,0], map_lines: [], + selectables: [], init: function() { this.mode_chat.available_modes = ["play", "study", "edit", "admin_enter"] this.mode_play.available_modes = ["chat", "study", "edit", "admin_enter", @@ -802,20 +803,20 @@ let tui = { } else if (this.mode.name == 'take_thing') { this.log_msg("selectable things:"); const player = game.things[game.player_id]; - let selectables = []; + this.selectables = []; for (const t_id in game.things) { const t = game.things[t_id]; if (t.position[0] == player.position[0] && t.position[1] == player.position[1] && t != player && t.type_ != 'Player') { - selectables.push([t_id, t]); + this.selectables.push([t_id, t]); } }; - if (selectables.length == 0) { + if (this.selectables.length == 0) { this.log_msg('none') } else { - for (const t of selectables) { - this.log_msg(t[0] + ' ' + explorer.get_thing_info(t[1])); + for (let [i, t] of this.selectables.entries()) { + this.log_msg(i + ': ' + explorer.get_thing_info(t[1])); } } } else if (this.mode.name == 'command_thing') { @@ -1400,7 +1401,12 @@ tui.inputEl.addEventListener('keydown', (event) => { if (tui.inputEl.value.length == 0) { tui.log_msg('@ aborted'); } else { - server.send(['TASK:PICK_UP', tui.inputEl.value]); + const i = parseInt(tui.inputEl.value); + if (isNaN(i) || i < 0 || i >= tui.selectables.length) { + tui.log_msg('? invalid index, aborted'); + } else { + server.send(['TASK:PICK_UP', tui.selectables[i][0]]); + } } tui.inputEl.value = ""; tui.switch_mode('play');