let parser = {
tokenize: function(str) {
- let token_ends = [];
let tokens = [];
let token = ''
let quoted = false;
quoted = true
} else if (c === ' ') {
if (token.length > 0) {
- token_ends.push(i);
tokens.push(token);
token = '';
}
if (token.length > 0) {
tokens.push(token);
}
- let token_starts = [];
- for (let i = 0; i < token_ends.length; i++) {
- token_starts.push(token_ends[i] - tokens[i].length);
- };
- return [tokens, token_starts];
+ return tokens;
},
parse_yx: function(position_string) {
let coordinate_strings = position_string.split(',')
this.websocket.send(unparser.untokenize(tokens));
},
handle_event: function(event) {
- let tokens = parser.tokenize(event.data)[0];
+ let tokens = parser.tokenize(event.data);
if (tokens[0] === 'TURN') {
game.turn_complete = false;
game.things = {};
} else if (tokens[0] === 'UNHANDLED_INPUT') {
tui.log_msg('? unknown command');
} else if (tokens[0] === 'PLAY_ERROR') {
+ tui.log_msg('? ' + tokens[1]);
terminal.blink_screen();
} else if (tokens[0] === 'ARGUMENT_ERROR') {
tui.log_msg('? syntax error: ' + tokens[1]);
};
},
switch_mode: function(mode) {
+ this.inputEl.focus();
this.show_help = false;
this.map_mode = 'terrain';
if (mode.shows_info && game.player_id in game.things) {
};
map_lines_split.push(line);
if (this.map_mode == 'terrain') {
+ for (const p in game.portals) {
+ let coordinate = p.split(',')
+ map_lines_split[coordinate[0]][coordinate[1]] = 'P ';
+ }
let used_positions = [];
for (const thing_id in game.things) {
let t = game.things[thing_id];
content += '[' + this.keys.switch_to_play + '] – play mode\n';
} else if (this.mode == mode_chat) {
content += '/nick NAME – re-name yourself to NAME\n';
- //content += '/msg USER TEXT – send TEXT to USER\n';
content += '/' + this.keys.switch_to_play + ' or /play – switch to play mode\n';
content += '/' + this.keys.switch_to_study + ' or /study – switch to study mode\n';
}
}
tui.full_refresh();
}, false);
-
tui.inputEl.addEventListener('keydown', (event) => {
tui.show_help = false;
if (event.key == 'Enter') {
} else {
tui.log_msg('? need new name');
}
- //} else if (tokens[0].slice(1) == 'msg') {
- // if (tokens.length > 2) {
- // let msg = tui.inputEl.value.slice(token_starts[2]);
- // server.send(['QUERY', tokens[1], msg]);
- // } else {
- // tui.log_msg('? need message target and message');
- // }
} else {
tui.log_msg('? unknown command');
}
tui.init_keys();
}, false);
}
-window.setInterval(function() {
- if (!(['input', 'n_cols', 'n_rows'].includes(document.activeElement.id)
- || document.activeElement.id.startsWith('key_'))) {
- tui.inputEl.focus();
- }
-}, 100);
window.setInterval(function() {
if (server.connected) {
server.send(['PING']);
tui.log_msg('@ attempting reconnect …')
}
}, 5000);
-
+document.getElementById("terminal").onclick = function() {
+ tui.inputEl.focus();
+};
document.getElementById("help").onclick = function() {
tui.show_help = true;
tui.full_refresh();