home · contact · privacy
Fix input line recalculation bugs.
[plomrogue2] / rogue_chat.html
index 2a41e0ad1285cb033c0194b392d3fce2c51152d5..d2136df8a6dd3517eff99e0b7fb210be99bc0c30 100644 (file)
 </head><body>
 <div>
 terminal rows: <input id="n_rows" type="number" step=4 min=24 value=24 />
-terminal columns: <input id="n_cols" type="number" step=4 min=80 value=80 />
+/ terminal columns: <input id="n_cols" type="number" step=4 min=80 value=80 />
+/ <a href="https://plomlompom.com/repos/?p=plomrogue2;a=summary">source code</a> (includes proper terminal/ncurses client)
 </div>
 <pre id="terminal"></pre>
 <textarea id="input" style="opacity: 0; width: 0px;"></textarea>
 <div>
-<a href="https://plomlompom.com/repos/?p=plomrogue2;a=summary">source code</a> (includes proper terminal / curses client)
+keyboard input/control: <span id="keyboard_control"></span>
+</div>
 <h3>button controls for mouse players</h3>
 <table style="float: left">
   <tr>
@@ -44,31 +46,33 @@ terminal columns: <input id="n_cols" type="number" step=4 min=80 value=80 />
   </tr>
   <tr>
     <td><button id="switch_to_study">study mode</button></td>
-    <td><button id="toggle_map_mode">toggle terrain/annotations/control view</button>
+    <td><button id="toggle_map_mode">toggle map view</button>
   </tr>
   <tr>
     <td><button id="switch_to_play">play mode</button></td>
     <td>
-      <button id="take_thing">take thing</button>
-      <button id="teleport">teleport</button>
+      <button id="take_thing">pick up thing</button>
       <button id="drop_thing">drop thing</button>
+      <button id="teleport">teleport</button>
     </td>
   </tr>
   <tr>
     <td><button id="switch_to_edit">map edit mode</button></td>
     <td>
-      <button id="switch_to_write">change tile</button>
+      <button id="switch_to_write">change terrain</button>
       <button id="flatten">flatten surroundings</button>
-      <button id="switch_to_password">change tile editing password</button>
       <button id="switch_to_annotate">annotate tile</button>
-      <button id="switch_to_portal">edit portal link</button>
+      <button id="switch_to_portal">edit portal</button>
+      <button id="switch_to_name_thing">name thing</button>
+      <button id="switch_to_password">enter map edit password</button>
     </td>
   </tr>
   <tr>
     <td><button id="switch_to_admin_enter">admin mode</button></td>
     <td>
-      <button id="switch_to_control_pw_type">change tile control password</button>
-      <button id="switch_to_control_tile_type">change tiles control</button>
+      <button id="switch_to_control_pw_type">change protection character password</button>
+      <button id="switch_to_control_tile_type">change protection areas</button>
+      <button id="toggle_tile_draw">toggle protection character drawing</button>
     </td>
   <tr>
   </tr>
@@ -88,20 +92,22 @@ terminal columns: <input id="n_cols" type="number" step=4 min=80 value=80 />
 <li>help: <input id="key_help" type="text" value="h" />
 <li>flatten surroundings: <input id="key_flatten" type="text" value="F" />
 <li>teleport: <input id="key_teleport" type="text" value="p" />
-<li>take thing under player: <input id="key_take_thing" type="text" value="z" />
-<li>drop carried thing: <input id="key_drop_thing" type="text" value="u" />
+<li>pick up thing: <input id="key_take_thing" type="text" value="z" />
+<li>drop thing: <input id="key_drop_thing" type="text" value="u" />
 <li><input id="key_switch_to_chat" type="text" value="t" />
 <li><input id="key_switch_to_play" type="text" value="p" />
 <li><input id="key_switch_to_study" type="text" value="?" />
 <li><input id="key_switch_to_edit" type="text" value="E" />
 <li><input id="key_switch_to_write" type="text" value="m" />
+<li><input id="key_switch_to_name_thing" type="text" value="N" />
 <li><input id="key_switch_to_password" type="text" value="P" />
 <li><input id="key_switch_to_admin_enter" type="text" value="A" />
 <li><input id="key_switch_to_control_pw_type" type="text" value="C" />
 <li><input id="key_switch_to_control_tile_type" type="text" value="Q" />
 <li><input id="key_switch_to_annotate" type="text" value="M" />
 <li><input id="key_switch_to_portal" type="text" value="T" />
-<li>toggle terrain/annotations/control view: <input id="key_toggle_map_mode" type="text" value="M" />
+<li>toggle map view: <input id="key_toggle_map_mode" type="text" value="L" />
+<li>toggle protection character drawing: <input id="key_toggle_tile_draw" type="text" value="m" />
 </ul>
 </div>
 <script>
@@ -112,34 +118,38 @@ let websocket_location = "wss://plomlompom.com/rogue_chat/";
 let mode_helps = {
     'play': {
         'short': 'play',
-        'long': 'This mode allows you to interact with the map.'
+        'long': 'This mode allows you to interact with the map in various ways.'
     },
     'study': {
         'short': 'study',
-        'long': 'This mode allows you to study the map and its tiles in detail.  Move the question mark over a tile, and the right half of the screen will show detailed information on it.'},
+        'long': 'This mode allows you to study the map and its tiles in detail.  Move the question mark over a tile, and the right half of the screen will show detailed information on it.  Toggle the map view to show or hide different information layers.'},
     'edit': {
-        'short': 'map edit',
-        'long': 'This mode allows you to change the map in various ways.'
+        'short': 'world edit',
+        'long': 'This mode allows you to change the game world in various ways.  Individual map tiles can be protected by "protection characters", which you can see by toggling into the protections map view.  You can edit a tile if you set the map edit password that matches its protection character.  The character "." marks the absence of protection:  Such tiles can always be edited.'
+    },
+    'name_thing': {
+        'short': 'name thing',
+        'long': 'Give name to/change name of thing here.'
     },
     'write': {
-        'short': 'terrain write',
+        'short': 'change terrain',
         'long': 'This mode allows you to change the map tile you currently stand on (if your map editing password authorizes you so).  Just enter any printable ASCII character to imprint it on the ground below you.'
     },
     'control_pw_type': {
-        'short': 'change tiles control password',
-        'long': 'This mode is the first of two steps to change the password for a tile control character.  First enter the tile control character for which you want to change the password!'
+        'short': 'change protection character password',
+        'long': 'This mode is the first of two steps to change the password for a tile protection character.  First enter the tile protection character for which you want to change the password.'
     },
     'control_pw_pw': {
-        'short': 'change tiles control password',
-        'long': 'This mode is the second of two steps to change the password for a tile control character.  Enter the new password for the tile control character you chose.'
+        'short': 'change tiles protection password',
+        'long': 'This mode is the second of two steps to change the password for a tile protection character.  Enter the new password for the tile protection character you chose.'
     },
     'control_tile_type': {
-        'short': 'change tiles control',
-        'long': 'This mode is the first of two steps to change tile control areas on the map.  First enter the tile control character you want to write.'
+        'short': 'change tiles protection',
+        'long': 'This mode is the first of two steps to change tile protection areas on the map.  First enter the tile tile protection character you want to write.'
     },
     'control_tile_draw': {
-        'short': 'change tiles control',
-        'long': 'This mode is the second of two steps to change tile control areas on the map.  Move cursor around the map to draw selected tile control character'
+        'short': 'change tiles protection',
+        'long': 'This mode is the second of two steps to change tile protection areas on the map.  Toggle tile protection drawing on/off and move the ?? cursor around the map to draw the selected tile protection character.'
     },
     'annotate': {
         'short': 'annotate tile',
@@ -155,7 +165,7 @@ let mode_helps = {
     },
     'login': {
         'short': 'login',
-        'long': 'Pick your player name.'
+        'long': 'Enter your player name.'
     },
     'waiting_for_server': {
         'short': 'waiting for server response',
@@ -166,7 +176,7 @@ let mode_helps = {
         'long': 'Waiting for a server response.'
     },
     'password': {
-        'short': 'map edit password',
+        'short': 'set map edit password',
         'long': 'This mode allows you to change the password that you send to authorize yourself for editing password-protected map tiles.  Hit return to confirm and leave.'
     },
     'admin_enter': {
@@ -249,7 +259,7 @@ let terminal = {
               let start_x = 0;
               for (let span of tui.links[y]) {
                   chunks.push(escapeHTML(line.slice(start_x, span[0])));
-                  chunks.push('<a href="');
+                  chunks.push('<a target="_blank" href="');
                   chunks.push(escapeHTML(span[2]));
                   chunks.push('">');
                   chunks.push(escapeHTML(line.slice(span[0], span[1])));
@@ -433,7 +443,6 @@ let server = {
         } else if (tokens[0] === 'ANNOTATION') {
             let position = parser.parse_yx(tokens[1]);
             explorer.update_info_db(position, tokens[2]);
-            tui.restore_input_values();
             tui.full_refresh();
         } else if (tokens[0] === 'UNHANDLED_INPUT') {
             tui.log_msg('? unknown command');
@@ -533,6 +542,7 @@ let tui = {
   password: 'foo',
   show_help: false,
   is_admin: false,
+  tile_draw: false,
   mode_waiting_for_server: new Mode('waiting_for_server',
                                      false, false, true),
   mode_login: new Mode('login', true, false, true),
@@ -543,15 +553,14 @@ let tui = {
   mode_study: new Mode('study', false, true),
   mode_write: new Mode('write', false, false, false, true),
   mode_edit: new Mode('edit'),
-  mode_control_pw_type: new Mode('control_pw_type',
-                                  false, false, false, true),
+  mode_control_pw_type: new Mode('control_pw_type', true),
   mode_portal: new Mode('portal', true, true),
   mode_password: new Mode('password', true),
+  mode_name_thing: new Mode('name_thing', true, true),
   mode_admin_enter: new Mode('admin_enter', true),
   mode_admin: new Mode('admin'),
   mode_control_pw_pw: new Mode('control_pw_pw', true),
-  mode_control_tile_type: new Mode('control_tile_type',
-                                   false, false, false, true),
+  mode_control_tile_type: new Mode('control_tile_type', true),
   mode_control_tile_draw: new Mode('control_tile_draw'),
   init: function() {
       this.mode_play.available_modes = ["chat", "study", "edit", "admin_enter"]
@@ -559,8 +568,8 @@ let tui = {
       this.mode_admin.available_modes = ["control_pw_type",
                                          "control_tile_type", "chat",
                                          "study", "play", "edit"]
-      this.mode_control_tile_draw.available_modes = ["admin"]
-      this.mode_edit.available_modes = ["write", "annotate", "portal",
+      this.mode_control_tile_draw.available_modes = ["admin_enter"]
+      this.mode_edit.available_modes = ["write", "annotate", "portal", "name_thing",
                                         "password", "chat", "study", "play",
                                         "admin_enter"]
       this.mode = this.mode_waiting_for_server;
@@ -607,22 +616,49 @@ let tui = {
     };
   },
   switch_mode: function(mode_name) {
-    this.inputEl.focus();
-    this.map_mode = 'terrain';
+    if (this.mode.name == 'control_tile_draw') {
+        tui.log_msg('@ finished tile protection drawing.')
+    }
+    this.tile_draw = false;
     if (mode_name == 'admin_enter' && this.is_admin) {
         mode_name = 'admin';
+    } else if (mode_name == 'name_thing') {
+        let player_position = game.things[game.player_id].position;
+        let thing_id = null;
+        for (let t_id in game.things) {
+            if (t_id == game.player_id) {
+                continue;
+            }
+            let t = game.things[t_id];
+            if (player_position[0] == t.position[0] && player_position[1] == t.position[1]) {
+                thing_id = t_id;
+                break;
+            }
+        }
+        if (!thing_id) {
+            terminal.blink_screen();
+            this.log_msg('? not standing over thing');
+            return;
+        } else {
+            this.selected_thing_id = thing_id;
+        }
     };
     this.mode = this['mode_' + mode_name];
+    if (["control_tile_draw", "control_tile_type", "control_pw_type"].includes(this.mode.name)) {
+        this.map_mode = 'protections';
+    } else if (this.mode.name != "edit") {
+        this.map_mode = 'terrain + things';
+    };
+    if (this.mode.has_input_prompt || this.mode.is_single_char_entry) {
+        this.inputEl.focus();
+    }
     if (game.player_id in game.things && (this.mode.shows_info || this.mode.name == 'control_tile_draw')) {
         explorer.position = game.things[game.player_id].position;
         if (this.mode.shows_info) {
-        explorer.query_info();
-        } else if (this.mode.name == 'control_tile_draw') {
-            explorer.send_tile_control_command();
-            this.map_mode = 'control';
+            explorer.query_info();
         }
     }
-    this.empty_input();
+    this.inputEl.value = "";
     this.restore_input_values();
     for (let el of document.getElementsByTagName("button")) {
         el.disabled = true;
@@ -672,6 +708,8 @@ let tui = {
         document.getElementById("switch_to_write").disabled = false;
         document.getElementById("switch_to_portal").disabled = false;
         document.getElementById("switch_to_password").disabled = false;
+        document.getElementById("switch_to_name_thing").disabled = false;
+        document.getElementById("toggle_map_mode").disabled = false;
     } else if (this.mode.name == 'admin') {
         document.getElementById("switch_to_control_pw_type").disabled = false;
         document.getElementById("switch_to_control_tile_type").disabled = false;
@@ -681,10 +719,15 @@ let tui = {
         this.show_help = true;
     } else if (this.mode.name == 'admin_enter') {
         this.log_msg('@ enter admin password:')
+    } else if (this.mode.name == 'control_pw_type') {
+        this.log_msg('@ enter tile protection character for which you want to change the password:')
+    } else if (this.mode.name == 'control_tile_type') {
+        this.log_msg('@ enter tile protection character which you want to draw:')
     } else if (this.mode.name == 'control_pw_pw') {
-        this.log_msg('@ enter tile control password for "' + this.tile_control_char + '":');
-    } else if (this.mode.name == 'control_pw_pw') {
-        this.log_msg('@ enter tile control password for "' + this.tile_control_char + '":');
+        this.log_msg('@ enter tile protection password for "' + this.tile_control_char + '":');
+    } else if (this.mode.name == 'control_tile_draw') {
+        document.getElementById("toggle_tile_draw").disabled = false;
+        this.log_msg('@ can draw tile protection character "' + this.tile_control_char + '", turn drawing on/off with [' + this.keys.toggle_tile_draw + '], finish with [' +  this.keys.switch_to_admin_enter + '].')
     }
     this.full_refresh();
   },
@@ -705,28 +748,26 @@ let tui = {
           let info = explorer.info_db[explorer.position];
           if (info != "(none)") {
               this.inputEl.value = info;
-              this.recalc_input_lines();
           }
       } else if (this.mode.name == 'portal' && explorer.position in game.portals) {
           let portal = game.portals[explorer.position]
           this.inputEl.value = portal;
-          this.recalc_input_lines();
       } else if (this.mode.name == 'password') {
           this.inputEl.value = this.password;
-          this.recalc_input_lines();
+      } else if (this.mode.name == 'name_thing') {
+          let t = game.get_thing(this.selected_thing_id);
+          if (t && t.name_) {
+              this.inputEl.value = t.name_;
+          }
       }
   },
-  empty_input: function(str) {
-      this.inputEl.value = "";
+  recalc_input_lines: function() {
       if (this.mode.has_input_prompt) {
-          this.recalc_input_lines();
+          let _ = null;
+          [this.input_lines, _] = this.msg_into_lines_of_width(this.input_prompt + this.inputEl.value, this.window_width);
       } else {
-          this.height_input = 0;
+          this.input_lines = [];
       }
-  },
-  recalc_input_lines: function() {
-      let _ = null;
-      [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) {
@@ -794,27 +835,28 @@ let tui = {
   draw_map: function() {
     let map_lines_split = [];
     let line = [];
-    let map_content = game.map;
-    if (this.map_mode == 'control') {
-        map_content = game.map_control;
-    }
     for (let i = 0, j = 0; i < game.map.length; i++, j++) {
         if (j == game.map_size[1]) {
             map_lines_split.push(line);
             line = [];
             j = 0;
         };
-        line.push(map_content[i] + ' ');
+        if (this.map_mode == 'protections') {
+            line.push(game.map_control[i] + ' ');
+        } else {
+            line.push(game.map[i] + ' ');
+        }
     };
     map_lines_split.push(line);
-    if (this.map_mode == 'annotations') {
+    if (this.map_mode == 'terrain + annotations') {
         for (const coordinate of explorer.info_hints) {
             map_lines_split[coordinate[0]][coordinate[1]] = 'A ';
         }
-    } else if (this.map_mode == 'terrain') {
+    } else if (this.map_mode == 'terrain + things') {
         for (const p in game.portals) {
             let coordinate = p.split(',')
-            map_lines_split[coordinate[0]][coordinate[1]] = 'P ';
+            let original = map_lines_split[coordinate[0]][coordinate[1]];
+            map_lines_split[coordinate[0]][coordinate[1]] = original[0] + 'P';
         }
         let used_positions = [];
         for (const thing_id in game.things) {
@@ -831,8 +873,11 @@ let tui = {
             used_positions.push(t.position.toString());
         };
     }
+    let player = game.things[game.player_id];
     if (tui.mode.shows_info || tui.mode.name == 'control_tile_draw') {
         map_lines_split[explorer.position[0]][explorer.position[1]] = '??';
+    } else if (tui.map_mode != 'terrain + things') {
+        map_lines_split[player.position[0]][player.position[1]] = '??';
     }
     let map_lines = []
     if (game.map_geometry == 'Square') {
@@ -851,9 +896,8 @@ let tui = {
         };
     }
     let window_center = [terminal.rows / 2, this.window_width / 2];
-    let player = game.things[game.player_id];
     let center_position = [player.position[0], player.position[1]];
-    if (tui.mode.shows_info) {
+    if (tui.mode.shows_info || tui.mode.name == 'control_tile_draw') {
         center_position = [explorer.position[0], explorer.position[1]];
     }
     center_position[1] = center_position[1] * 2;
@@ -930,7 +974,10 @@ let tui = {
     }
   },
   draw_help: function() {
-      let movement_keys_desc = Object.keys(this.movement_keys).join(',');
+      let movement_keys_desc = '';
+      if (!this.mode.is_intro) {
+          movement_keys_desc = Object.keys(this.movement_keys).join(',');
+      }
       let content = this.mode.short_desc + " help\n\n" + this.mode.help_intro + "\n\n";
       if (this.mode.name == 'play') {
           content += "Available actions:\n";
@@ -941,20 +988,28 @@ let tui = {
               content += "[" + this.keys.take_thing + "] – pick up thing\n";
           }
           if (game.tasks.includes('DROP')) {
-              content += "[" + this.keys.drop_thing + "] – drop picked up thing\n";
+              content += "[" + this.keys.drop_thing + "] – drop thing\n";
           }
-          content += "[" + tui.keys.teleport + "] – teleport to other space\n";
+          content += "[" + tui.keys.teleport + "] – teleport\n";
           content += '\n';
       } else if (this.mode.name == 'study') {
           content += "Available actions:\n";
           content += '[' + movement_keys_desc + '] – move question mark\n';
-          content += '[' + this.keys.toggle_map_mode + '] – toggle view between terrain, annotations, and password protection areas\n';
+          content += '[' + this.keys.toggle_map_mode + '] – toggle map view\n';
           content += '\n';
       } else if (this.mode.name == 'edit') {
           content += "Available actions:\n";
+          if (game.tasks.includes('MOVE')) {
+              content += "[" + movement_keys_desc + "] – move player\n";
+          }
           if (game.tasks.includes('FLATTEN_SURROUNDINGS')) {
-              content += "[" + tui.keys.flatten + "] – flatten player's surroundings\n";
+              content += "[" + tui.keys.flatten + "] – flatten surroundings\n";
           }
+          content += '[' + this.keys.toggle_map_mode + '] – toggle map view\n';
+          content += '\n';
+      } else if (this.mode.name == 'control_tile_draw') {
+          content += "Available actions:\n";
+          content += "[" + tui.keys.toggle_tile_draw + "] – toggle protection character drawing\n";
           content += '\n';
       } else if (this.mode.name == 'chat') {
           content += '/nick NAME – re-name yourself to NAME\n';
@@ -974,9 +1029,28 @@ let tui = {
           terminal.write(y, start_x, lines[i]);
       }
   },
+  toggle_tile_draw: function() {
+      if (tui.tile_draw) {
+          tui.tile_draw = false;
+      } else {
+          tui.tile_draw = true;
+      }
+  },
+  toggle_map_mode: function() {
+      if (tui.map_mode == 'terrain only') {
+          tui.map_mode = 'terrain + annotations';
+      } else if (tui.map_mode == 'terrain + annotations') {
+          tui.map_mode = 'terrain + things';
+      } else if (tui.map_mode == 'terrain + things') {
+          tui.map_mode = 'protections';
+      } else if (tui.map_mode == 'protections') {
+          tui.map_mode = 'terrain only';
+      }
+  },
   full_refresh: function() {
     this.links = {};
     terminal.drawBox(0, 0, terminal.rows, terminal.cols);
+    this.recalc_input_lines();
     if (this.mode.is_intro) {
         this.draw_history();
         this.draw_input();
@@ -1088,7 +1162,7 @@ let explorer = {
             this.position = target
             if (tui.mode.shows_info) {
                 this.query_info();
-            } else if (tui.mode.name == 'control_tile_draw') {
+            } else if (tui.tile_draw) {
                 this.send_tile_control_command();
             }
         } else {
@@ -1112,11 +1186,11 @@ let explorer = {
         server.send(["GET_ANNOTATION", unparser.to_yx(explorer.position)]);
     },
     get_info: function() {
+        let info = "MAP VIEW: " + tui.map_mode + "\n";
         let position_i = this.position[0] * game.map_size[1] + this.position[1];
         if (game.fov[position_i] != '.') {
-            return 'outside field of view';
+            return info + 'outside field of view';
         };
-        let info = "";
         let terrain_char = game.map[position_i]
         let terrain_desc = '?'
         if (game.terrains[terrain_char]) {
@@ -1175,19 +1249,15 @@ tui.inputEl.addEventListener('input', (event) => {
         if (tui.inputEl.value.length > max_length) {
             tui.inputEl.value = tui.inputEl.value.slice(0, max_length);
         };
-        tui.recalc_input_lines();
     } else if (tui.mode.name == 'write' && tui.inputEl.value.length > 0) {
         server.send(["TASK:WRITE", tui.inputEl.value[0], tui.password]);
         tui.switch_mode('edit');
-    } else if (tui.mode.name == 'control_pw_type' && tui.inputEl.value.length > 0) {
-        tui.tile_control_char = tui.inputEl.value[0];
-        tui.switch_mode('control_pw_pw');
-    } else if (tui.mode.name == 'control_tile_type' && tui.inputEl.value.length > 0) {
-        tui.tile_control_char = tui.inputEl.value[0];
-        tui.switch_mode('control_tile_draw');
     }
     tui.full_refresh();
 }, false);
+document.onclick = function() {
+    tui.show_help = false;
+};
 tui.inputEl.addEventListener('keydown', (event) => {
     tui.show_help = false;
     if (event.key == 'Enter') {
@@ -1195,7 +1265,7 @@ tui.inputEl.addEventListener('keydown', (event) => {
     }
     if (tui.mode.has_input_prompt && event.key == 'Enter' && tui.inputEl.value == '/help') {
         tui.show_help = true;
-        tui.empty_input();
+        tui.inputEl.value = "";
         tui.restore_input_values();
     } else if (!tui.mode.has_input_prompt && event.key == tui.keys.help
                && !tui.mode.is_single_char_entry) {
@@ -1203,18 +1273,25 @@ tui.inputEl.addEventListener('keydown', (event) => {
     } else if (tui.mode.name == 'login' && event.key == 'Enter') {
         tui.login_name = tui.inputEl.value;
         server.send(['LOGIN', tui.inputEl.value]);
-        tui.empty_input();
+        tui.inputEl.value = "";
     } else if (tui.mode.name == 'control_pw_pw' && event.key == 'Enter') {
         if (tui.inputEl.value.length == 0) {
             tui.log_msg('@ aborted');
         } else {
             server.send(['SET_MAP_CONTROL_PASSWORD',
                         tui.tile_control_char, tui.inputEl.value]);
+            tui.log_msg('@ sent new password for protection character "' + tui.tile_control_char + '".');
         }
         tui.switch_mode('admin');
     } else if (tui.mode.name == 'portal' && event.key == 'Enter') {
         explorer.set_portal(tui.inputEl.value);
         tui.switch_mode('edit');
+    } else if (tui.mode.name == 'name_thing' && event.key == 'Enter') {
+        if (tui.inputEl.value.length == 0) {
+            tui.inputEl.value = " ";
+        }
+        server.send(["THING_NAME", tui.selected_thing_id, tui.inputEl.value]);
+        tui.switch_mode('edit');
     } else if (tui.mode.name == 'annotate' && event.key == 'Enter') {
         explorer.annotate(tui.inputEl.value);
         tui.switch_mode('edit');
@@ -1227,6 +1304,22 @@ tui.inputEl.addEventListener('keydown', (event) => {
     } else if (tui.mode.name == 'admin_enter' && event.key == 'Enter') {
         server.send(['BECOME_ADMIN', tui.inputEl.value]);
         tui.switch_mode('play');
+    } else if (tui.mode.name == 'control_pw_type' && event.key == 'Enter') {
+        if (tui.inputEl.value.length != 1) {
+            tui.log_msg('@ entered non-single-char, therefore aborted');
+            tui.switch_mode('admin');
+        } else {
+            tui.tile_control_char = tui.inputEl.value[0];
+            tui.switch_mode('control_pw_pw');
+        }
+    } else if (tui.mode.name == 'control_tile_type' && event.key == 'Enter') {
+        if (tui.inputEl.value.length != 1) {
+            tui.log_msg('@ entered non-single-char, therefore aborted');
+            tui.switch_mode('admin');
+        } else {
+            tui.tile_control_char = tui.inputEl.value[0];
+            tui.switch_mode('control_tile_draw');
+        }
     } else if (tui.mode.name == 'chat' && event.key == 'Enter') {
         let tokens = parser.tokenize(tui.inputEl.value);
         if (tokens.length > 0 && tokens[0].length > 0) {
@@ -1254,7 +1347,7 @@ tui.inputEl.addEventListener('keydown', (event) => {
         } else if (tui.inputEl.valuelength > 0) {
                server.send(['ALL', tui.inputEl.value]);
         }
-        tui.empty_input();
+        tui.inputEl.value = "";
     } else if (tui.mode.name == 'play') {
           if (tui.mode.mode_switch_on_key(event)) {
               null;
@@ -1276,19 +1369,15 @@ tui.inputEl.addEventListener('keydown', (event) => {
         } else if (event.key in tui.movement_keys) {
             explorer.move(tui.movement_keys[event.key]);
         } else if (event.key == tui.keys.toggle_map_mode) {
-            if (tui.map_mode == 'terrain') {
-                tui.map_mode = 'annotations';
-            } else if (tui.map_mode == 'annotations') {
-                tui.map_mode = 'control';
-            } else {
-                tui.map_mode = 'terrain';
-            }
+            tui.toggle_map_mode();
         };
     } else if (tui.mode.name == 'control_tile_draw') {
         if (tui.mode.mode_switch_on_key(event)) {
-              null;
+            null;
         } else if (event.key in tui.movement_keys) {
             explorer.move(tui.movement_keys[event.key]);
+        } else if (event.key === tui.keys.toggle_tile_draw) {
+            tui.toggle_tile_draw();
         };
     } else if (tui.mode.name == 'admin') {
         if (tui.mode.mode_switch_on_key(event)) {
@@ -1303,6 +1392,8 @@ tui.inputEl.addEventListener('keydown', (event) => {
         } else if (event.key === tui.keys.flatten
                    && game.tasks.includes('FLATTEN_SURROUNDINGS')) {
             server.send(["TASK:FLATTEN_SURROUNDINGS", tui.password]);
+        } else if (event.key == tui.keys.toggle_map_mode) {
+            tui.toggle_map_mode();
         }
     }
     tui.full_refresh();
@@ -1339,6 +1430,15 @@ window.setInterval(function() {
         tui.log_msg('@ attempting reconnect …')
     }
 }, 5000);
+window.setInterval(function() {
+    let val = "?";
+    if (document.activeElement == tui.inputEl) {
+        val = "on (click outside terminal to change)";
+    } else {
+        val = "off (click into terminal to change)";
+    };
+    document.getElementById("keyboard_control").textContent = val;
+}, 100);
 document.getElementById("terminal").onclick = function() {
     tui.inputEl.focus();
 };
@@ -1353,14 +1453,11 @@ for (const switchEl  of document.querySelectorAll('[id^="switch_to_"]')) {
         tui.full_refresh();
     }
 };
+document.getElementById("toggle_tile_draw").onclick = function() {
+    tui.toggle_tile_draw();
+}
 document.getElementById("toggle_map_mode").onclick = function() {
-    if (tui.map_mode == 'terrain') {
-        tui.map_mode = 'annotations';
-    } else if (tui.map_mode == 'annotations') {
-        tui.map_mode = 'control';
-    } else {
-        tui.map_mode = 'terrain';
-    }
+    tui.toggle_map_mode();
     tui.full_refresh();
 };
 document.getElementById("take_thing").onclick = function() {
@@ -1376,56 +1473,56 @@ document.getElementById("teleport").onclick = function() {
     game.teleport();
 };
 document.getElementById("move_upleft").onclick = function() {
-    if (tui.mode.name == 'play') {
+    if (tui.mode.name == 'play' || tui.mode.name == 'edit') {
         server.send(['TASK:MOVE', 'UPLEFT']);
     } else {
         explorer.move('UPLEFT');
     };
 };
 document.getElementById("move_left").onclick = function() {
-    if (tui.mode.name == 'play') {
+    if (tui.mode.name == 'play' || tui.mode.name == 'edit') {
         server.send(['TASK:MOVE', 'LEFT']);
     } else {
         explorer.move('LEFT');
     };
 };
 document.getElementById("move_downleft").onclick = function() {
-    if (tui.mode.name == 'play') {
+    if (tui.mode.name == 'play' || tui.mode.name == 'edit') {
         server.send(['TASK:MOVE', 'DOWNLEFT']);
     } else {
         explorer.move('DOWNLEFT');
     };
 };
 document.getElementById("move_down").onclick = function() {
-    if (tui.mode.name == 'play') {
+    if (tui.mode.name == 'play' || tui.mode.name == 'edit') {
         server.send(['TASK:MOVE', 'DOWN']);
     } else {
         explorer.move('DOWN');
     };
 };
 document.getElementById("move_up").onclick = function() {
-    if (tui.mode.name == 'play') {
+    if (tui.mode.name == 'play' || tui.mode.name == 'edit') {
         server.send(['TASK:MOVE', 'UP']);
     } else {
         explorer.move('UP');
     };
 };
 document.getElementById("move_upright").onclick = function() {
-    if (tui.mode.name == 'play') {
+    if (tui.mode.name == 'play' || tui.mode.name == 'edit') {
         server.send(['TASK:MOVE', 'UPRIGHT']);
     } else {
         explorer.move('UPRIGHT');
     };
 };
 document.getElementById("move_right").onclick = function() {
-    if (tui.mode.name == 'play') {
+    if (tui.mode.name == 'play' || tui.mode.name == 'edit') {
         server.send(['TASK:MOVE', 'RIGHT']);
     } else {
         explorer.move('RIGHT');
     };
 };
 document.getElementById("move_downright").onclick = function() {
-    if (tui.mode.name == 'play') {
+    if (tui.mode.name == 'play' || tui.mode.name == 'edit') {
         server.send(['TASK:MOVE', 'DOWNRIGHT']);
     } else {
         explorer.move('DOWNRIGHT');