7 terminal rows: <input id="n_rows" type="number" step=4 min=8 value=24 />
8 terminal columns: <input id="n_cols" type="number" step=4 min=20 value=80 />
10 <pre id="terminal" style="display: inline-block;"></pre>
11 <textarea id="input" style="opacity: 0; width: 0px;"></textarea>
13 keys (see <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">here</a> for non-obvious available values):<br />
14 move up (square grid): <input id="key_square_move_up" type="text" value="w" /> (hint: ArrowUp)<br />
15 move left (square grid): <input id="key_square_move_left" type="text" value="a" /> (hint: ArrowLeft)<br />
16 move down (square grid): <input id="key_square_move_down" type="text" value="s" /> (hint: ArrowDown)<br />
17 move right (square grid): <input id="key_square_move_right" type="text" value="d" /> (hint: ArrowRight)<br />
18 move up-left (hex grid): <input id="key_hex_move_upleft" type="text" value="w" /><br />
19 move up-right (hex grid): <input id="key_hex_move_upright" type="text" value="e" /><br />
20 move right (hex grid): <input id="key_hex_move_right" type="text" value="d" /><br />
21 move down-right (hex grid): <input id="key_hex_move_downright" type="text" value="x" /><br />
22 move down-left (hex grid): <input id="key_hex_move_downleft" type="text" value="y" /><br />
23 move left (hex grid): <input id="key_hex_move_left" type="text" value="a" /><br />
24 flatten surroundings: <input id="key_flatten" type="text" value="F" /><br />
25 switch to chat mode: <input id="key_switch_to_chat" type="text" value="t" /><br />
26 switch to play mode: <input id="key_switch_to_play" type="text" value="p" /><br />
27 switch to study mode: <input id="key_switch_to_study" type="text" value="?" /><br />
28 edit terrain (from play mode): <input id="key_switch_to_edit" type="text" value="m" /><br />
29 enter terrain password (from play mode): <input id="key_switch_to_password" type="text" value="P" /><br />
30 annotate terrain (from study mode): <input id="key_switch_to_annotate" type="text" value="m" /><br />
31 annotate portal (from study mode): <input id="key_switch_to_portal" type="text" value="P" /><br />
32 toggle terrain/control view (from study mode): <input id="key_toggle_map_mode" type="text" value="M" /><br />
36 let websocket_location = "wss://plomlompom.com/rogue_chat/";
38 let rows_selector = document.getElementById("n_rows");
39 let cols_selector = document.getElementById("n_cols");
40 let key_selectors = document.querySelectorAll('[id^="key_"]');
42 function restore_selector_value(selector) {
43 let stored_selection = window.localStorage.getItem(selector.id);
44 if (stored_selection) {
45 selector.value = stored_selection;
48 restore_selector_value(rows_selector);
49 restore_selector_value(cols_selector);
50 for (let key_selector of key_selectors) {
51 restore_selector_value(key_selector);
57 initialize: function() {
58 this.rows = rows_selector.value;
59 this.cols = cols_selector.value;
60 this.pre_el = document.getElementById("terminal");
61 this.pre_el.style.color = this.foreground;
62 this.pre_el.style.backgroundColor = this.background;
65 for (let y = 0, x = 0; y <= this.rows; x++) {
69 this.content.push(line);
78 blink_screen: function() {
79 this.pre_el.style.color = this.background;
80 this.pre_el.style.backgroundColor = this.foreground;
82 this.pre_el.style.color = this.foreground;
83 this.pre_el.style.backgroundColor = this.background;
88 for (let y = 0; y < this.rows; y++) {
89 let line = this.content[y].join('');
90 pre_string += line + '\n';
92 this.pre_el.textContent = pre_string;
94 write: function(start_y, start_x, msg) {
95 for (let x = start_x, i = 0; x < this.cols && i < msg.length; x++, i++) {
96 this.content[start_y][x] = msg[i];
99 drawBox: function(start_y, start_x, height, width) {
100 let end_y = start_y + height;
101 let end_x = start_x + width;
102 for (let y = start_y, x = start_x; y < this.rows; x++) {
110 this.content[y][x] = ' ';
114 terminal.initialize();
117 tokenize: function(str) {
123 for (let i = 0; i < str.length; i++) {
129 } else if (c == '\\') {
131 } else if (c == '"') {
136 } else if (c == '"') {
138 } else if (c === ' ') {
139 if (token.length > 0) {
148 if (token.length > 0) {
151 let token_starts = [];
152 for (let i = 0; i < token_ends.length; i++) {
153 token_starts.push(token_ends[i] - tokens[i].length);
155 return [tokens, token_starts];
157 parse_yx: function(position_string) {
158 let coordinate_strings = position_string.split(',')
159 let position = [0, 0];
160 position[0] = parseInt(coordinate_strings[0].slice(2));
161 position[1] = parseInt(coordinate_strings[1].slice(2));
173 init: function(url) {
175 this.websocket = new WebSocket(this.url);
176 this.websocket.onopen = function(event) {
177 window.setInterval(function() { server.send(['PING']) }, 30000);
179 tui.log_msg("@ server connected! :)");
180 tui.switch_mode(mode_login);
182 this.websocket.onclose = function(event) {
183 tui.log_msg("@ server disconnected :(");
184 tui.log_msg("@ hint: try the '/reconnect' command");
186 this.websocket.onmessage = this.handle_event;
188 reconnect: function() {
189 this.reconnect_to(this.url);
191 reconnect_to: function(url) {
192 this.websocket.close();
195 send: function(tokens) {
196 this.websocket.send(unparser.untokenize(tokens));
198 handle_event: function(event) {
199 let tokens = parser.tokenize(event.data)[0];
200 if (tokens[0] === 'TURN') {
201 game.turn_complete = false;
204 game.turn = parseInt(tokens[1]);
205 } else if (tokens[0] === 'THING_POS') {
206 game.get_thing(tokens[1], true).position = parser.parse_yx(tokens[2]);
207 } else if (tokens[0] === 'THING_NAME') {
208 game.get_thing(tokens[1], true).name_ = tokens[2];
209 } else if (tokens[0] === 'TASKS') {
210 game.tasks = tokens[1].split(',')
211 } else if (tokens[0] === 'MAP') {
212 game.map_geometry = tokens[1];
214 game.map_size = parser.parse_yx(tokens[2]);
216 } else if (tokens[0] === 'MAP_CONTROL') {
217 game.map_control = tokens[1]
218 } else if (tokens[0] === 'GAME_STATE_COMPLETE') {
219 game.turn_complete = true;
220 explorer.empty_info_db();
221 if (tui.mode == mode_post_login_wait) {
222 tui.switch_mode(mode_play);
224 } else if (tui.mode == mode_study) {
225 explorer.query_info();
227 let t = game.get_thing(game.player_id);
228 if (t.position in game.portals) {
229 tui.teleport_target = game.portals[t.position];
230 tui.switch_mode(mode_teleport);
234 } else if (tokens[0] === 'CHAT') {
235 tui.log_msg('# ' + tokens[1], 1);
236 } else if (tokens[0] === 'PLAYER_ID') {
237 game.player_id = parseInt(tokens[1]);
238 } else if (tokens[0] === 'LOGIN_OK') {
239 this.send(['GET_GAMESTATE']);
240 tui.switch_mode(mode_post_login_wait);
241 } else if (tokens[0] === 'PORTAL') {
242 let position = parser.parse_yx(tokens[1]);
243 game.portals[position] = tokens[2];
244 } else if (tokens[0] === 'ANNOTATION') {
245 let position = parser.parse_yx(tokens[1]);
246 explorer.update_info_db(position, tokens[2]);
247 } else if (tokens[0] === 'UNHANDLED_INPUT') {
248 tui.log_msg('? unknown command');
249 } else if (tokens[0] === 'PLAY_ERROR') {
250 terminal.blink_screen();
251 } else if (tokens[0] === 'ARGUMENT_ERROR') {
252 tui.log_msg('? syntax error: ' + tokens[1]);
253 } else if (tokens[0] === 'GAME_ERROR') {
254 tui.log_msg('? game error: ' + tokens[1]);
255 } else if (tokens[0] === 'PONG') {
258 tui.log_msg('? unhandled input: ' + event.data);
264 quote: function(str) {
266 for (let i = 0; i < str.length; i++) {
268 if (['"', '\\'].includes(c)) {
274 return quoted.join('');
276 to_yx: function(yx_coordinate) {
277 return "Y:" + yx_coordinate[0] + ",X:" + yx_coordinate[1];
279 untokenize: function(tokens) {
280 let quoted_tokens = [];
281 for (let token of tokens) {
282 quoted_tokens.push(this.quote(token));
284 return quoted_tokens.join(" ");
289 constructor(name, has_input_prompt=false, shows_info=false, is_intro=false) {
291 this.has_input_prompt = has_input_prompt;
292 this.shows_info= shows_info;
293 this.is_intro = is_intro;
296 let mode_waiting_for_server = new Mode('waiting_for_server', false, false, true);
297 let mode_login = new Mode('login', true, false, true);
298 let mode_post_login_wait = new Mode('waiting for game world', false, false, true);
299 let mode_chat = new Mode('chat / write messages to players', true, false);
300 let mode_annotate = new Mode('add message to map tile', true, true);
301 let mode_play = new Mode('play / move around', false, false);
302 let mode_study = new Mode('check map tiles for messages', false, true);
303 let mode_edit = new Mode('write ASCII char to map tile', false, false);
304 let mode_teleport = new Mode('teleport away?', true);
305 let mode_portal = new Mode('add portal to map tile', true, true);
306 let mode_password = new Mode('enter terrain password', true, false, false);
309 mode: mode_waiting_for_server,
313 window_width: terminal.cols / 2,
319 this.inputEl = document.getElementById("input");
320 this.inputEl.focus();
321 this.recalc_input_lines();
322 this.height_header = this.height_turn_line + this.height_mode_line;
323 this.log_msg("@ waiting for server connection ...");
326 init_keys: function() {
328 for (let key_selector of key_selectors) {
329 this.keys[key_selector.id.slice(4)] = key_selector.value;
331 if (game.map_geometry == 'Square') {
332 this.movement_keys = {
333 [this.keys.square_move_up]: 'UP',
334 [this.keys.square_move_left]: 'LEFT',
335 [this.keys.square_move_down]: 'DOWN',
336 [this.keys.square_move_right]: 'RIGHT'
338 } else if (game.map_geometry == 'Hex') {
339 this.movement_keys = {
340 [this.keys.hex_move_upleft]: 'UPLEFT',
341 [this.keys.hex_move_upright]: 'UPRIGHT',
342 [this.keys.hex_move_right]: 'RIGHT',
343 [this.keys.hex_move_downright]: 'DOWNRIGHT',
344 [this.keys.hex_move_downleft]: 'DOWNLEFT',
345 [this.keys.hex_move_left]: 'LEFT'
349 switch_mode: function(mode, keep_pos=false) {
350 this.map_mode = 'terrain';
351 if (mode == mode_study && !keep_pos && game.player_id in game.things) {
352 explorer.position = game.things[game.player_id].position;
356 if (mode == mode_annotate && explorer.position in explorer.info_db) {
357 let info = explorer.info_db[explorer.position];
358 if (info != "(none)") {
359 this.inputEl.value = info;
360 this.recalc_input_lines();
363 if (mode == mode_login) {
364 if (this.login_name) {
365 server.send(['LOGIN', this.login_name]);
367 this.log_msg("? need login name");
369 } else if (mode == mode_portal && explorer.position in game.portals) {
370 let portal = game.portals[explorer.position]
371 this.inputEl.value = portal;
372 this.recalc_input_lines();
373 } else if (mode == mode_password) {
374 this.inputEl.value = this.password;
375 this.recalc_input_lines();
376 } else if (mode == mode_teleport) {
377 tui.log_msg("@ May teleport to: " + tui.teleport_target);
378 tui.log_msg("@ Enter 'YES!' to entusiastically affirm.");
382 empty_input: function(str) {
383 this.inputEl.value = "";
384 if (this.mode.has_input_prompt) {
385 this.recalc_input_lines();
387 this.height_input = 0;
390 recalc_input_lines: function() {
391 this.input_lines = this.msg_into_lines_of_width(this.input_prompt + this.inputEl.value, this.window_width);
392 this.height_input = this.input_lines.length;
394 msg_into_lines_of_width: function(msg, width) {
397 for (let i = 0, x = 0; i < msg.length; i++, x++) {
398 if (x >= width || msg[i] == "\n") {
403 if (msg[i] != "\n") {
410 log_msg: function(msg) {
412 while (this.log.length > 100) {
417 log_help: function() {
418 let movement_keys_desc = Object.keys(this.movement_keys).join(',');
419 this.log_msg("HELP:");
420 this.log_msg("chat mode commands:");
421 this.log_msg(" /nick NAME - re-name yourself to NAME");
422 this.log_msg(" /msg USER TEXT - send TEXT to USER");
423 this.log_msg(" /help - show this help");
424 this.log_msg(" /" + this.keys.switch_to_play + " or /play - switch to play mode");
425 this.log_msg(" /" + this.keys.switch_to_study + " or /study - switch to study mode");
426 this.log_msg("commands common to study and play mode:");
427 if (game.tasks.includes('MOVE')) {
428 this.log_msg(" " + movement_keys_desc + " - move");
430 this.log_msg(" " + this.keys.switch_to_chat + " - switch to chat mode");
431 this.log_msg("commands specific to play mode:");
432 this.log_msg(" " + this.keys.switch_to_password + " - enter terrain password");
433 if (game.tasks.includes('WRITE')) {
434 this.log_msg(" " + this.keys.switch_to_edit + " - write following ASCII character");
436 if (game.tasks.includes('FLATTEN_SURROUNDINGS')) {
437 this.log_msg(" " + this.keys.flatten + " - flatten surroundings");
439 this.log_msg(" " + this.keys.switch_to_study + " - switch to study mode");
440 this.log_msg("commands specific to study mode:");
441 this.log_msg(" " + this.keys.switch_to_play + " - switch to play mode");
442 if (!game.tasks.includes('MOVE')) {
443 this.log_msg(" " + movement_keys_desc + " - move");
445 this.log_msg(" " + this.keys.switch_to_annotate + " - annotate terrain");
446 this.log_msg(" " + this.keys.toggle_map_mode + " - toggle terrain/control view");
448 draw_map: function() {
449 let map_lines_split = [];
451 let map_content = game.map;
452 if (this.map_mode == 'control') {
453 map_content = game.map_control;
455 for (let i = 0, j = 0; i < game.map.length; i++, j++) {
456 if (j == game.map_size[1]) {
457 map_lines_split.push(line);
461 line.push(map_content[i]);
463 map_lines_split.push(line);
464 if (this.map_mode == 'terrain') {
465 for (const thing_id in game.things) {
466 let t = game.things[thing_id];
467 map_lines_split[t.position[0]][t.position[1]] = '@';
470 if (tui.mode.shows_info) {
471 map_lines_split[explorer.position[0]][explorer.position[1]] = '?';
474 if (game.map_geometry == 'Square') {
475 for (let line_split of map_lines_split) {
476 map_lines.push(line_split.join(' '));
478 } else if (game.map_geometry == 'Hex') {
480 for (let line_split of map_lines_split) {
481 map_lines.push(' '.repeat(indent) + line_split.join(' '));
489 let window_center = [terminal.rows / 2, this.window_width / 2];
490 let player = game.things[game.player_id];
491 let center_position = [player.position[0], player.position[1]];
492 if (tui.mode.shows_info) {
493 center_position = [explorer.position[0], explorer.position[1]];
495 center_position[1] = center_position[1] * 2;
496 let offset = [center_position[0] - window_center[0],
497 center_position[1] - window_center[1]]
498 if (game.map_geometry == 'Hex' && offset[0] % 2) {
501 let term_y = Math.max(0, -offset[0]);
502 let term_x = Math.max(0, -offset[1]);
503 let map_y = Math.max(0, offset[0]);
504 let map_x = Math.max(0, offset[1]);
505 for (; term_y < terminal.rows && map_y < game.map_size[0]; term_y++, map_y++) {
506 let to_draw = map_lines[map_y].slice(map_x, this.window_width + offset[1]);
507 terminal.write(term_y, term_x, to_draw);
510 draw_mode_line: function() {
511 terminal.write(0, this.window_width, 'MODE: ' + this.mode.name);
513 draw_turn_line: function(n) {
514 terminal.write(1, this.window_width, 'TURN: ' + game.turn);
516 draw_history: function() {
517 let log_display_lines = [];
518 for (let line of this.log) {
519 log_display_lines = log_display_lines.concat(this.msg_into_lines_of_width(line, this.window_width));
521 for (let y = terminal.rows - 1 - this.height_input,
522 i = log_display_lines.length - 1;
523 y >= this.height_header && i >= 0;
525 terminal.write(y, this.window_width, log_display_lines[i]);
528 draw_info: function() {
529 let lines = this.msg_into_lines_of_width(explorer.get_info(), this.window_width);
530 for (let y = this.height_header, i = 0; y < terminal.rows && i < lines.length; y++, i++) {
531 terminal.write(y, this.window_width, lines[i]);
534 draw_input: function() {
535 if (this.mode.has_input_prompt) {
536 for (let y = terminal.rows - this.height_input, i = 0; i < this.input_lines.length; y++, i++) {
537 terminal.write(y, this.window_width, this.input_lines[i]);
541 full_refresh: function() {
542 terminal.drawBox(0, 0, terminal.rows, terminal.cols);
543 if (this.mode.is_intro) {
547 if (game.turn_complete) {
549 this.draw_turn_line();
551 this.draw_mode_line();
552 if (this.mode.shows_info) {
568 this.map_control = "";
569 this.map_size = [0,0];
574 get_thing: function(id_, create_if_not_found=false) {
575 if (id_ in game.things) {
576 return game.things[id_];
577 } else if (create_if_not_found) {
578 let t = new Thing([0,0]);
579 game.things[id_] = t;
583 move: function(start_position, direction) {
584 let target = [start_position[0], start_position[1]];
585 if (direction == 'LEFT') {
587 } else if (direction == 'RIGHT') {
589 } else if (game.map_geometry == 'Square') {
590 if (direction == 'UP') {
592 } else if (direction == 'DOWN') {
595 } else if (game.map_geometry == 'Hex') {
596 let start_indented = start_position[0] % 2;
597 if (direction == 'UPLEFT') {
599 if (!start_indented) {
602 } else if (direction == 'UPRIGHT') {
604 if (start_indented) {
607 } else if (direction == 'DOWNLEFT') {
609 if (!start_indented) {
612 } else if (direction == 'DOWNRIGHT') {
614 if (start_indented) {
619 if (target[0] < 0 || target[1] < 0 ||
620 target[0] >= this.map_size[0] || target[1] >= this.map_size[1]) {
630 server.init(websocket_location);
635 move: function(direction) {
636 let target = game.move(this.position, direction);
638 this.position = target
642 terminal.blink_screen();
645 update_info_db: function(yx, str) {
646 this.info_db[yx] = str;
647 if (tui.mode == mode_study) {
651 empty_info_db: function() {
653 if (tui.mode == mode_study) {
657 query_info: function() {
658 server.send(["GET_ANNOTATION", unparser.to_yx(explorer.position)]);
660 get_info: function() {
662 let position_i = this.position[0] * game.map_size[1] + this.position[1];
663 info += "TERRAIN: " + game.map[position_i] + "\n";
664 for (let t_id in game.things) {
665 let t = game.things[t_id];
666 if (t.position[0] == this.position[0] && t.position[1] == this.position[1]) {
669 info += ": " + t.name_;
674 if (this.position in game.portals) {
675 info += "PORTAL: " + game.portals[this.position] + "\n";
677 if (this.position in this.info_db) {
678 info += "ANNOTATIONS: " + this.info_db[this.position];
684 annotate: function(msg) {
685 if (msg.length == 0) {
686 msg = " "; // triggers annotation deletion
688 server.send(["ANNOTATE", unparser.to_yx(explorer.position), msg]);
690 set_portal: function(msg) {
691 if (msg.length == 0) {
692 msg = " "; // triggers portal deletion
694 server.send(["PORTAL", unparser.to_yx(explorer.position), msg]);
698 tui.inputEl.addEventListener('input', (event) => {
699 if (tui.mode.has_input_prompt) {
700 let max_length = tui.window_width * terminal.rows - tui.input_prompt.length;
701 if (tui.inputEl.value.length > max_length) {
702 tui.inputEl.value = tui.inputEl.value.slice(0, max_length);
704 tui.recalc_input_lines();
706 } else if (tui.mode == mode_edit && tui.inputEl.value.length > 0) {
707 server.send(["TASK:WRITE", tui.inputEl.value[0], tui.password]);
708 tui.switch_mode(mode_play);
709 } else if (tui.mode == mode_teleport) {
710 if (['Y', 'y'].includes(tui.inputEl.value[0])) {
711 server.reconnect_to(tui.teleport_target);
713 tui.log_msg("@ teleportation aborted");
714 tui.switch_mode(mode_play);
718 tui.inputEl.addEventListener('keydown', (event) => {
719 if (event.key == 'Enter') {
720 event.preventDefault();
722 if (tui.mode == mode_login && event.key == 'Enter') {
723 tui.login_name = tui.inputEl.value;
724 server.send(['LOGIN', tui.inputEl.value]);
726 } else if (tui.mode == mode_portal && event.key == 'Enter') {
727 explorer.set_portal(tui.inputEl.value);
728 tui.switch_mode(mode_study, true);
729 } else if (tui.mode == mode_annotate && event.key == 'Enter') {
730 explorer.annotate(tui.inputEl.value);
731 tui.switch_mode(mode_study, true);
732 } else if (tui.mode == mode_password && event.key == 'Enter') {
733 if (tui.inputEl.value.length == 0) {
734 tui.inputEl.value = " ";
736 tui.password = tui.inputEl.value
737 tui.switch_mode(mode_play);
738 } else if (tui.mode == mode_teleport && event.key == 'Enter') {
739 if (tui.inputEl.value == 'YES!') {
740 server.reconnect_to(tui.teleport_target);
742 tui.log_msg('@ teleport aborted');
743 tui.switch_mode(mode_play);
745 } else if (tui.mode == mode_chat && event.key == 'Enter') {
746 let [tokens, token_starts] = parser.tokenize(tui.inputEl.value);
747 if (tokens.length > 0 && tokens[0].length > 0) {
748 if (tui.inputEl.value[0][0] == '/') {
749 if (tokens[0].slice(1) == 'play' || tokens[0][1] == tui.keys.switch_to_play) {
750 tui.switch_mode(mode_play);
751 } else if (tokens[0].slice(1) == 'study' || tokens[0][1] == tui.keys.switch_to_study) {
752 tui.switch_mode(mode_study);
753 } else if (tokens[0].slice(1) == 'help') {
755 } else if (tokens[0].slice(1) == 'nick') {
756 if (tokens.length > 1) {
757 server.send(['NICK', tokens[1]]);
759 tui.log_msg('? need new name');
761 } else if (tokens[0].slice(1) == 'msg') {
762 if (tokens.length > 2) {
763 let msg = tui.inputEl.value.slice(token_starts[2]);
764 server.send(['QUERY', tokens[1], msg]);
766 tui.log_msg('? need message target and message');
768 } else if (tokens[0].slice(1) == 'reconnect') {
769 if (tokens.length > 1) {
770 server.reconnect_to(tokens[1]);
775 tui.log_msg('? unknown command');
778 server.send(['ALL', tui.inputEl.value]);
780 } else if (tui.inputEl.valuelength > 0) {
781 server.send(['ALL', tui.inputEl.value]);
785 } else if (tui.mode == mode_play) {
786 if (event.key === tui.keys.switch_to_chat) {
787 event.preventDefault();
788 tui.switch_mode(mode_chat);
789 } else if (event.key === tui.keys.switch_to_edit
790 && game.tasks.includes('WRITE')) {
791 event.preventDefault();
792 tui.switch_mode(mode_edit);
793 } else if (event.key === tui.keys.switch_to_study) {
794 tui.switch_mode(mode_study);
795 } else if (event.key === tui.keys.switch_to_password) {
796 tui.switch_mode(mode_password);
797 } else if (event.key === tui.keys.flatten
798 && game.tasks.includes('FLATTEN_SURROUNDINGS')) {
799 server.send(["TASK:FLATTEN_SURROUNDINGS"]);
800 } else if (event.key in tui.movement_keys
801 && game.tasks.includes('MOVE')) {
802 server.send(['TASK:MOVE', tui.movement_keys[event.key]]);
804 } else if (tui.mode == mode_study) {
805 if (event.key === tui.keys.switch_to_chat) {
806 event.preventDefault();
807 tui.switch_mode(mode_chat);
808 } else if (event.key == tui.keys.switch_to_play) {
809 tui.switch_mode(mode_play);
810 } else if (event.key === tui.keys.switch_to_portal) {
811 event.preventDefault();
812 tui.switch_mode(mode_portal);
813 } else if (event.key in tui.movement_keys) {
814 explorer.move(tui.movement_keys[event.key]);
815 } else if (event.key == tui.keys.toggle_map_mode) {
816 if (tui.map_mode == 'terrain') {
817 tui.map_mode = 'control';
819 tui.map_mode = 'terrain';
822 } else if (event.key === tui.keys.switch_to_annotate) {
823 event.preventDefault();
824 tui.switch_mode(mode_annotate);
829 rows_selector.addEventListener('input', function() {
830 if (rows_selector.value % 4 != 0) {
833 window.localStorage.setItem(rows_selector.id, rows_selector.value);
834 terminal.initialize();
837 cols_selector.addEventListener('input', function() {
838 if (cols_selector.value % 4 != 0) {
841 window.localStorage.setItem(cols_selector.id, cols_selector.value);
842 terminal.initialize();
843 tui.window_width = terminal.cols / 2,
846 for (let key_selector of key_selectors) {
847 key_selector.addEventListener('input', function() {
848 window.localStorage.setItem(key_selector.id, key_selector.value);
852 window.setInterval(function() {
853 if (!(['input', 'n_cols', 'n_rows'].includes(document.activeElement.id)
854 || document.activeElement.id.startsWith('key_'))) {