home · contact · privacy
Add terrain editing access control via passwords.
[plomrogue2] / rogue_chat_nocanvas_monochrome.html
index c01f7ab6a4d2c9676c674790f84c71543153529c..942cdbf12dd6bf750f5fa382d75a19e212bf18b9 100644 (file)
@@ -26,8 +26,10 @@ switch to chat mode: <input id="key_switch_to_chat" type="text" value="t" /><br
 switch to play mode: <input id="key_switch_to_play" type="text" value="p" /><br />
 switch to study mode: <input id="key_switch_to_study" type="text" value="?" /><br />
 edit terrain (from play mode): <input id="key_switch_to_edit" type="text" value="m" /><br />
+enter terrain password (from play mode): <input id="key_switch_to_password" type="text" value="P" /><br />
 annotate terrain (from study mode): <input id="key_switch_to_annotate" type="text" value="m" /><br />
 annotate portal (from study mode): <input id="key_switch_to_portal" type="text" value="P" /><br />
+toggle terrain/control view (from study mode): <input id="key_toggle_map_mode" type="text" value="M" /><br />
 </div>
 <script>
 "use strict";
@@ -173,6 +175,7 @@ let server = {
         this.websocket = new WebSocket(this.url);
         this.websocket.onopen = function(event) {
             window.setInterval(function() { server.send(['PING']) }, 30000);
+            this.send('TASKS');
             tui.log_msg("@ server connected! :)");
             tui.switch_mode(mode_login);
         };
@@ -203,11 +206,15 @@ let server = {
             game.get_thing(tokens[1], true).position = parser.parse_yx(tokens[2]);
         } else if (tokens[0] === 'THING_NAME') {
             game.get_thing(tokens[1], true).name_ = tokens[2];
+        } else if (tokens[0] === 'TASKS') {
+            game.tasks = tokens[1].split(',')
         } else if (tokens[0] === 'MAP') {
             game.map_geometry = tokens[1];
             tui.init_keys();
             game.map_size = parser.parse_yx(tokens[2]);
             game.map = tokens[3]
+        } else if (tokens[0] === 'MAP_CONTROL') {
+            game.map_control = tokens[1]
         } else if (tokens[0] === 'GAME_STATE_COMPLETE') {
             game.turn_complete = true;
             explorer.empty_info_db();
@@ -296,6 +303,7 @@ let mode_study = new Mode('check map tiles for messages', false, true);
 let mode_edit = new Mode('write ASCII char to map tile', false, false);
 let mode_teleport = new Mode('teleport away?', true);
 let mode_portal = new Mode('add portal to map tile', true, true);
+let mode_password = new Mode('enter terrain password', true, false, false);
 
 let tui = {
   mode: mode_waiting_for_server,
@@ -306,6 +314,7 @@ let tui = {
   height_turn_line: 1,
   height_mode_line: 1,
   height_input: 1,
+  password: 'foo',
   init: function() {
       this.inputEl = document.getElementById("input");
       this.inputEl.focus();
@@ -338,6 +347,7 @@ let tui = {
     };
   },
   switch_mode: function(mode, keep_pos=false) {
+    this.map_mode = 'terrain';
     if (mode == mode_study && !keep_pos && game.player_id in game.things) {
       explorer.position = game.things[game.player_id].position;
     }
@@ -360,6 +370,9 @@ let tui = {
         let portal = game.portals[explorer.position]
         this.inputEl.value = portal;
         this.recalc_input_lines();
+    } else if (mode == mode_password) {
+        this.inputEl.value = this.password;
+        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.");
@@ -411,32 +424,49 @@ let tui = {
     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");
+    if (game.tasks.includes('MOVE')) {
+        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_password + " - enter terrain password");
+    if (game.tasks.includes('WRITE')) {
+        this.log_msg("  " + this.keys.switch_to_edit + " - write following ASCII character");
+    }
+    if (game.tasks.includes('FLATTEN_SURROUNDINGS')) {
+        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");
+    if (!game.tasks.includes('MOVE')) {
+        this.log_msg("  " + movement_keys_desc + " - move");
+    }
+    this.log_msg("  " + this.keys.switch_to_annotate + " - annotate terrain");
+    this.log_msg("  " + this.keys.toggle_map_mode + " - toggle terrain/control view");
   },
   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(game.map[i]);
+        line.push(map_content[i]);
     };
     map_lines_split.push(line);
-    for (const thing_id in game.things) {
-        let t = game.things[thing_id];
-        map_lines_split[t.position[0]][t.position[1]] = '@';
-    };
+    if (this.map_mode == 'terrain') {
+        for (const thing_id in game.things) {
+            let t = game.things[thing_id];
+            map_lines_split[t.position[0]][t.position[1]] = '@';
+        };
+    }
     if (tui.mode.shows_info) {
         map_lines_split[explorer.position[0]][explorer.position[1]] = '?';
     }
@@ -535,9 +565,11 @@ let game = {
         this.things = {};
         this.turn = -1;
         this.map = "";
+        this.map_control = "";
         this.map_size = [0,0];
         this.player_id = -1;
         this.portals = {};
+        this.tasks = {};
     },
     get_thing: function(id_, create_if_not_found=false) {
         if (id_ in game.things) {
@@ -672,7 +704,7 @@ tui.inputEl.addEventListener('input', (event) => {
         tui.recalc_input_lines();
         tui.full_refresh();
     } else if (tui.mode == mode_edit && tui.inputEl.value.length > 0) {
-        server.send(["TASK:WRITE", tui.inputEl.value[0]]);
+        server.send(["TASK:WRITE", tui.inputEl.value[0], tui.password]);
         tui.switch_mode(mode_play);
     } else if (tui.mode == mode_teleport) {
         if (['Y', 'y'].includes(tui.inputEl.value[0])) {
@@ -697,6 +729,12 @@ tui.inputEl.addEventListener('keydown', (event) => {
     } else if (tui.mode == mode_annotate && event.key == 'Enter') {
         explorer.annotate(tui.inputEl.value);
         tui.switch_mode(mode_study, true);
+    } else if (tui.mode == mode_password && event.key == 'Enter') {
+        if (tui.inputEl.value.length == 0) {
+            tui.inputEl.value = " ";
+        }
+        tui.password = tui.inputEl.value
+        tui.switch_mode(mode_play);
     } else if (tui.mode == mode_teleport && event.key == 'Enter') {
         if (tui.inputEl.value == 'YES!') {
             server.reconnect_to(tui.teleport_target);
@@ -748,14 +786,19 @@ tui.inputEl.addEventListener('keydown', (event) => {
           if (event.key === tui.keys.switch_to_chat) {
               event.preventDefault();
               tui.switch_mode(mode_chat);
-          } else if (event.key === tui.keys.switch_to_edit) {
+          } else if (event.key === tui.keys.switch_to_edit
+                     && game.tasks.includes('WRITE')) {
               event.preventDefault();
               tui.switch_mode(mode_edit);
           } else if (event.key === tui.keys.switch_to_study) {
               tui.switch_mode(mode_study);
-          } else if (event.key === tui.keys.flatten) {
+          } else if (event.key === tui.keys.switch_to_password) {
+              tui.switch_mode(mode_password);
+          } else if (event.key === tui.keys.flatten
+                     && game.tasks.includes('FLATTEN_SURROUNDINGS')) {
               server.send(["TASK:FLATTEN_SURROUNDINGS"]);
-          } else if (event.key in tui.movement_keys) {
+          } else if (event.key in tui.movement_keys
+                     && game.tasks.includes('MOVE')) {
               server.send(['TASK:MOVE', tui.movement_keys[event.key]]);
           };
     } else if (tui.mode == mode_study) {
@@ -769,9 +812,16 @@ tui.inputEl.addEventListener('keydown', (event) => {
             tui.switch_mode(mode_portal);
         } 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 = 'control';
+            } else {
+                tui.map_mode = 'terrain';
+            }
+            tui.full_refresh();
         } else if (event.key === tui.keys.switch_to_annotate) {
-          event.preventDefault();
-          tui.switch_mode(mode_annotate);
+            event.preventDefault();
+            tui.switch_mode(mode_annotate);
         };
     }
 }, false);