home · contact · privacy
Add thing protection.
[plomrogue2] / rogue_chat.html
index d2136df8a6dd3517eff99e0b7fb210be99bc0c30..15b715a4f0e686108bfdf0923ee8b4b19b558162 100644 (file)
@@ -72,6 +72,7 @@ keyboard input/control: <span id="keyboard_control"></span>
     <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>
     </td>
   <tr>
@@ -104,6 +105,7 @@ keyboard input/control: <span id="keyboard_control"></span>
 <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_admin_thing_protect" type="text" value="T" />
 <li><input id="key_switch_to_annotate" type="text" value="M" />
 <li><input id="key_switch_to_portal" type="text" value="T" />
 <li>toggle map view: <input id="key_toggle_map_mode" type="text" value="L" />
@@ -131,6 +133,10 @@ let mode_helps = {
         'short': 'name thing',
         'long': 'Give name to/change name of thing here.'
     },
+    'admin_thing_protect': {
+        'short': 'change thing protection',
+        'long': 'Change protection character for thing here.'
+    },
     '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.'
@@ -386,9 +392,10 @@ let server = {
             game.portals = {};
             game.turn = parseInt(tokens[1]);
         } else if (tokens[0] === 'THING') {
-            let t = game.get_thing(tokens[3], true);
+            let t = game.get_thing(tokens[4], true);
             t.position = parser.parse_yx(tokens[1]);
             t.type_ = tokens[2];
+            t.protection = tokens[3];
         } else if (tokens[0] === 'THING_NAME') {
             let t = game.get_thing(tokens[1], false);
             if (t) {
@@ -554,6 +561,7 @@ let tui = {
   mode_write: new Mode('write', false, false, false, true),
   mode_edit: new Mode('edit'),
   mode_control_pw_type: new Mode('control_pw_type', true),
+  mode_admin_thing_protect: new Mode('admin_thing_protect', true),
   mode_portal: new Mode('portal', true, true),
   mode_password: new Mode('password', true),
   mode_name_thing: new Mode('name_thing', true, true),
@@ -565,7 +573,7 @@ let tui = {
   init: function() {
       this.mode_play.available_modes = ["chat", "study", "edit", "admin_enter"]
       this.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"]
-      this.mode_admin.available_modes = ["control_pw_type",
+      this.mode_admin.available_modes = ["admin_thing_protect", "control_pw_type",
                                          "control_tile_type", "chat",
                                          "study", "play", "edit"]
       this.mode_control_tile_draw.available_modes = ["admin_enter"]
@@ -622,7 +630,7 @@ let tui = {
     this.tile_draw = false;
     if (mode_name == 'admin_enter' && this.is_admin) {
         mode_name = 'admin';
-    } else if (mode_name == 'name_thing') {
+    } else if (['name_thing', 'admin_thing_protect'].includes(mode_name)) {
         let player_position = game.things[game.player_id].position;
         let thing_id = null;
         for (let t_id in game.things) {
@@ -713,6 +721,7 @@ let tui = {
     } else if (this.mode.name == 'admin') {
         document.getElementById("switch_to_control_pw_type").disabled = false;
         document.getElementById("switch_to_control_tile_type").disabled = false;
+        document.getElementById("switch_to_admin_thing_protect").disabled = false;
     } else if (this.mode.name == 'study') {
         document.getElementById("toggle_map_mode").disabled = false;
     } else if (this.mode.is_single_char_entry) {
@@ -723,6 +732,8 @@ let tui = {
         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 == '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 + '":');
     } else if (this.mode.name == 'control_tile_draw') {
@@ -759,6 +770,11 @@ let tui = {
           if (t && t.name_) {
               this.inputEl.value = t.name_;
           }
+      } else if (this.mode.name == 'admin_thing_protect') {
+          let t = game.get_thing(this.selected_thing_id);
+          if (t && t.protection) {
+              this.inputEl.value = t.protection;
+          }
       }
   },
   recalc_input_lines: function() {
@@ -1206,7 +1222,11 @@ let explorer = {
              let t = game.things[t_id];
              if (t.position[0] == this.position[0] && t.position[1] == this.position[1]) {
                  let symbol = game.thing_types[t.type_];
-                 info += "THING: " + t.type_ + " / " + symbol;
+                 let protection = t.protection;
+                 if (protection == '.') {
+                     protection = 'unprotected';
+                 }
+                 info += "THING: " + t.type_ + " / protection: " + protection + " / " + symbol;
                  if (t.player_char) {
                      info += t.player_char;
                  };
@@ -1290,7 +1310,8 @@ tui.inputEl.addEventListener('keydown', (event) => {
         if (tui.inputEl.value.length == 0) {
             tui.inputEl.value = " ";
         }
-        server.send(["THING_NAME", tui.selected_thing_id, tui.inputEl.value]);
+        server.send(["THING_NAME", tui.selected_thing_id, tui.inputEl.value,
+                     tui.password]);
         tui.switch_mode('edit');
     } else if (tui.mode.name == 'annotate' && event.key == 'Enter') {
         explorer.annotate(tui.inputEl.value);
@@ -1320,6 +1341,14 @@ tui.inputEl.addEventListener('keydown', (event) => {
             tui.tile_control_char = tui.inputEl.value[0];
             tui.switch_mode('control_tile_draw');
         }
+    } else if (tui.mode.name == 'admin_thing_protect' && event.key == 'Enter') {
+        if (tui.inputEl.value.length != 1) {
+            tui.log_msg('@ entered non-single-char, therefore aborted');
+        } else {
+            server.send(['THING_PROTECTION', tui.selected_thing_id, tui.inputEl.value])
+            tui.log_msg('@ sent new protection character for thing');
+        }
+        tui.switch_mode('admin');
     } else if (tui.mode.name == 'chat' && event.key == 'Enter') {
         let tokens = parser.tokenize(tui.inputEl.value);
         if (tokens.length > 0 && tokens[0].length > 0) {