7 rows: <input id="n_rows" type="number" step=4 min=8 value=24 />
8 cols: <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>
14 square_move_up: <input id="key_square_move_up" type="text" value="w" /> (hint: ArrowUp)<br />
15 square_move_left: <input id="key_square_move_left" type="text" value="a" /> (hint: ArrowLeft)<br />
16 square_move_down: <input id="key_square_move_down" type="text" value="s" /> (hint: ArrowDown)<br />
17 square_move_right: <input id="key_square_move_right" type="text" value="d" /> (hint: ArrowRight)<br />
18 hex_move_upleft: <input id="key_hex_move_upleft" type="text" value="w" /><br />
19 hex_move_upright: <input id="key_hex_move_upright" type="text" value="e" /><br />
20 hex_move_right: <input id="key_hex_move_right" type="text" value="d" /><br />
21 hex_move_downright: <input id="key_hex_move_downright" type="text" value="c" /><br />
22 hex_move_downleft: <input id="key_hex_move_downleft" type="text" value="x" /><br />
23 hex_move_left: <input id="key_hex_move_left" type="text" value="s" /><br />
24 flatten_: <input id="key_flatten" type="text" value="f" /><br />
25 switch_to_chat: <input id="key_switch_to_chat" type="text" value="C" /><br />
26 switch_to_play: <input id="key_switch_to_play" type="text" value="P" /><br />
27 switch_to_annotate: <input id="key_switch_to_annotate" type="text" value="E" /><br />
28 switch_to_portal: <input id="key_switch_to_portal" type="text" value="p" /><br />
29 switch_to_study: <input id="key_switch_to_study" type="text" value="?" /><br />
30 switch_to_edit: <input id="key_switch_to_edit" type="text" value="E" /><br />
34 let websocket_location = "ws://localhost:8000";
36 let rows_selector = document.getElementById("n_rows");
37 let cols_selector = document.getElementById("n_cols");
38 let key_switch_to_chat_selector = document.getElementById("key_switch_to_chat");
39 let key_switch_to_play_selector = document.getElementById("key_switch_to_play");
40 let key_switch_to_annotate_selector = document.getElementById("key_switch_to_annotate");
41 let key_switch_to_portal_selector = document.getElementById("key_switch_to_portal");
42 let key_switch_to_study_selector = document.getElementById("key_switch_to_study");
43 let key_switch_to_edit_selector = document.getElementById("key_switch_to_edit");
44 let key_flatten_selector = document.getElementById("key_flatten");
45 let key_hex_move_upleft_selector = document.getElementById("key_hex_move_upleft");
46 let key_hex_move_upright_selector = document.getElementById("key_hex_move_upright");
47 let key_hex_move_right_selector = document.getElementById("key_hex_move_right");
48 let key_hex_move_downright_selector = document.getElementById("key_hex_move_downright");
49 let key_hex_move_downleft_selector = document.getElementById("key_hex_move_downleft");
50 let key_hex_move_left_selector = document.getElementById("key_hex_move_left");
51 let key_square_move_up_selector = document.getElementById("key_square_move_up");
52 let key_square_move_left_selector = document.getElementById("key_square_move_left");
53 let key_square_move_down_selector = document.getElementById("key_square_move_down");
54 let key_square_move_right_selector = document.getElementById("key_square_move_right");
59 initialize: function() {
60 this.rows = rows_selector.value;
61 this.cols = cols_selector.value;
62 this.pre_el = document.getElementById("terminal");
63 this.pre_el.style.color = this.foreground;
64 this.pre_el.style.backgroundColor = this.background;
67 for (let y = 0, x = 0; y <= this.rows; x++) {
71 this.content.push(line);
80 blink_screen: function() {
81 this.pre_el.style.color = this.background;
82 this.pre_el.style.backgroundColor = this.foreground;
84 this.pre_el.style.color = this.foreground;
85 this.pre_el.style.backgroundColor = this.background;
90 for (let y = 0; y < this.rows; y++) {
91 let line = this.content[y].join('');
92 pre_string += line + '\n';
94 this.pre_el.textContent = pre_string;
96 write: function(start_y, start_x, msg) {
97 for (let x = start_x, i = 0; x < this.cols && i < msg.length; x++, i++) {
98 this.content[start_y][x] = msg[i];
101 drawBox: function(start_y, start_x, height, width) {
102 let end_y = start_y + height;
103 let end_x = start_x + width;
104 for (let y = start_y, x = start_x; y < this.rows; x++) {
112 this.content[y][x] = ' ';
116 terminal.initialize();
119 tokenize: function(str) {
125 for (let i = 0; i < str.length; i++) {
131 } else if (c == '\\') {
133 } else if (c == '"') {
138 } else if (c == '"') {
140 } else if (c === ' ') {
141 if (token.length > 0) {
150 if (token.length > 0) {
153 let token_starts = [];
154 for (let i = 0; i < token_ends.length; i++) {
155 token_starts.push(token_ends[i] - tokens[i].length);
157 return [tokens, token_starts];
159 parse_yx: function(position_string) {
160 let coordinate_strings = position_string.split(',')
161 let position = [0, 0];
162 position[0] = parseInt(coordinate_strings[0].slice(2));
163 position[1] = parseInt(coordinate_strings[1].slice(2));
175 init: function(url) {
177 this.websocket = new WebSocket(this.url);
178 this.websocket.onopen = function(event) {
179 window.setInterval(function() { server.send(['PING']) }, 30000);
180 tui.log_msg("@ server connected! :)");
181 tui.switch_mode(mode_login);
183 this.websocket.onclose = function(event) {
184 tui.log_msg("@ server disconnected :(");
185 tui.log_msg("@ hint: try the '/reconnect' command");
187 this.websocket.onmessage = this.handle_event;
189 reconnect: function() {
190 this.reconnect_to(this.url);
192 reconnect_to: function(url) {
193 this.websocket.close();
196 send: function(tokens) {
197 this.websocket.send(unparser.untokenize(tokens));
199 handle_event: function(event) {
200 let tokens = parser.tokenize(event.data)[0];
201 if (tokens[0] === 'TURN') {
202 game.turn_complete = false;
205 game.turn = parseInt(tokens[1]);
206 } else if (tokens[0] === 'THING_POS') {
207 game.get_thing(tokens[1], true).position = parser.parse_yx(tokens[2]);
208 } else if (tokens[0] === 'THING_NAME') {
209 game.get_thing(tokens[1], true).name_ = tokens[2];
210 } else if (tokens[0] === 'MAP') {
211 game.map_geometry = tokens[1];
213 game.map_size = parser.parse_yx(tokens[2]);
215 } else if (tokens[0] === 'GAME_STATE_COMPLETE') {
216 game.turn_complete = true;
217 explorer.empty_info_db();
218 if (tui.mode == mode_post_login_wait) {
219 tui.switch_mode(mode_play);
221 } else if (tui.mode == mode_study) {
222 explorer.query_info();
224 let t = game.get_thing(game.player_id);
225 if (t.position in game.portals) {
226 tui.teleport_target = game.portals[t.position];
227 tui.switch_mode(mode_teleport);
231 } else if (tokens[0] === 'CHAT') {
232 tui.log_msg('# ' + tokens[1], 1);
233 } else if (tokens[0] === 'PLAYER_ID') {
234 game.player_id = parseInt(tokens[1]);
235 } else if (tokens[0] === 'LOGIN_OK') {
236 this.send(['GET_GAMESTATE']);
237 tui.switch_mode(mode_post_login_wait);
238 } else if (tokens[0] === 'PORTAL') {
239 let position = parser.parse_yx(tokens[1]);
240 game.portals[position] = tokens[2];
241 } else if (tokens[0] === 'ANNOTATION') {
242 let position = parser.parse_yx(tokens[1]);
243 explorer.update_info_db(position, tokens[2]);
244 } else if (tokens[0] === 'UNHANDLED_INPUT') {
245 tui.log_msg('? unknown command');
246 } else if (tokens[0] === 'PLAY_ERROR') {
247 terminal.blink_screen();
248 } else if (tokens[0] === 'ARGUMENT_ERROR') {
249 tui.log_msg('? syntax error: ' + tokens[1]);
250 } else if (tokens[0] === 'GAME_ERROR') {
251 tui.log_msg('? game error: ' + tokens[1]);
252 } else if (tokens[0] === 'PONG') {
255 tui.log_msg('? unhandled input: ' + event.data);
261 quote: function(str) {
263 for (let i = 0; i < str.length; i++) {
265 if (['"', '\\'].includes(c)) {
271 return quoted.join('');
273 to_yx: function(yx_coordinate) {
274 return "Y:" + yx_coordinate[0] + ",X:" + yx_coordinate[1];
276 untokenize: function(tokens) {
277 let quoted_tokens = [];
278 for (let token of tokens) {
279 quoted_tokens.push(this.quote(token));
281 return quoted_tokens.join(" ");
286 constructor(name, has_input_prompt=false, shows_info=false, is_intro=false) {
288 this.has_input_prompt = has_input_prompt;
289 this.shows_info= shows_info;
290 this.is_intro = is_intro;
293 let mode_waiting_for_server = new Mode('waiting_for_server', false, false, true);
294 let mode_login = new Mode('login', true, false, true);
295 let mode_post_login_wait = new Mode('waiting for game world', false, false, true);
296 let mode_chat = new Mode('chat / write messages to players', true, false);
297 let mode_annotate = new Mode('add message to map tile', true, true);
298 let mode_play = new Mode('play / move around', false, false);
299 let mode_study = new Mode('check map tiles for messages', false, true);
300 let mode_edit = new Mode('write ASCII char to map tile', false, false);
301 let mode_teleport = new Mode('teleport away?', true);
302 let mode_portal = new Mode('add portal to map tile', true, true);
305 mode: mode_waiting_for_server,
309 window_width: terminal.cols / 2,
314 this.inputEl = document.getElementById("input");
315 this.inputEl.focus();
316 this.recalc_input_lines();
317 this.height_header = this.height_turn_line + this.height_mode_line;
318 this.log_msg("@ waiting for server connection ...");
321 init_keys: function() {
323 switch_to_chat: key_switch_to_chat_selector.value,
324 switch_to_play: key_switch_to_play_selector.value,
325 switch_to_annotate: key_switch_to_annotate_selector.value,
326 switch_to_portal: key_switch_to_portal_selector.value,
327 switch_to_study: key_switch_to_study_selector.value,
328 switch_to_edit: key_switch_to_edit_selector.value,
329 flatten: key_flatten_selector.value,
330 hex_move_upleft: key_hex_move_upleft_selector.value,
331 hex_move_upright: key_hex_move_upright_selector.value,
332 hex_move_right: key_hex_move_right_selector.value,
333 hex_move_downright: key_hex_move_downright_selector.value,
334 hex_move_downleft: key_hex_move_downleft_selector.value,
335 hex_move_left: key_hex_move_left_selector.value,
336 square_move_up: key_square_move_up_selector.value,
337 square_move_left: key_square_move_left_selector.value,
338 square_move_down: key_square_move_down_selector.value,
339 square_move_right: key_square_move_right_selector.value,
341 if (game.map_geometry == 'Square') {
342 this.movement_keys = {
343 [this.keys.square_move_up]: 'UP',
344 [this.keys.square_move_left]: 'LEFT',
345 [this.keys.square_move_down]: 'DOWN',
346 [this.keys.square_move_right]: 'RIGHT'
348 } else if (game.map_geometry == 'Hex') {
349 this.movement_keys = {
350 [this.keys.hex_move_upleft]: 'UPLEFT',
351 [this.keys.hex_move_upright]: 'UPRIGHT',
352 [this.keys.hex_move_right]: 'RIGHT',
353 [this.keys.hex_move_downright]: 'DOWNRIGHT',
354 [this.keys.hex_move_downleft]: 'DOWNLEFT',
355 [this.keys.hex_move_left]: 'LEFT'
359 switch_mode: function(mode, keep_pos=false) {
360 if (mode == mode_study && !keep_pos && game.player_id in game.things) {
361 explorer.position = game.things[game.player_id].position;
365 if (mode == mode_annotate && explorer.position in explorer.info_db) {
366 let info = explorer.info_db[explorer.position];
367 if (info != "(none)") {
368 this.inputEl.value = info;
369 this.recalc_input_lines();
372 if (mode == mode_login) {
373 if (this.login_name) {
374 server.send(['LOGIN', this.login_name]);
376 this.log_msg("? need login name");
378 } else if (mode == mode_portal && explorer.position in game.portals) {
379 let portal = game.portals[explorer.position]
380 this.inputEl.value = portal;
381 this.recalc_input_lines();
382 } else if (mode == mode_teleport) {
383 tui.log_msg("@ May teleport to: " + tui.teleport_target);
384 tui.log_msg("@ Enter 'YES!' to entusiastically affirm.");
388 empty_input: function(str) {
389 this.inputEl.value = "";
390 if (this.mode.has_input_prompt) {
391 this.recalc_input_lines();
393 this.height_input = 0;
396 recalc_input_lines: function() {
397 this.input_lines = this.msg_into_lines_of_width(this.input_prompt + this.inputEl.value, this.window_width);
398 this.height_input = this.input_lines.length;
400 msg_into_lines_of_width: function(msg, width) {
403 for (let i = 0, x = 0; i < msg.length; i++, x++) {
404 if (x >= width || msg[i] == "\n") {
409 if (msg[i] != "\n") {
416 log_msg: function(msg) {
418 while (this.log.length > 100) {
423 log_help: function() {
424 let movement_keys_desc = Object.keys(this.movement_keys).join(',');
425 this.log_msg("HELP:");
426 this.log_msg("chat mode commands:");
427 this.log_msg(" /nick NAME - re-name yourself to NAME");
428 this.log_msg(" /msg USER TEXT - send TEXT to USER");
429 this.log_msg(" /help - show this help");
430 this.log_msg(" /P or /play - switch to play mode");
431 this.log_msg(" /? or /study - switch to study mode");
432 this.log_msg("commands common to study and play mode:");
433 this.log_msg(" " + movement_keys_desc + " - move");
434 this.log_msg(" " + this.keys.switch_to_chat + " - switch to chat mode");
435 this.log_msg("commands specific to play mode:");
436 this.log_msg(" " + this.keys.switch_to_edit + " - write following ASCII character");
437 this.log_msg(" " + this.keys.flatten + " - flatten surroundings");
438 this.log_msg(" " + this.keys.switch_to_study + " - switch to study mode");
439 this.log_msg("commands specific to study mode:");
440 this.log_msg(" " + this.keys.switch_to_annotate + " - annotate terrain");
441 this.log_msg(" " + this.keys.switch_to_play + " - switch to play mode");
443 draw_map: function() {
444 let map_lines_split = [];
446 for (let i = 0, j = 0; i < game.map.length; i++, j++) {
447 if (j == game.map_size[1]) {
448 map_lines_split.push(line);
452 line.push(game.map[i]);
454 map_lines_split.push(line);
455 for (const thing_id in game.things) {
456 let t = game.things[thing_id];
457 map_lines_split[t.position[0]][t.position[1]] = '@';
459 if (tui.mode.shows_info) {
460 map_lines_split[explorer.position[0]][explorer.position[1]] = '?';
463 if (game.map_geometry == 'Square') {
464 for (let line_split of map_lines_split) {
465 map_lines.push(line_split.join(' '));
467 } else if (game.map_geometry == 'Hex') {
469 for (let line_split of map_lines_split) {
470 map_lines.push(' '.repeat(indent) + line_split.join(' '));
478 let window_center = [terminal.rows / 2, this.window_width / 2];
479 let player = game.things[game.player_id];
480 let center_position = [player.position[0], player.position[1]];
481 if (tui.mode.shows_info) {
482 center_position = [explorer.position[0], explorer.position[1]];
484 center_position[1] = center_position[1] * 2;
485 let offset = [center_position[0] - window_center[0],
486 center_position[1] - window_center[1]]
487 if (game.map_geometry == 'Hex' && offset[0] % 2) {
490 let term_y = Math.max(0, -offset[0]);
491 let term_x = Math.max(0, -offset[1]);
492 let map_y = Math.max(0, offset[0]);
493 let map_x = Math.max(0, offset[1]);
494 for (; term_y < terminal.rows && map_y < game.map_size[0]; term_y++, map_y++) {
495 let to_draw = map_lines[map_y].slice(map_x, this.window_width + offset[1]);
496 terminal.write(term_y, term_x, to_draw);
499 draw_mode_line: function() {
500 terminal.write(0, this.window_width, 'MODE: ' + this.mode.name);
502 draw_turn_line: function(n) {
503 terminal.write(1, this.window_width, 'TURN: ' + game.turn);
505 draw_history: function() {
506 let log_display_lines = [];
507 for (let line of this.log) {
508 log_display_lines = log_display_lines.concat(this.msg_into_lines_of_width(line, this.window_width));
510 for (let y = terminal.rows - 1 - this.height_input,
511 i = log_display_lines.length - 1;
512 y >= this.height_header && i >= 0;
514 terminal.write(y, this.window_width, log_display_lines[i]);
517 draw_info: function() {
518 let lines = this.msg_into_lines_of_width(explorer.get_info(), this.window_width);
519 for (let y = this.height_header, i = 0; y < terminal.rows && i < lines.length; y++, i++) {
520 terminal.write(y, this.window_width, lines[i]);
523 draw_input: function() {
524 if (this.mode.has_input_prompt) {
525 for (let y = terminal.rows - this.height_input, i = 0; i < this.input_lines.length; y++, i++) {
526 terminal.write(y, this.window_width, this.input_lines[i]);
530 full_refresh: function() {
531 terminal.drawBox(0, 0, terminal.rows, terminal.cols);
532 if (this.mode.is_intro) {
536 if (game.turn_complete) {
538 this.draw_turn_line();
540 this.draw_mode_line();
541 if (this.mode.shows_info) {
557 this.map_size = [0,0];
561 get_thing: function(id_, create_if_not_found=false) {
562 if (id_ in game.things) {
563 return game.things[id_];
564 } else if (create_if_not_found) {
565 let t = new Thing([0,0]);
566 game.things[id_] = t;
570 move: function(start_position, direction) {
571 let target = [start_position[0], start_position[1]];
572 if (direction == 'LEFT') {
574 } else if (direction == 'RIGHT') {
576 } else if (game.map_geometry == 'Square') {
577 if (direction == 'UP') {
579 } else if (direction == 'DOWN') {
582 } else if (game.map_geometry == 'Hex') {
583 let start_indented = start_position[0] % 2;
584 if (direction == 'UPLEFT') {
586 if (!start_indented) {
589 } else if (direction == 'UPRIGHT') {
591 if (start_indented) {
594 } else if (direction == 'DOWNLEFT') {
596 if (!start_indented) {
599 } else if (direction == 'DOWNRIGHT') {
601 if (start_indented) {
606 if (target[0] < 0 || target[1] < 0 ||
607 target[0] >= this.map_size[0] || target[1] >= this.map_size[1]) {
617 server.init(websocket_location);
622 move: function(direction) {
623 let target = game.move(this.position, direction);
625 this.position = target
629 terminal.blink_screen();
632 update_info_db: function(yx, str) {
633 this.info_db[yx] = str;
634 if (tui.mode == mode_study) {
638 empty_info_db: function() {
640 if (tui.mode == mode_study) {
644 query_info: function() {
645 server.send(["GET_ANNOTATION", unparser.to_yx(explorer.position)]);
647 get_info: function() {
649 let position_i = this.position[0] * game.map_size[1] + this.position[1];
650 info += "TERRAIN: " + game.map[position_i] + "\n";
651 for (let t_id in game.things) {
652 let t = game.things[t_id];
653 if (t.position[0] == this.position[0] && t.position[1] == this.position[1]) {
656 info += ": " + t.name_;
661 if (this.position in game.portals) {
662 info += "PORTAL: " + game.portals[this.position] + "\n";
664 if (this.position in this.info_db) {
665 info += "ANNOTATIONS: " + this.info_db[this.position];
671 annotate: function(msg) {
672 if (msg.length == 0) {
673 msg = " "; // triggers annotation deletion
675 server.send(["ANNOTATE", unparser.to_yx(explorer.position), msg]);
677 set_portal: function(msg) {
678 if (msg.length == 0) {
679 msg = " "; // triggers portal deletion
681 server.send(["PORTAL", unparser.to_yx(explorer.position), msg]);
685 tui.inputEl.addEventListener('input', (event) => {
686 if (tui.mode.has_input_prompt) {
687 let max_length = tui.window_width * terminal.rows - tui.input_prompt.length;
688 if (tui.inputEl.value.length > max_length) {
689 tui.inputEl.value = tui.inputEl.value.slice(0, max_length);
691 tui.recalc_input_lines();
693 } else if (tui.mode == mode_edit && tui.inputEl.value.length > 0) {
694 server.send(["TASK:WRITE", tui.inputEl.value[0]]);
695 tui.switch_mode(mode_play);
696 } else if (tui.mode == mode_teleport) {
697 if (['Y', 'y'].includes(tui.inputEl.value[0])) {
698 server.reconnect_to(tui.teleport_target);
700 tui.log_msg("@ teleportation aborted");
701 tui.switch_mode(mode_play);
705 tui.inputEl.addEventListener('keydown', (event) => {
706 if (event.key == 'Enter') {
707 event.preventDefault();
709 if (tui.mode == mode_login && event.key == 'Enter') {
710 tui.login_name = tui.inputEl.value;
711 server.send(['LOGIN', tui.inputEl.value]);
713 } else if (tui.mode == mode_portal && event.key == 'Enter') {
714 explorer.set_portal(tui.inputEl.value);
715 tui.switch_mode(mode_study, true);
716 } else if (tui.mode == mode_annotate && event.key == 'Enter') {
717 explorer.annotate(tui.inputEl.value);
718 tui.switch_mode(mode_study, true);
719 } else if (tui.mode == mode_teleport && event.key == 'Enter') {
720 if (tui.inputEl.value == 'YES!') {
721 server.reconnect_to(tui.teleport_target);
723 tui.log_msg('@ teleport aborted');
724 tui.switch_mode(mode_play);
726 } else if (tui.mode == mode_chat && event.key == 'Enter') {
727 let [tokens, token_starts] = parser.tokenize(tui.inputEl.value);
728 if (tokens.length > 0 && tokens[0].length > 0) {
729 if (tui.inputEl.value[0][0] == '/') {
730 if (tokens[0].slice(1) == 'play' || tokens[0].slice(1) == 'P') {
731 tui.switch_mode(mode_play);
732 } else if (tokens[0].slice(1) == 'study' || tokens[0].slice(1) == '?') {
733 tui.switch_mode(mode_study);
734 } else if (tokens[0].slice(1) == 'help') {
736 } else if (tokens[0].slice(1) == 'nick') {
737 if (tokens.length > 1) {
738 server.send(['LOGIN', tokens[1]]);
740 tui.log_msg('? need login name');
742 } else if (tokens[0].slice(1) == 'msg') {
743 if (tokens.length > 2) {
744 let msg = tui.inputEl.value.slice(token_starts[2]);
745 server.send(['QUERY', tokens[1], msg]);
747 tui.log_msg('? need message target and message');
749 } else if (tokens[0].slice(1) == 'reconnect') {
750 if (tokens.length > 1) {
751 server.reconnect_to(tokens[1]);
756 tui.log_msg('? unknown command');
759 server.send(['ALL', tui.inputEl.value]);
761 } else if (tui.inputEl.valuelength > 0) {
762 server.send(['ALL', tui.inputEl.value]);
766 } else if (tui.mode == mode_play) {
767 if (event.key === tui.keys.switch_to_chat) {
768 event.preventDefault();
769 tui.switch_mode(mode_chat);
770 } else if (event.key === tui.keys.switch_to_edit) {
771 event.preventDefault();
772 tui.switch_mode(mode_edit);
773 } else if (event.key === tui.keys.switch_to_study) {
774 tui.switch_mode(mode_study);
775 } else if (event.key === tui.keys.flatten) {
776 server.send(["TASK:FLATTEN_SURROUNDINGS"]);
777 } else if (event.key in tui.movement_keys) {
778 server.send(['TASK:MOVE', tui.movement_keys[event.key]]);
780 } else if (tui.mode == mode_study) {
781 if (event.key === tui.keys.switch_to_chat) {
782 event.preventDefault();
783 tui.switch_mode(mode_chat);
784 } else if (event.key == tui.keys.switch_to_play) {
785 tui.switch_mode(mode_play);
786 } else if (event.key === tui.keys.switch_to_portal) {
787 event.preventDefault();
788 tui.switch_mode(mode_portal);
789 } else if (event.key in tui.movement_keys) {
790 explorer.move(tui.movement_keys[event.key]);
791 } else if (event.key === tui.keys.switch_to_annotate) {
792 event.preventDefault();
793 tui.switch_mode(mode_annotate);
798 rows_selector.addEventListener('input', function() {
799 if (rows_selector.value % 4 != 0) {
802 terminal.initialize();
805 cols_selector.addEventListener('input', function() {
806 if (cols_selector.value % 4 != 0) {
809 terminal.initialize();
810 tui.window_width = terminal.cols / 2,
813 key_switch_to_chat_selector.addEventListener('input', function() { tui.init_keys(); }, false);
814 key_switch_to_play_selector.addEventListener('input', function() { tui.init_keys(); }, false);
815 key_switch_to_annotate_selector.addEventListener('input', function() { tui.init_keys(); }, false);
816 key_switch_to_portal_selector.addEventListener('input', function() { tui.init_keys(); }, false);
817 key_switch_to_study_selector.addEventListener('input', function() { tui.init_keys(); }, false);
818 key_switch_to_edit_selector.addEventListener('input', function() { tui.init_keys(); }, false);
819 key_flatten_selector.addEventListener('input', function() { tui.init_keys(); }, false);
820 key_hex_move_upleft_selector.addEventListener('input', function() { tui.init_keys(); }, false);
821 key_hex_move_upright_selector.addEventListener('input', function() { tui.init_keys(); }, false);
822 key_hex_move_right_selector.addEventListener('input', function() { tui.init_keys(); }, false);
823 key_hex_move_downright_selector.addEventListener('input', function() { tui.init_keys(); }, false);
824 key_hex_move_downleft_selector.addEventListener('input', function() { tui.init_keys(); }, false);
825 key_hex_move_left_selector.addEventListener('input', function() { tui.init_keys(); }, false);
826 key_square_move_up_selector.addEventListener('input', function() { tui.init_keys(); }, false);
827 key_square_move_left_selector.addEventListener('input', function() { tui.init_keys(); }, false);
828 key_square_move_down_selector.addEventListener('input', function() { tui.init_keys(); }, false);
829 key_square_move_right_selector.addEventListener('input', function() { tui.init_keys(); }, false);
830 window.setInterval(function() {
831 if (!(['input', 'n_cols', 'n_rows',
832 'key_switch_to_chat',
833 'key_switch_to_play',
834 'key_switch_to_annotate',
835 'key_switch_to_portal',
836 'key_switch_to_study',
837 'key_switch_to_edit',
839 'key_hex_move_upleft',
840 'key_hex_move_upright',
841 'key_hex_move_right',
842 'key_hex_move_downright',
843 'key_hex_move_downleft',
845 'key_square_move_up',
846 'key_square_move_left',
847 'key_square_move_down',
848 'key_square_move_right',].includes(document.activeElement.id))) {