+ this.websocket.send(unparser.untokenize(tokens));
+ },
+ handle_event: function(event) {
+ let tokens = parser.tokenize(event.data)[0];
+ if (tokens[0] === 'TURN') {
+ game.things = {};
+ game.portals = {};
+ game.turn = parseInt(tokens[1]);
+ } else if (tokens[0] === 'THING_POS') {
+ game.things[tokens[1]] = parser.parse_yx(tokens[2]);
+ } else if (tokens[0] === 'MAP') {
+ game.map_size = parser.parse_yx(tokens[1]);
+ game.map = tokens[2]
+ } else if (tokens[0] === 'GAME_STATE_COMPLETE') {
+ explorer.empty_info_db();
+ if (tui.mode == mode_study) {
+ explorer.query_info();
+ }
+ let player_position = [0,0];
+ for (const thing_id in game.things) {
+ if (game.player_id == thing_id) {
+ let t = game.things[thing_id];
+ player_position = t;
+ }
+ }
+ if (player_position in game.portals) {
+ tui.teleport_target = game.portals[player_position];
+ tui.switch_mode(mode_teleport);
+ return;
+ }
+ tui.full_refresh();
+ } else if (tokens[0] === 'CHAT') {
+ tui.log_msg('# ' + tokens[1], 1);
+ } else if (tokens[0] === 'PLAYER_ID') {
+ game.player_id = parseInt(tokens[1]);
+ } else if (tokens[0] === 'LOGIN_OK') {
+ this.send(['GET_GAMESTATE']);
+ tui.log_help();
+ tui.switch_mode(mode_play);
+ } else if (tokens[0] === 'PORTAL') {
+ let position = parser.parse_yx(tokens[1]);
+ game.portals[position] = tokens[2];
+ } else if (tokens[0] === 'ANNOTATION') {
+ let position = parser.parse_yx(tokens[1]);
+ explorer.update_info_db(position, tokens[2]);
+ } else if (tokens[0] === 'UNHANDLED_INPUT') {
+ tui.log_msg('? unknown command');
+ } else if (tokens[0] === 'PLAY_ERROR') {
+ terminal.blink_screen();
+ } else if (tokens[0] === 'ARGUMENT_ERROR') {
+ tui.log_msg('? syntax error: ' + tokens[1]);
+ } else if (tokens[0] === 'GAME_ERROR') {
+ tui.log_msg('? game error: ' + tokens[1]);
+ } else if (tokens[0] === 'PONG') {
+ console.log('PONG');