home · contact · privacy
In web client, enforce terminal size restrictions harder.
[plomrogue2] / rogue_chat_nocanvas_monochrome.html
index f037bc74978d5f837434a40c9b65aa038a7c1ed3..d6e8a6ed3798cbf8165ba1333206de5646bec220 100644 (file)
@@ -4,8 +4,8 @@
 </style>
 </head><body>
 <div>
-terminal rows: <input id="n_rows" type="number" step=4 min=8 value=24 />
-terminal columns: <input id="n_cols" type="number" step=4 min=20 value=80 />
+terminal rows: <input id="n_rows" type="number" step=4 min=24 value=24 />
+terminal columns: <input id="n_cols" type="number" step=4 min=80 value=80 />
 </div>
 <pre id="terminal" style="display: inline-block;"></pre>
 <textarea id="input" style="opacity: 0; width: 0px;"></textarea>
@@ -24,6 +24,7 @@ terminal columns: <input id="n_cols" type="number" step=4 min=20 value=80 />
 <button id="take_thing">take thing</button>
 <button id="drop_thing">drop thing</button>
 <button id="flatten">flatten surroundings</button>
+<button id="teleport">teleport</button>
 <button id="switch_to_edit">change tile</button><br />
 <button id="switch_to_password">change tile editing password</button>
 <button id="switch_to_annotate">annotate tile</button>
@@ -44,6 +45,7 @@ terminal columns: <input id="n_cols" type="number" step=4 min=20 value=80 />
 <li>move left (hex grid): <input id="key_hex_move_left" type="text" value="a" />
 <li>help: <input id="key_help" type="text" value="h" />
 <li>flatten surroundings: <input id="key_flatten" type="text" value="F" />
+<li>teleport: <input id="key_teleport" type="text" value="p" />
 <li>take thing under player: <input id="key_take_thing" type="text" value="z" />
 <li>drop carried thing: <input id="key_drop_thing" type="text" value="u" />
 <li>switch to chat mode: <input id="key_switch_to_chat" type="text" value="t" />
@@ -140,7 +142,6 @@ terminal.initialize();
 
 let parser = {
   tokenize: function(str) {
-    let token_ends = [];
     let tokens = [];
     let token = ''
     let quoted = false;
@@ -162,7 +163,6 @@ let parser = {
         quoted = true
       } else if (c === ' ') {
         if (token.length > 0) {
-          token_ends.push(i);
           tokens.push(token);
           token = '';
         }
@@ -173,11 +173,7 @@ let parser = {
     if (token.length > 0) {
       tokens.push(token);
     }
-    let token_starts = [];
-    for (let i = 0; i < token_ends.length; i++) {
-      token_starts.push(token_ends[i] - tokens[i].length);
-    };
-    return [tokens, token_starts];
+    return tokens;
   },
   parse_yx: function(position_string) {
     let coordinate_strings = position_string.split(',')
@@ -223,7 +219,7 @@ let server = {
         this.websocket.send(unparser.untokenize(tokens));
     },
     handle_event: function(event) {
-        let tokens = parser.tokenize(event.data)[0];
+        let tokens = parser.tokenize(event.data);
         if (tokens[0] === 'TURN') {
             game.turn_complete = false;
             game.things = {};
@@ -266,12 +262,6 @@ let server = {
             } else if (tui.mode == mode_study) {
                 explorer.query_info();
             }
-            let t = game.get_thing(game.player_id);
-            if (t.position in game.portals) {
-                tui.teleport_target = game.portals[t.position];
-                tui.switch_mode(mode_teleport);
-                return;
-            }
             tui.full_refresh();
         } else if (tokens[0] === 'CHAT') {
              tui.log_msg('# ' + tokens[1], 1);
@@ -289,6 +279,7 @@ let server = {
         } else if (tokens[0] === 'UNHANDLED_INPUT') {
             tui.log_msg('? unknown command');
         } else if (tokens[0] === 'PLAY_ERROR') {
+            tui.log_msg('? ' + tokens[1]);
             terminal.blink_screen();
         } else if (tokens[0] === 'ARGUMENT_ERROR') {
             tui.log_msg('? syntax error: ' + tokens[1]);
@@ -344,7 +335,6 @@ let mode_chat = new Mode('chat', 'This mode allows you to engage in chit-chat wi
 let mode_play = new Mode('play', 'This mode allows you to interact with the map.', false, false);
 let mode_study = new Mode('study', 'This mode allows you to study the map and its tiles in detail.  Move the question mark over a tile, and the right half of the screen will show detailed information on it.', false, true);
 let mode_edit = new Mode('edit', '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.', false, false);
-let mode_teleport = new Mode('teleport', 'Follow the instructions to re-connect and log-in to another server, or enter anything else to abort.', true);
 let mode_portal = new Mode('portal', 'This mode allows you to imprint/edit/remove a teleportation target on the ground you are currently standing on (provided your map editing password authorizes you so).  Enter or edit a URL to imprint a teleportation target; enter emptiness to remove a pre-existing teleportation target.  Hit Return to leave.', true, true);
 let mode_password = new Mode('password', 'This mode allows you to change the password that you send to authorize yourself for editing password-protected map tiles.  Hit return to confirm and leave.', true, false, false);
 
@@ -390,6 +380,7 @@ let tui = {
     };
   },
   switch_mode: function(mode) {
+    this.inputEl.focus();
     this.show_help = false;
     this.map_mode = 'terrain';
     if (mode.shows_info && game.player_id in game.things) {
@@ -401,6 +392,7 @@ let tui = {
     document.getElementById("take_thing").disabled = true;
     document.getElementById("drop_thing").disabled = true;
     document.getElementById("flatten").disabled = true;
+    document.getElementById("teleport").disabled = true;
     document.getElementById("toggle_map_mode").disabled = true;
     document.getElementById("switch_to_chat").disabled = true;
     document.getElementById("switch_to_play").disabled = true;
@@ -457,6 +449,7 @@ let tui = {
         }
         if (game.tasks.includes('MOVE')) {
         }
+        document.getElementById("teleport").disabled = false;
         document.getElementById("switch_to_annotate").disabled = false;
         document.getElementById("switch_to_edit").disabled = false;
         document.getElementById("switch_to_portal").disabled = false;
@@ -465,9 +458,6 @@ let tui = {
         document.getElementById("toggle_map_mode").disabled = false;
     } else if (mode == mode_edit) {
         this.show_help = true;
-    } else if (mode == mode_teleport) {
-        tui.log_msg("@ May teleport to: " + tui.teleport_target);
-        tui.log_msg("@ Enter 'YES!' to entusiastically affirm.");
     }
     this.full_refresh();
   },
@@ -539,6 +529,10 @@ let tui = {
     };
     map_lines_split.push(line);
     if (this.map_mode == 'terrain') {
+        for (const p in game.portals) {
+            let coordinate = p.split(',')
+            map_lines_split[coordinate[0]][coordinate[1]] = 'P ';
+        }
         let used_positions = [];
         for (const thing_id in game.things) {
             let t = game.things[thing_id];
@@ -646,6 +640,7 @@ let tui = {
           if (game.tasks.includes('FLATTEN_SURROUNDINGS')) {
               content += "[" + tui.keys.flatten + "] – flatten player's surroundings\n";
           }
+          content += "[" + tui.keys.teleport + "] – teleport to other space\n";
           content += '\nOther modes available from here:\n';
           content += '[' + this.keys.switch_to_chat + '] – chat mode\n';
           content += '[' + this.keys.switch_to_study + '] – study mode\n';
@@ -662,7 +657,6 @@ let tui = {
           content += '[' + this.keys.switch_to_play + '] – play mode\n';
       } else if (this.mode == mode_chat) {
           content += '/nick NAME – re-name yourself to NAME\n';
-          //content += '/msg USER TEXT – send TEXT to USER\n';
           content += '/' + this.keys.switch_to_play + ' or /play – switch to play mode\n';
           content += '/' + this.keys.switch_to_study + ' or /study – switch to study mode\n';
       }
@@ -762,6 +756,15 @@ let game = {
             return null;
         };
         return target;
+    },
+    teleport: function() {
+        let player = this.get_thing(game.player_id);
+        if (player.position in this.portals) {
+            server.reconnect_to(this.portals[player.position]);
+        } else {
+            terminal.blink_screen();
+            tui.log_msg('? not standing on portal')
+        }
     }
 }
 
@@ -860,7 +863,6 @@ tui.inputEl.addEventListener('input', (event) => {
     }
     tui.full_refresh();
 }, false);
-
 tui.inputEl.addEventListener('keydown', (event) => {
     tui.show_help = false;
     if (event.key == 'Enter') {
@@ -888,13 +890,6 @@ tui.inputEl.addEventListener('keydown', (event) => {
         }
         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);
-        } else {
-            tui.log_msg('@ teleport aborted');
-            tui.switch_mode(mode_play);
-        };
     } else if (tui.mode == mode_chat && event.key == 'Enter') {
         let [tokens, token_starts] = parser.tokenize(tui.inputEl.value);
         if (tokens.length > 0 && tokens[0].length > 0) {
@@ -909,13 +904,6 @@ tui.inputEl.addEventListener('keydown', (event) => {
                     } else {
                         tui.log_msg('? need new name');
                     }
-                //} else if (tokens[0].slice(1) == 'msg') {
-                //    if (tokens.length > 2) {
-                //        let msg = tui.inputEl.value.slice(token_starts[2]);
-                //        server.send(['QUERY', tokens[1], msg]);
-                //    } else {
-                //        tui.log_msg('? need message target and message');
-                //    }
                 } else {
                     tui.log_msg('? unknown command');
                 }
@@ -951,6 +939,8 @@ tui.inputEl.addEventListener('keydown', (event) => {
           } else if (event.key in tui.movement_keys
                      && game.tasks.includes('MOVE')) {
               server.send(['TASK:MOVE', tui.movement_keys[event.key]]);
+          } else if (event.key === tui.keys.teleport) {
+              game.teleport();
           } else if (event.key === tui.keys.switch_to_portal) {
               event.preventDefault();
               tui.switch_mode(mode_portal);
@@ -978,7 +968,7 @@ tui.inputEl.addEventListener('keydown', (event) => {
 }, false);
 
 rows_selector.addEventListener('input', function() {
-    if (rows_selector.value % 4 != 0) {
+    if (rows_selector.value % 4 != 0 || rows_selector.value < 24) {
         return;
     }
     window.localStorage.setItem(rows_selector.id, rows_selector.value);
@@ -986,7 +976,7 @@ rows_selector.addEventListener('input', function() {
     tui.full_refresh();
 }, false);
 cols_selector.addEventListener('input', function() {
-    if (cols_selector.value % 4 != 0) {
+    if (cols_selector.value % 4 != 0 || cols_selector.value < 80) {
         return;
     }
     window.localStorage.setItem(cols_selector.id, cols_selector.value);
@@ -1000,12 +990,6 @@ for (let key_selector of key_selectors) {
         tui.init_keys();
     }, false);
 }
-window.setInterval(function() {
-    if (!(['input', 'n_cols', 'n_rows'].includes(document.activeElement.id)
-          || document.activeElement.id.startsWith('key_'))) {
-        tui.inputEl.focus();
-    }
-}, 100);
 window.setInterval(function() {
     if (server.connected) {
         server.send(['PING']);
@@ -1014,7 +998,9 @@ window.setInterval(function() {
         tui.log_msg('@ attempting reconnect …')
     }
 }, 5000);
-
+document.getElementById("terminal").onclick = function() {
+    tui.inputEl.focus();
+};
 document.getElementById("help").onclick = function() {
     tui.show_help = true;
     tui.full_refresh();
@@ -1064,6 +1050,9 @@ document.getElementById("drop_thing").onclick = function() {
 document.getElementById("flatten").onclick = function() {
     server.send(['TASK:FLATTEN_SURROUNDINGS', tui.password]);
 };
+document.getElementById("teleport").onclick = function() {
+    game.teleport();
+};
 document.getElementById("move_upleft").onclick = function() {
     if (tui.mode == mode_play) {
         server.send(['TASK:MOVE', 'UPLEFT']);