home · contact · privacy
Refactor curses client.
[plomrogue2] / rogue_chat.html
index ffed950bfe65738cfe5d29468eb93de0fa244fec..9be10523e911239400965e16eac91783bba4308c 100644 (file)
@@ -22,19 +22,19 @@ keyboard input/control: <span id="keyboard_control"></span>
 <h3>button controls for mouse players</h3>
 <table style="float: left">
   <tr>
-    <td style="text-align: right"><button id="move_upleft">up-left</button></td>
-    <td style="text-align: center"><button id="move_up">up</button></td>
-    <td><button id="move_upright">up-right</button></td>
+    <td style="text-align: right"><button id="hex_move_upleft">up-left</button></td>
+    <td style="text-align: center"><button id="square_move_up">up</button></td>
+    <td><button id="hex_move_upright">up-right</button></td>
   </tr>
   <tr>
-    <td style="text-align: right;"><button id="move_left">left</button></td>
+    <td style="text-align: right;"><button id="square_move_left">left</button><button id="hex_move_left">left</button></td>
     <td stlye="text-align: center;">move</td>
-    <td><button id="move_right">right</button></td>
+    <td><button id="square_move_right">right</button><button id="hex_move_right">right</button></td>
   </tr>
   <tr>
-    <td><button id="move_downleft">down-left</button></td>
-    <td style="text-align: center"><button id="move_down">down</button></td>
-    <td><button id="move_downright">down-right</button></td>
+    <td><button id="hex_move_downleft">down-left</button></td>
+    <td style="text-align: center"><button id="square_move_down">down</button></td>
+    <td><button id="hex_move_downright">down-right</button></td>
   </tr>
 </table>
 <table>
@@ -57,14 +57,14 @@ keyboard input/control: <span id="keyboard_control"></span>
     </td>
   </tr>
   <tr>
-    <td><button id="switch_to_edit">map edit mode</button></td>
+    <td><button id="switch_to_edit">world edit mode</button></td>
     <td>
       <button id="switch_to_write">change terrain</button>
       <button id="flatten">flatten surroundings</button>
       <button id="switch_to_annotate">annotate tile</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>
+      <button id="switch_to_password">enter world edit password</button>
     </td>
   </tr>
   <tr>
@@ -127,7 +127,7 @@ let mode_helps = {
         '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': '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.'
+        '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 world 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',
@@ -139,31 +139,31 @@ let mode_helps = {
     },
     '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.'
+        'long': 'This mode allows you to change the map tile you currently stand on (if your world editing password authorizes you so).  Just enter any printable ASCII character to imprint it on the ground below you.'
     },
     'control_pw_type': {
         '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.'
+        'long': 'This mode is the first of two steps to change the password for a protection character.  First enter the protection character for which you want to change the password.'
     },
     'control_pw_pw': {
-        '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.'
+        'short': 'change protection character password',
+        'long': 'This mode is the second of two steps to change the password for a protection character.  Enter the new password for the protection character you chose.'
     },
     'control_tile_type': {
         '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.'
+        'long': 'This mode is the first of two steps to change tile protection areas on the map.  First enter the tile protection character you want to write.'
     },
     'control_tile_draw': {
         '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.'
+        '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 protection character.'
     },
     'annotate': {
         'short': 'annotate tile',
-        'long': 'This mode allows you to add/edit a comment on the tile you are currently standing on (provided your map editing password authorizes you so).  Hit Return to leave.'
+        'long': 'This mode allows you to add/edit a comment on the tile you are currently standing on (provided your world editing password authorizes you so).  Hit Return to leave.'
     },
     'portal': {
         'short': 'edit portal',
-        'long': 'This mode allows you to imprint/edit/remove a teleportation target on the ground you are currently standing on (provided your map editing password authorizes you so).  Enter or edit a URL to imprint a teleportation target; enter emptiness to remove a pre-existing teleportation target.  Hit Return to leave.'
+        'long': 'This mode allows you to imprint/edit/remove a teleportation target on the ground you are currently standing on (provided your world editing password authorizes you so).  Enter or edit a URL to imprint a teleportation target; enter emptiness to remove a pre-existing teleportation target.  Hit Return to leave.'
     },
     'chat': {
         'short': 'chat',
@@ -182,8 +182,8 @@ let mode_helps = {
         'long': 'Waiting for a server response.'
     },
     '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.'
+        'short': 'set world edit password',
+        'long': 'This mode allows you to change the password that you send to authorize yourself for editing password-protected elements of the world.  Hit return to confirm and leave.'
     },
     'admin_enter': {
         'short': 'become admin',
@@ -194,6 +194,28 @@ let mode_helps = {
         'long': 'This mode allows you access to actions limited to administrators.'
     }
 }
+let key_descriptions = {
+    'help': 'help',
+    'flatten': 'flatten surroundings',
+    'teleport': 'teleport',
+    'take_thing': 'pick up thing',
+    'drop_thing': 'drop thing',
+    'toggle_map_mode': 'toggle map view',
+    'toggle_tile_draw': 'toggle protection character drawing',
+    'hex_move_upleft': 'up-left',
+    'hex_move_upright': 'up-right',
+    'hex_move_right': 'right',
+    'hex_move_left': 'left',
+    'hex_move_downleft': 'down-left',
+    'hex_move_downright': 'down-right',
+    'square_move_right': 'right',
+    'square_move_left': 'left',
+    'square_move_up': 'up',
+    'square_move_down': 'down',
+};
+for (const mode_name of Object.keys(mode_helps)) {
+    key_descriptions['switch_to_' + mode_name] = mode_helps[mode_name].short;
+};
 
 let rows_selector = document.getElementById("n_rows");
 let cols_selector = document.getElementById("n_cols");
@@ -216,6 +238,15 @@ for (let key_selector of key_selectors) {
     restore_selector_value(key_selector);
 }
 
+function escapeHTML(str) {
+    return str.
+        replace(/&/g, '&amp;').
+        replace(/</g, '&lt;').
+        replace(/>/g, '&gt;').
+        replace(/'/g, '&apos;').
+        replace(/"/g, '&quot;');
+};
+
 let terminal = {
   foreground: 'white',
   background: 'black',
@@ -249,14 +280,6 @@ let terminal = {
       }, 100);
   },
   refresh: function() {
-      function escapeHTML(str) {
-          return str.
-              replace(/&/g, '&amp;').
-              replace(/</g, '&lt;').
-              replace(/>/g, '&gt;').
-              replace(/'/g, '&apos;').
-              replace(/"/g, '&quot;');
-      };
       let pre_content = '';
       for (let y = 0; y < this.rows; y++) {
           let line = this.content[y].join('');
@@ -593,35 +616,29 @@ let tui = {
     for (let key_selector of key_selectors) {
         this.keys[key_selector.id.slice(4)] = key_selector.value;
     }
-    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'
-        };
-        document.getElementById("move_upright").hidden = true;
-        document.getElementById("move_upleft").hidden = true;
-        document.getElementById("move_downright").hidden = true;
-        document.getElementById("move_downleft").hidden = true;
-        document.getElementById("move_up").hidden = false;
-        document.getElementById("move_down").hidden = false;
-    } else if (game.map_geometry == 'Hex') {
-        document.getElementById("move_upright").hidden = false;
-        document.getElementById("move_upleft").hidden = false;
-        document.getElementById("move_downright").hidden = false;
-        document.getElementById("move_downleft").hidden = false;
-        document.getElementById("move_up").hidden = true;
-        document.getElementById("move_down").hidden = true;
-        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'
-        };
+    this.movement_keys = {};
+    if (!game.map_geometry) {
+        return;
+    }
+    let geometry_prefix = game.map_geometry.toLowerCase() + '_';
+    for (const key_name of Object.keys(key_descriptions)) {
+        if (key_name.startsWith(geometry_prefix)) {
+            let direction = key_name.split('_')[2].toUpperCase();
+            let key = this.keys[key_name];
+            this.movement_keys[key] = direction;
+        }
+    };
+    for (const move_button of document.querySelectorAll('[id*="_move_"]')) {
+        move_button.hidden = true;
     };
+    for (const move_button of document.querySelectorAll('[id^="' + geometry_prefix + 'move_"]')) {
+        move_button.hidden = false;
+    };
+    for (let el of document.getElementsByTagName("button")) {
+      let action_desc = key_descriptions[el.id];
+      let action_key = '[' + this.keys[el.id] + ']';
+      el.innerHTML = escapeHTML(action_desc) + '<br /><span class="keyboard_controlled">' + escapeHTML(action_key) + '</span>';
+    }
   },
   switch_mode: function(mode_name) {
     if (this.mode.name == 'control_tile_draw') {
@@ -673,7 +690,7 @@ let tui = {
     }
     document.getElementById("help").disabled = false;
     if (this.mode.name == 'play' || this.mode.name == 'study' || this.mode.name == 'control_tile_draw' || this.mode.name == 'edit' || this.mode.name == 'admin') {
-        for (const move_key of document.querySelectorAll('[id^="move_"]')) {
+        for (const move_key of document.querySelectorAll('[id*="_move_"]')) {
             move_key.disabled = false;
         }
     }
@@ -729,16 +746,16 @@ let tui = {
     } 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:')
+        this.log_msg('@ enter 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:')
+        this.log_msg('@ enter protection character which you want to draw:')
     } else if (this.mode.name == 'admin_thing_protect') {
         this.log_msg('@ enter thing protection character:')
     } else if (this.mode.name == 'control_pw_pw') {
-        this.log_msg('@ enter tile protection password for "' + this.tile_control_char + '":');
+        this.log_msg('@ enter 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.log_msg('@ can draw 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();
   },
@@ -814,6 +831,10 @@ let tui = {
               if (in_link) {
                   push_inner_link(y, chunk.length);
                   url_start_x = 0;
+                  if (url_ends[0] == i) {
+                      in_link = false;
+                      url_ends.shift();
+                  }
               };
               lines.push(chunk);
               chunk = "";
@@ -830,7 +851,8 @@ let tui = {
               url_start_x = x;
               url = link_data[i];
               in_link = true;
-          } else if (url_ends.includes(i)) {
+          } else if (url_ends[0] == i) {
+              url_ends.shift();
               push_inner_link(y, x);
               in_link = false;
           }
@@ -1031,7 +1053,7 @@ let tui = {
           content += '/nick NAME – re-name yourself to NAME\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';
-          content += '/' + this.keys.switch_to_edit + ' or /edit – switch to map edit mode\n';
+          content += '/' + this.keys.switch_to_edit + ' or /edit – switch to world edit mode\n';
           content += '/' + this.keys.switch_to_admin_enter + ' or /admin – switch to admin mode\n';
       } else if (this.mode.name == 'admin') {
           content += "Available actions:\n";
@@ -1470,12 +1492,17 @@ window.setInterval(function() {
 }, 5000);
 window.setInterval(function() {
     let val = "?";
+    let span_decoration = "none";
     if (document.activeElement == tui.inputEl) {
         val = "on (click outside terminal to change)";
     } else {
         val = "off (click into terminal to change)";
+        span_decoration = "line-through";
     };
     document.getElementById("keyboard_control").textContent = val;
+    for (const span of document.querySelectorAll('.keyboard_controlled')) {
+        span.style.textDecoration = span_decoration;
+    }
 }, 100);
 document.getElementById("terminal").onclick = function() {
     tui.inputEl.focus();
@@ -1510,60 +1537,14 @@ document.getElementById("flatten").onclick = function() {
 document.getElementById("teleport").onclick = function() {
     game.teleport();
 };
-document.getElementById("move_upleft").onclick = function() {
-    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' || tui.mode.name == 'edit') {
-        server.send(['TASK:MOVE', 'LEFT']);
-    } else {
-        explorer.move('LEFT');
-    };
-};
-document.getElementById("move_downleft").onclick = function() {
-    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' || tui.mode.name == 'edit') {
-        server.send(['TASK:MOVE', 'DOWN']);
-    } else {
-        explorer.move('DOWN');
-    };
-};
-document.getElementById("move_up").onclick = function() {
-    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' || tui.mode.name == 'edit') {
-        server.send(['TASK:MOVE', 'UPRIGHT']);
-    } else {
-        explorer.move('UPRIGHT');
-    };
-};
-document.getElementById("move_right").onclick = function() {
-    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' || tui.mode.name == 'edit') {
-        server.send(['TASK:MOVE', 'DOWNRIGHT']);
-    } else {
-        explorer.move('DOWNRIGHT');
+for (const move_button of document.querySelectorAll('[id*="_move_"]')) {
+    let direction = move_button.id.split('_')[2].toUpperCase();
+    move_button.onclick = function() {
+        if (tui.mode.name == 'play' || tui.mode.name == 'edit') {
+            server.send(['TASK:MOVE', direction]);
+        } else {
+            explorer.move(direction);
+        };
     };
 };
 </script>