home · contact · privacy
Fix color setting bug.
[plomrogue2] / rogue_chat.html
index 3825581359fa615777a3a6709479eb8ccbe593bf..0a70962a0d72e30218980101b90ecea16736789d 100644 (file)
@@ -22,58 +22,60 @@ keyboard input/control: <span id="keyboard_control"></span>
 <h3>button controls for mouse players</h3>
 <table id="move_table" style="float: left">
   <tr>
-    <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>
+    <td style="text-align: right"><button id="hex_move_upleft"></button></td>
+    <td style="text-align: center"><button id="square_move_up"></button></td>
+    <td><button id="hex_move_upright"></button></td>
   </tr>
   <tr>
-    <td style="text-align: right;"><button id="square_move_left">left</button><button id="hex_move_left">left</button></td>
+    <td style="text-align: right;"><button id="square_move_left"></button><button id="hex_move_left">left</button></td>
     <td stlye="text-align: center;">move</td>
-    <td><button id="square_move_right">right</button><button id="hex_move_right">right</button></td>
+    <td><button id="square_move_right"></button><button id="hex_move_right"></button></td>
   </tr>
   <tr>
-    <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>
+    <td><button id="hex_move_downleft"></button></td>
+    <td style="text-align: center"><button id="square_move_down"></button></td>
+    <td><button id="hex_move_downright"></button></td>
   </tr>
 </table>
 <table>
   <tr>
-    <td><button id="help">help</button></td>
+    <td><button id="help"></button></td>
   </tr>
   <tr>
-    <td><button id="switch_to_chat">chat mode</button><br /></td>
+    <td><button id="switch_to_chat"></button><br /></td>
   </tr>
   <tr>
-    <td><button id="switch_to_study">study mode</button></td>
-    <td><button id="toggle_map_mode">toggle map view</button>
+    <td><button id="switch_to_study"></button></td>
+    <td><button id="toggle_map_mode"></button>
   </tr>
   <tr>
-    <td><button id="switch_to_play">play mode</button></td>
+    <td><button id="switch_to_play"></button></td>
     <td>
-      <button id="take_thing">pick up thing</button>
-      <button id="drop_thing">drop thing</button>
-      <button id="teleport">teleport</button>
+      <button id="take_thing"></button>
+      <button id="drop_thing"></button>
+      <button id="door"></button>
+      <button id="consume"></button>
+      <button id="teleport"></button>
     </td>
   </tr>
   <tr>
-    <td><button id="switch_to_edit">world edit mode</button></td>
+    <td><button id="switch_to_edit"></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 world edit password</button>
+      <button id="switch_to_write"></button>
+      <button id="flatten"></button>
+      <button id="switch_to_annotate"></button>
+      <button id="switch_to_portal"></button>
+      <button id="switch_to_name_thing"></button>
+      <button id="switch_to_password"></button>
     </td>
   </tr>
   <tr>
-    <td><button id="switch_to_admin_enter">admin mode</button></td>
+    <td><button id="switch_to_admin_enter"></button></td>
     <td>
-      <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="switch_to_admin_thing_protect">change thing protection</button>
-      <button id="toggle_tile_draw">toggle protection character drawing</button>
+      <button id="switch_to_control_pw_type"></button>
+      <button id="switch_to_control_tile_type"></button>
+      <button id="switch_to_admin_thing_protect"></button>
+      <button id="toggle_tile_draw"></button>
     </td>
   <tr>
   </tr>
@@ -95,6 +97,8 @@ keyboard input/control: <span id="keyboard_control"></span>
 <li>teleport: <input id="key_teleport" type="text" value="p" />
 <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>open/close: <input id="key_door" type="text" value="D" />
+<li>consume: <input id="key_consume" type="text" value="C" />
 <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="?" />
@@ -200,6 +204,8 @@ let key_descriptions = {
     'teleport': 'teleport',
     'take_thing': 'pick up thing',
     'drop_thing': 'drop thing',
+    'door': 'open/close',
+    'consume': 'consume',
     'toggle_map_mode': 'toggle map view',
     'toggle_tile_draw': 'toggle protection character drawing',
     'hex_move_upleft': 'up-left',
@@ -248,14 +254,12 @@ function escapeHTML(str) {
 };
 
 let terminal = {
-  foreground: 'white',
-  background: 'black',
   initialize: function() {
     this.rows = rows_selector.value;
     this.cols = cols_selector.value;
     this.pre_el = document.getElementById("terminal");
-    this.pre_el.style.color = this.foreground;
-    this.pre_el.style.backgroundColor = this.background;
+    this.set_default_colors();
+    this.apply_colors();
     this.content = [];
       let line = []
     for (let y = 0, x = 0; y <= this.rows; x++) {
@@ -271,6 +275,23 @@ let terminal = {
         line.push(' ');
     }
   },
+  apply_colors: function() {
+    this.pre_el.style.color = this.foreground;
+    this.pre_el.style.backgroundColor = this.background;
+  },
+  set_default_colors: function() {
+      this.foreground = 'white';
+      this.background = 'black';
+      this.apply_colors();
+  },
+  set_random_colors: function() {
+      function rand(offset) {
+          return Math.floor(offset + Math.random() * 96).toString(16).padStart(2, '0');
+      }
+      this.foreground = '#' + rand(159) + rand(159) + rand(159);
+      this.background = '#' + rand(0) + rand(0) + rand(0);
+      this.apply_colors();
+  },
   blink_screen: function() {
       this.pre_el.style.color = this.background;
       this.pre_el.style.backgroundColor = this.foreground;
@@ -427,7 +448,7 @@ let server = {
         } else if (tokens[0] === 'THING_CHAR') {
             let t = game.get_thing(tokens[1], false);
             if (t) {
-                t.player_char = tokens[2];
+                t.thing_char = tokens[2];
             };
         } else if (tokens[0] === 'TASKS') {
             game.tasks = tokens[1].split(',');
@@ -460,6 +481,10 @@ let server = {
         } else if (tokens[0] === 'LOGIN_OK') {
             this.send(['GET_GAMESTATE']);
             tui.switch_mode('post_login_wait');
+        } else if (tokens[0] === 'DEFAULT_COLORS') {
+            terminal.set_default_colors();
+        } else if (tokens[0] === 'RANDOM_COLORS') {
+            terminal.set_random_colors();
         } else if (tokens[0] === 'ADMIN_OK') {
             tui.is_admin = true;
             tui.log_msg('@ you now have admin rights');
@@ -599,11 +624,14 @@ let tui = {
       'take_thing': 'PICK_UP',
       'drop_thing': 'DROP',
       'move': 'MOVE',
+      'door': 'DOOR',
+      'consume': 'INTOXICATE',
   },
   init: function() {
       this.mode_chat.available_modes = ["play", "study", "edit", "admin_enter"]
       this.mode_play.available_modes = ["chat", "study", "edit", "admin_enter"]
-      this.mode_play.available_actions = ["move", "take_thing", "drop_thing", "teleport"];
+      this.mode_play.available_actions = ["move", "take_thing", "drop_thing",
+                                          "teleport", "door", "consume"];
       this.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"]
       this.mode_study.available_actions = ["toggle_map_mode", "move_explorer"];
       this.mode_admin.available_modes = ["admin_thing_protect", "control_pw_type",
@@ -643,6 +671,9 @@ let tui = {
         }
     };
     for (const move_button of document.querySelectorAll('[id*="_move_"]')) {
+        if (move_button.id.startsWith('key_')) {
+            continue;
+        }
         move_button.hidden = true;
     };
     for (const move_button of document.querySelectorAll('[id^="' + geometry_prefix + 'move_"]')) {
@@ -888,8 +919,8 @@ let tui = {
             let t = game.things[thing_id];
             let symbol = game.thing_types[t.type_];
             let meta_char = ' ';
-            if (t.player_char) {
-                meta_char = t.player_char;
+            if (t.thing_char) {
+                meta_char = t.thing_char;
             }
             if (used_positions.includes(t.position.toString())) {
                 meta_char = '+';
@@ -1219,16 +1250,16 @@ let explorer = {
                  let symbol = game.thing_types[t.type_];
                  let protection = t.protection;
                  if (protection == '.') {
-                     protection = 'unprotected';
+                     protection = 'none';
                  }
-                 info += "THING: " + t.type_ + " / protection: " + protection + " / " + symbol;
-                 if (t.player_char) {
-                     info += t.player_char;
+                 info += "THING: " + t.type_ + " / " + symbol;
+                 if (t.thing_char) {
+                     info += t.thing_char;
                  };
                  if (t.name_) {
                      info += " (" + t.name_ + ")";
                  }
-                 info += "\n";
+                 info += " / protection: " + protection + "\n";
              }
         }
         if (this.position in game.portals) {
@@ -1379,6 +1410,10 @@ tui.inputEl.addEventListener('keydown', (event) => {
               server.send(["TASK:PICK_UP"]);
           } else if (event.key === tui.keys.drop_thing && tui.task_action_on('drop_thing')) {
               server.send(["TASK:DROP"]);
+          } else if (event.key === tui.keys.consume && tui.task_action_on('consume')) {
+              server.send(["TASK:INTOXICATE"]);
+          } else if (event.key === tui.keys.door && tui.task_action_on('door')) {
+              server.send(["TASK:DOOR"]);
           } else if (event.key in tui.movement_keys && tui.task_action_on('move')) {
               server.send(['TASK:MOVE', tui.movement_keys[event.key]]);
           } else if (event.key === tui.keys.teleport) {
@@ -1495,6 +1530,12 @@ document.getElementById("drop_thing").onclick = function() {
 document.getElementById("flatten").onclick = function() {
     server.send(['TASK:FLATTEN_SURROUNDINGS', tui.password]);
 };
+document.getElementById("door").onclick = function() {
+    server.send(['TASK:DOOR']);
+};
+document.getElementById("consume").onclick = function() {
+    server.send(['TASK:INTOXICATE']);
+};
 document.getElementById("teleport").onclick = function() {
     game.teleport();
 };