home · contact · privacy
dd annotation hints view.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 18 Nov 2020 04:35:33 +0000 (05:35 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 18 Nov 2020 04:35:33 +0000 (05:35 +0100)
plomrogue/game.py
rogue_chat_curses.py
rogue_chat_nocanvas_monochrome.html

index ccd51dcc1b363e1d6e1cb46428dd96b61ad023cb..84bebb98c2d4a45f0a1f68619681790f07ce5d99 100755 (executable)
@@ -146,6 +146,12 @@ class Game(GameBase):
                     target_yx = player.fov_stencil.target_yx(big_yx, little_yx)
                     portal = self.portals[big_yx][little_yx]
                     self.io.send('PORTAL %s %s' % (target_yx, quote(portal)), c_id)
+            for big_yx in self.annotations:
+                for little_yx in [little_yx for little_yx in self.annotations[big_yx]
+                                  if player.fov_test(big_yx, little_yx)]:
+                    target_yx = player.fov_stencil.target_yx(big_yx, little_yx)
+                    annotation = self.annotations[big_yx][little_yx]
+                    self.io.send('ANNOTATION_HINT %s' % (target_yx,), c_id)
         self.io.send('GAME_STATE_COMPLETE')
 
     def run_tick(self):
index 15f4cd2db0b8773ff1ab68dd05abdc971f9227db..54499daf2551ac335dc93ff9f274d1dcc09bd136 100755 (executable)
@@ -51,6 +51,8 @@ class PlomSocketClient(PlomSocket):
             pass  # we assume socket will be known as dead by now
 
 def cmd_TURN(game, n):
+    game.info_db = {}
+    game.info_hints = []
     game.turn = n
     game.things = []
     game.portals = {}
@@ -124,7 +126,6 @@ def cmd_MAP_CONTROL(game, content):
 cmd_MAP_CONTROL.argtypes = 'string'
 
 def cmd_GAME_STATE_COMPLETE(game):
-    game.info_db = {}
     if game.tui.mode.name == 'post_login_wait':
         game.tui.switch_mode('play')
     if game.tui.mode.shows_info:
@@ -153,6 +154,10 @@ def cmd_ARGUMENT_ERROR(game, msg):
     game.tui.do_refresh = True
 cmd_ARGUMENT_ERROR.argtypes = 'string'
 
+def cmd_ANNOTATION_HINT(game, position):
+    game.info_hints += [position]
+cmd_ANNOTATION_HINT.argtypes = 'yx_tuple:nonneg'
+
 def cmd_ANNOTATION(game, position, msg):
     game.info_db[position] = msg
     game.tui.restore_input_values()
@@ -197,6 +202,7 @@ class Game(GameBase):
         self.register_command(cmd_MAP_CONTROL)
         self.register_command(cmd_PORTAL)
         self.register_command(cmd_ANNOTATION)
+        self.register_command(cmd_ANNOTATION_HINT)
         self.register_command(cmd_GAME_STATE_COMPLETE)
         self.register_command(cmd_ARGUMENT_ERROR)
         self.register_command(cmd_GAME_ERROR)
@@ -206,6 +212,7 @@ class Game(GameBase):
         self.map_content = ''
         self.player_id = -1
         self.info_db = {}
+        self.info_hints = []
         self.portals = {}
         self.terrains = {}
 
@@ -509,7 +516,10 @@ class TUI:
                 start = self.game.map_geometry.size.x * y
                 end = start + self.game.map_geometry.size.x
                 map_lines_split += [[c + ' ' for c in map_content[start:end]]]
-            if self.map_mode == 'terrain':
+            if self.map_mode == 'annotations':
+                for p in self.game.info_hints:
+                    map_lines_split[p.y][p.x] = 'A '
+            elif self.map_mode == 'terrain':
                 for p in self.game.portals.keys():
                     map_lines_split[p.y][p.x] = 'P '
                 used_positions = []
@@ -577,13 +587,12 @@ class TUI:
             elif self.mode == self.mode_study:
                 content += 'Available actions:\n'
                 content += '[%s] – move question mark\n' % ','.join(self.movement_keys)
-                content += '[%s] – toggle view between terrain, and password protection areas\n' % self.keys['toggle_map_mode']
+                content += '[%s] – toggle view between terrain, annotations, and password protection areas\n' % self.keys['toggle_map_mode']
                 content += '\n\nOther modes available from here:'
                 content += '[%s] – chat mode\n' % self.keys['switch_to_chat']
                 content += '[%s] – play mode\n' % self.keys['switch_to_play']
             elif self.mode == self.mode_chat:
                 content += '/nick NAME – re-name yourself to NAME\n'
-                #content += '/msg USER TEXT – send TEXT to USER\n'
                 content += '/%s or /play – switch to play mode\n' % self.keys['switch_to_play']
                 content += '/%s or /study – switch to study mode\n' % self.keys['switch_to_study']
             for i in range(self.size.y):
@@ -719,6 +728,8 @@ class TUI:
                     self.switch_mode('play')
                 elif key == self.keys['toggle_map_mode']:
                     if self.map_mode == 'terrain':
+                        self.map_mode = 'annotations'
+                    elif self.map_mode == 'annotations':
                         self.map_mode = 'control'
                     else:
                         self.map_mode = 'terrain'
index a5b2d69d81913938ba42c2ec4b9bee549e7779df..88b66723d9ee6f5f54aa2a06dada0214f22a80f4 100644 (file)
@@ -29,7 +29,7 @@ terminal columns: <input id="n_cols" type="number" step=4 min=80 value=80 />
 <button id="switch_to_password">change tile editing password</button>
 <button id="switch_to_annotate">annotate tile</button>
 <button id="switch_to_portal">edit portal link</button>
-<button id="toggle_map_mode">toggle terrain/control view</button>
+<button id="toggle_map_mode">toggle terrain/annotations/control view</button>
 </div>
 <h3>edit keybindings</h3> (see <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">here</a> for non-obvious available values):<br />
 <ul>
@@ -55,7 +55,7 @@ terminal columns: <input id="n_cols" type="number" step=4 min=80 value=80 />
 <li>enter tile password (from play mode): <input id="key_switch_to_password" type="text" value="P" />
 <li>annotate tile (from play mode): <input id="key_switch_to_annotate" type="text" value="M" />
 <li>annotate portal (from play mode): <input id="key_switch_to_portal" type="text" value="T" />
-<li>toggle terrain/control view (from study mode): <input id="key_toggle_map_mode" type="text" value="M" />
+<li>toggle terrain/annotations/control view (from study mode): <input id="key_toggle_map_mode" type="text" value="M" />
 </ul>
 </div>
 <script>
@@ -223,6 +223,7 @@ let server = {
         let tokens = parser.tokenize(event.data);
         if (tokens[0] === 'TURN') {
             game.turn_complete = false;
+            explorer.empty_info_db();
             game.things = {};
             game.portals = {};
             game.turn = parseInt(tokens[1]);
@@ -257,7 +258,6 @@ let server = {
             game.map_control = tokens[1]
         } else if (tokens[0] === 'GAME_STATE_COMPLETE') {
             game.turn_complete = true;
-            explorer.empty_info_db();
             if (tui.mode == mode_post_login_wait) {
                 tui.switch_mode(mode_play);
             } else if (tui.mode == mode_study) {
@@ -274,6 +274,9 @@ let server = {
         } else if (tokens[0] === 'PORTAL') {
             let position = parser.parse_yx(tokens[1]);
             game.portals[position] = tokens[2];
+        } else if (tokens[0] === 'ANNOTATION_HINT') {
+            let position = parser.parse_yx(tokens[1]);
+            explorer.info_hints = explorer.info_hints.concat([position]);
         } else if (tokens[0] === 'ANNOTATION') {
             let position = parser.parse_yx(tokens[1]);
             explorer.update_info_db(position, tokens[2]);
@@ -532,7 +535,11 @@ let tui = {
         line.push(map_content[i] + ' ');
     };
     map_lines_split.push(line);
-    if (this.map_mode == 'terrain') {
+    if (this.map_mode == 'annotations') {
+        for (const coordinate of explorer.info_hints) {
+            map_lines_split[coordinate[0]][coordinate[1]] = 'A ';
+        }
+    } else if (this.map_mode == 'terrain') {
         for (const p in game.portals) {
             let coordinate = p.split(',')
             map_lines_split[coordinate[0]][coordinate[1]] = 'P ';
@@ -655,7 +662,7 @@ let tui = {
       } else if (this.mode == mode_study) {
           content += "Available actions:\n";
           content += '[' + movement_keys_desc + '] – move question mark\n';
-          content += '[' + this.keys.toggle_map_mode + '] – toggle view between terrain, and password protection areas\n';
+          content += '[' + this.keys.toggle_map_mode + '] – toggle view between terrain, annotations, and password protection areas\n';
           content += '\nOther modes available from here:\n';
           content += '[' + this.keys.switch_to_chat + '] – chat mode\n';
           content += '[' + this.keys.switch_to_play + '] – play mode\n';
@@ -780,6 +787,7 @@ server.init(websocket_location);
 let explorer = {
     position: [0,0],
     info_db: {},
+    info_hints: [],
     move: function(direction) {
         let target = game.move(this.position, direction);
         if (target) {
@@ -797,6 +805,7 @@ let explorer = {
     },
     empty_info_db: function() {
         this.info_db = {};
+        this.info_hints = [];
         if (tui.mode == mode_study) {
             tui.full_refresh();
         }
@@ -962,6 +971,8 @@ tui.inputEl.addEventListener('keydown', (event) => {
             explorer.move(tui.movement_keys[event.key]);
         } else if (event.key == tui.keys.toggle_map_mode) {
             if (tui.map_mode == 'terrain') {
+                tui.map_mode = 'annotations';
+            } else if (tui.map_mode == 'annotations') {
                 tui.map_mode = 'control';
             } else {
                 tui.map_mode = 'terrain';
@@ -1039,6 +1050,8 @@ document.getElementById("switch_to_portal").onclick = function() {
 };
 document.getElementById("toggle_map_mode").onclick = function() {
     if (tui.map_mode == 'terrain') {
+        tui.map_mode = 'annotations';
+    } else if (tui.map_mode == 'annotations') {
         tui.map_mode = 'control';
     } else {
         tui.map_mode = 'terrain';