home · contact · privacy
Add TASK command to request available commands.
[plomrogue2] / rogue_chat_nocanvas_monochrome.html
index c01f7ab6a4d2c9676c674790f84c71543153529c..4adb4ee24c7875b6775b7b904b3b23b6665712c1 100644 (file)
@@ -173,6 +173,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,6 +204,8 @@ 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();
@@ -411,13 +414,22 @@ 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");
+    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:");
+    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.switch_to_play + " - switch to play mode");
   },
@@ -538,6 +550,7 @@ let game = {
         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) {
@@ -748,14 +761,17 @@ 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.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) {