- if (chat.input_line === '') {
- tui.draw_input_line();
- tui.refresh();
- }
- if (event.key && event.key.length === 1) {
- chat.input_line += event.key;
- tui.draw_input_line();
- tui.refresh();
- } else if (event.key === 'Backspace') {
- chat.input_line = chat.input_line.slice(0, -1);
- tui.draw_input_line();
- tui.refresh();
- } else if (event.key === 'Enter') {
- if (chat.input_line.length === 1) {
- websocket.send("TASK:WRITE " + chat.input_line);
- } else if (chat.input_line.trimEnd() === 'FLATTEN') {
- websocket.send("TASK:FLATTEN_SURROUNDINGS");
- } else {
- websocket.send(chat.input_line);
+ if (mode == 'chat') {
+ if (event.key.length === 1) {
+ chat.input_line += event.key;
+ tui.draw_input_line();
+ tui.refresh();
+ } else if (event.key == 'Backspace') {
+ chat.input_line = chat.input_line.slice(0, -1);
+ tui.draw_input_line();
+ tui.refresh();
+ } else if (event.key == 'Enter') {
+ let tokens = parser.tokenize(chat.input_line);
+ console.log(tokens);
+ if (tokens.length > 0 && tokens[0].length > 0) {
+ if (tokens[0][0] == '/') {
+ if (tokens[0] == '/game') {
+ mode = 'game';
+ } else if (tokens[0] == '/?') {
+ 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) {
+ websocket.send('QUERY ' + quote(tokens[1]) + ' ' + quote(tokens[2]));
+ } else {
+ tui.log_msg('need message target and message');
+ }
+ } else {
+ tui.log_msg('unknown command');
+ }
+ } else {
+ websocket.send('ALL ' + quote(chat.input_line));
+ }
+ }
+ chat.input_line = '';
+ tui.draw_input_line();
+ tui.refresh();
+ }
+ } else if (mode == 'game') {
+ if (event.key === 'c') {
+ mode = 'chat';
+ } else if (event.key === 'e') {
+ mode = 'edit';
+ } else if (event.key === '?') {
+ 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 (mode == 'edit') {
+ if (event.key.length === 1) {
+ websocket.send("TASK:WRITE " + event.key);
+ }
+ mode = 'game';