+ if (tui.mode == 'chat') {
+ if (event.key.length === 1) {
+ tui.input_line += event.key;
+ tui.draw_input_line();
+ tui.refresh();
+ } else if (event.key == 'Backspace') {
+ tui.input_line = tui.input_line.slice(0, -1);
+ tui.draw_input_line();
+ tui.refresh();
+ } else if (event.key == 'Enter') {
+ let [tokens, token_starts] = parser.tokenize(tui.input_line);
+ if (tokens.length > 0 && tokens[0].length > 0) {
+ if (tokens[0][0] == '/') {
+ if (tokens[0] == '/play' || tokens[0] == '/p') {
+ tui.switch_mode('play');
+ } else if (tokens[0] == '/study' || tokens[0] == '/s') {
+ tui.switch_mode('study');
+ } else if (tokens[0] == '/help') {
+ tui.log_help();
+ tui.refresh();
+ } else if (tokens[0] == '/login') {
+ if (tokens.length > 1) {
+ websocket.send('LOGIN ' + quote(tokens[1]));
+ } else {
+ tui.log_msg('? need login name');
+ }
+ } else if (tokens[0] == '/msg') {
+ if (tokens.length > 2) {
+ let msg = tui.input_line.slice(token_starts[2]);
+ websocket.send('QUERY ' + quote(tokens[1]) + ' ' + quote(msg));
+ } else {
+ tui.log_msg('? need message target and message');
+ }
+ } else {
+ tui.log_msg('? unknown command');
+ }
+ } else {
+ websocket.send('ALL ' + quote(tui.input_line));
+ }
+ }
+ tui.input_line = '';
+ tui.draw_input_line();
+ tui.refresh();
+ }
+ } else if (tui.mode == 'play') {
+ if (event.key === 'c') {
+ tui.switch_mode('chat');
+ } else if (event.key === 'e') {
+ tui.switch_mode('edit');
+ } else if (event.key === '?') {
+ tui.switch_mode('study');
+ } else if (event.key === 'F1') {
+ tui.log_help();
+ tui.refresh();
+ } else if (event.key === 'f') {
+ websocket.send("TASK:FLATTEN_SURROUNDINGS");
+ } else if (event.key === 'a') {
+ websocket.send('TASK:MOVE LEFT');
+ } else if (event.key === 'd') {
+ websocket.send('TASK:MOVE RIGHT');
+ } else if (event.key === 'w') {
+ websocket.send('TASK:MOVE UP');
+ } else if (event.key === 's') {
+ websocket.send('TASK:MOVE DOWN');
+ };
+ } else if (tui.mode == 'edit') {
+ if (event.key.length === 1) {
+ websocket.send("TASK:WRITE " + quote(event.key));
+ }
+ tui.switch_mode('play');
+ } else if (tui.mode == 'study') {
+ if (event.key === 'c') {
+ tui.switch_mode('chat');
+ } else if (event.key == 'p') {
+ tui.switch_mode('play');
+ } else if (event.key === 'a') {
+ explorer.move('left');
+ } else if (event.key === 'd') {
+ explorer.move('right');
+ } else if (event.key === 'w') {
+ explorer.move('up');
+ } else if (event.key === 's') {
+ explorer.move('down');
+ } else if (event.key === 'A') {
+ tui.switch_mode('annotate');
+ tui.draw_info();
+ tui.refresh();
+ };
+ } else if (tui.mode == 'annotate') {
+ if (event.key.length === 1) {
+ tui.input_line += event.key;
+ tui.draw_input_line();
+ tui.refresh();
+ } else if (event.key == 'Backspace') {
+ tui.input_line = tui.input_line.slice(0, -1);
+ tui.draw_input_line();
+ tui.refresh();
+ } else if (event.key == 'Enter') {
+ explorer.annotate(tui.input_line);
+ tui.input_line = '';
+ tui.switch_mode('study', true);
+ }