home · contact · privacy
Improve teleportation dialogue handling.
[plomrogue2-experiments] / new2 / rogue_chat_nocanvas_monochrome.html
index 3e25304e6cf08df3ee3755330189c23fb2055af7..583b2dc76becec857bc2fd7252b13415d6742ace 100644 (file)
@@ -258,6 +258,7 @@ let mode_play = new Mode('play / move around', false, false);
 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?');
+let mode_portal = new Mode('add portal to map tile', true, true);
 
 let tui = {
   mode: mode_waiting_for_server,
@@ -303,12 +304,17 @@ let tui = {
     if (mode == mode_annotate && explorer.position in explorer.info_db) {
         let info = explorer.info_db[explorer.position];
         if (info != "(none)") {
-           this.inputEl.value = explorer.info_db[explorer.position];
+           this.inputEl.value = info;
            this.recalc_input_lines();
         }
+    }
+    if (mode == mode_portal && explorer.position in game.portals) {
+        let portal = game.portals[explorer.position]
+       this.inputEl.value = portal;
+       this.recalc_input_lines();
     } else if (mode == mode_teleport) {
-        tui.log_msg("Type Y or y to affirm teleportation, any other key to abort.");
-        tui.log_msg("target: " + tui.teleport_target);
+        tui.log_msg("@ May teleport to: " + tui.teleport_target);
+        tui.log_msg("@ Type Y or y to affirm, other keys to abort.");
     }
     this.full_refresh();
   },
@@ -526,6 +532,12 @@ let explorer = {
             msg = " ";  // triggers annotation deletion
         }
         server.send(["ANNOTATE", unparser.to_yx(explorer.position), msg]);
+    },
+    set_portal: function(msg) {
+        if (msg.length == 0) {
+            msg = " ";  // triggers portal deletion
+        }
+        server.send(["PORTAL", unparser.to_yx(explorer.position), msg]);
     }
 }
 
@@ -544,6 +556,7 @@ tui.inputEl.addEventListener('input', (event) => {
         if (['Y', 'y'].includes(tui.inputEl.value[0])) {
             server.reconnect_to(tui.teleport_target);
        } else {
+            tui.log_msg("@ teleportation aborted");
             tui.switch_mode(mode_play);
        }
     }
@@ -555,6 +568,9 @@ tui.inputEl.addEventListener('keydown', (event) => {
     if (tui.mode == mode_login && event.key == 'Enter') {
         server.send(['LOGIN', tui.inputEl.value]);
         tui.switch_mode(mode_login);
+    } else if (tui.mode == mode_portal && event.key == 'Enter') {
+        explorer.set_portal(tui.inputEl.value);
+        tui.switch_mode(mode_study, true);
     } else if (tui.mode == mode_annotate && event.key == 'Enter') {
         explorer.annotate(tui.inputEl.value);
         tui.switch_mode(mode_study, true);
@@ -625,6 +641,9 @@ tui.inputEl.addEventListener('keydown', (event) => {
             tui.switch_mode(mode_chat);
         } else if (event.key == 'p') {
             tui.switch_mode(mode_play);
+        } else if (event.key === 'P') {
+            event.preventDefault();
+            tui.switch_mode(mode_portal);
         } else if (event.key === tui.key_left) {
              explorer.move('left');
         } else if (event.key === tui.key_right) {