+ if (game.map_geometry == 'Square') {
+ this.movement_keys = {
+ [this.keys.square_move_up]: 'UP',
+ [this.keys.square_move_left]: 'LEFT',
+ [this.keys.square_move_down]: 'DOWN',
+ [this.keys.square_move_right]: 'RIGHT'
+ };
+ } else if (game.map_geometry == 'Hex') {
+ this.movement_keys = {
+ [this.keys.hex_move_upleft]: 'UPLEFT',
+ [this.keys.hex_move_upright]: 'UPRIGHT',
+ [this.keys.hex_move_right]: 'RIGHT',
+ [this.keys.hex_move_downright]: 'DOWNRIGHT',
+ [this.keys.hex_move_downleft]: 'DOWNLEFT',
+ [this.keys.hex_move_left]: 'LEFT'
+ };
+ };
+ },
+ switch_mode: function(mode, keep_pos=false) {
+ if (mode == mode_study && !keep_pos && game.player_id in game.things) {
+ explorer.position = game.things[game.player_id].position;
+ }
+ this.mode = mode;
+ this.empty_input();
+ if (mode == mode_annotate && explorer.position in explorer.info_db) {
+ let info = explorer.info_db[explorer.position];
+ if (info != "(none)") {
+ this.inputEl.value = info;
+ this.recalc_input_lines();
+ }
+ }
+ if (mode == mode_login) {
+ if (this.login_name) {
+ server.send(['LOGIN', this.login_name]);
+ } else {
+ this.log_msg("? need login name");
+ }
+ } else if (mode == mode_portal && explorer.position in game.portals) {
+ let portal = game.portals[explorer.position]
+ this.inputEl.value = portal;
+ this.recalc_input_lines();
+ } else if (mode == mode_teleport) {
+ tui.log_msg("@ May teleport to: " + tui.teleport_target);
+ tui.log_msg("@ Enter 'YES!' to entusiastically affirm.");
+ }
+ this.full_refresh();
+ },
+ empty_input: function(str) {
+ this.inputEl.value = "";
+ if (this.mode.has_input_prompt) {
+ this.recalc_input_lines();
+ } else {
+ this.height_input = 0;
+ }
+ },
+ recalc_input_lines: function() {
+ this.input_lines = this.msg_into_lines_of_width(this.input_prompt + this.inputEl.value, this.window_width);
+ this.height_input = this.input_lines.length;
+ },
+ msg_into_lines_of_width: function(msg, width) {
+ let chunk = "";
+ let lines = [];
+ for (let i = 0, x = 0; i < msg.length; i++, x++) {
+ if (x >= width || msg[i] == "\n") {
+ lines.push(chunk);
+ chunk = "";
+ x = 0;
+ };
+ if (msg[i] != "\n") {
+ chunk += msg[i];
+ }
+ }
+ lines.push(chunk);
+ return lines;
+ },
+ log_msg: function(msg) {
+ this.log.push(msg);
+ while (this.log.length > 100) {
+ this.log.shift();
+ };
+ this.full_refresh();
+ },
+ log_help: function() {
+ let movement_keys_desc = Object.keys(this.movement_keys).join(',');
+ this.log_msg("HELP:");
+ this.log_msg("chat mode commands:");
+ this.log_msg(" /nick NAME - re-name yourself to NAME");
+ this.log_msg(" /msg USER TEXT - send TEXT to USER");
+ this.log_msg(" /help - show this help");
+ this.log_msg(" /" + this.keys.switch_to_play + " or /play - switch to play mode");
+ this.log_msg(" /" + this.keys.switch_to_study + " or /study - switch to study mode");
+ this.log_msg("commands common to study and play mode:");
+ this.log_msg(" " + movement_keys_desc + " - move");
+ this.log_msg(" " + this.keys.switch_to_chat + " - switch to chat mode");
+ this.log_msg("commands specific to play mode:");
+ this.log_msg(" " + this.keys.switch_to_edit + " - write following ASCII character");
+ this.log_msg(" " + this.keys.flatten + " - flatten surroundings");
+ this.log_msg(" " + this.keys.switch_to_study + " - switch to study mode");
+ this.log_msg("commands specific to study mode:");
+ this.log_msg(" " + this.keys.switch_to_annotate + " - annotate terrain");
+ this.log_msg(" " + this.keys.switch_to_play + " - switch to play mode");