home · contact · privacy
Add player faces/hats popping up n their chat messages, if in FOV.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 11 Dec 2020 03:37:23 +0000 (04:37 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 11 Dec 2020 03:37:23 +0000 (04:37 +0100)
plomrogue/things.py
rogue_chat.html
rogue_chat_curses.py

index 9bf03b2f0d881364c56a32999d6a16c8fe1b13c4..0195a623f88e2426f214d56b1ce80b5bad887ac4 100644 (file)
@@ -94,6 +94,8 @@ class Thing(ThingBase):
                                                                lowered_nick,
                                                                lowered_msg)),
                               c_id)
+            if listener.fov_test(self.position[0], self.position[1]):
+                self.game.io.send('CHATFACE %s' % self.id_)
 
 
 
index 16a27ba68a4b6739615a506b4497088598d80d44..5a55f3bd1d01254e7531b03762d83508baea4739 100644 (file)
@@ -539,6 +539,8 @@ let server = {
             }
         } else if (tokens[0] === 'CHAT') {
              tui.log_msg('# ' + tokens[1], 1);
+        } else if (tokens[0] === 'CHATFACE') {
+            tui.draw_face = tokens[1];
         } else if (tokens[0] === 'REPLY') {
              tui.log_msg('#MUSICPLAYER: ' + tokens[1], 1);
         } else if (tokens[0] === 'PLAYER_ID') {
@@ -701,6 +703,7 @@ let tui = {
   offset: [0,0],
   map_lines: [],
   selectables: [],
+  draw_face: false,
   init: function() {
       this.mode_play.available_modes = ["chat", "study", "edit", "admin_enter",
                                         "command_thing", "take_thing", "drop_thing"]
@@ -1127,6 +1130,27 @@ let tui = {
         terminal.write(term_y, term_x, to_draw);
     }
   },
+  draw_face_popup: function() {
+      const t = game.things[this.draw_face];
+      if (!t) {
+          this.draw_face = false;
+          return;
+      }
+      function draw_body_part(body_part, end_y) {
+          const start_x = tui.window_width - 10;
+          terminal.write(end_y - 4, start_x, '+--------+');
+          terminal.write(end_y - 3, start_x, '|        |');
+          terminal.write(end_y - 2, start_x, '| ' + body_part.slice(0, 6) + ' |');
+          terminal.write(end_y - 1, start_x, '| ' + body_part.slice(6, 12) + ' |');
+          terminal.write(end_y, start_x, '| ' + body_part.slice(12, 18) + ' |');
+      }
+      if (t.face) {
+          draw_body_part(t.face, terminal.rows - 1);
+      }
+      if (t.hat) {
+          draw_body_part(t.hat, terminal.rows - 4);
+      }
+  },
   draw_mode_line: function() {
       let help = 'hit [' + this.keys.help + '] for help';
       if (this.mode.has_input_prompt) {
@@ -1264,6 +1288,9 @@ let tui = {
     if (this.show_help) {
         this.draw_help();
     }
+    if (this.draw_face && ['chat', 'play'].includes(this.mode.name)) {
+        this.draw_face_popup();
+    }
     if (!this.draw_links) {
         this.links = {};
     }
@@ -1475,6 +1502,7 @@ document.onclick = function() {
 };
 tui.inputEl.addEventListener('keydown', (event) => {
     tui.show_help = false;
+    tui.draw_face = false;
     if (event.key == 'Enter') {
         event.preventDefault();
     }
index 5046de199ce0f7c6db4f31bd176eded30235d002..7d2a3b163b0d3a05f4c0a24ffe1f2e3b2b67d95a 100755 (executable)
@@ -200,6 +200,10 @@ def cmd_CHAT(game, msg):
     game.tui.do_refresh = True
 cmd_CHAT.argtypes = 'string'
 
+def cmd_CHATFACE(game, thing_id):
+    game.tui.draw_face = thing_id
+cmd_CHATFACE.argtypes = 'int:pos'
+
 def cmd_PLAYER_ID(game, player_id):
     game.player_id = player_id
 cmd_PLAYER_ID.argtypes = 'int:nonneg'
@@ -348,6 +352,7 @@ class Game(GameBase):
         self.register_command(cmd_ADMIN_OK)
         self.register_command(cmd_PONG)
         self.register_command(cmd_CHAT)
+        self.register_command(cmd_CHATFACE)
         self.register_command(cmd_REPLY)
         self.register_command(cmd_PLAYER_ID)
         self.register_command(cmd_TURN)
@@ -543,6 +548,7 @@ class TUI:
         self.fov = ''
         self.flash = False
         self.map_lines = []
+        self.draw_face = False
         self.offset = YX(0,0)
         curses.wrapper(self.loop)
 
@@ -957,6 +963,25 @@ class TUI:
                 term_y += 1
                 map_y += 1
 
+        def draw_face_popup():
+            t = self.game.get_thing(self.draw_face)
+            if not t:
+                self.draw_face = False
+                return
+
+            def draw_body_part(body_part, end_y):
+                start_x = self.window_width - 10
+                safe_addstr(end_y - 4, start_x, '+--------+')
+                safe_addstr(end_y - 3, start_x, '|        |')
+                safe_addstr(end_y - 2, start_x, '| ' + body_part[0:6] + ' |')
+                safe_addstr(end_y - 1, start_x, '| ' + body_part[6:12] + ' |')
+                safe_addstr(end_y, start_x, '| ' + body_part[12:18] + ' |')
+
+            if hasattr(t, 'face'):
+                draw_body_part(t.face, self.size.y - 1)
+            if hasattr(t, 'hat'):
+                draw_body_part(t.hat, self.size.y - 4)
+
         def draw_help():
             content = "%s help\n\n%s\n\n" % (self.mode.short_desc,
                                              self.mode.help_intro)
@@ -1005,6 +1030,8 @@ class TUI:
                 draw_map()
             if self.show_help:
                 draw_help()
+            if self.draw_face and self.mode.name in {'chat', 'play'}:
+                draw_face_popup()
 
         def pick_selectable(task_name):
             try:
@@ -1089,6 +1116,7 @@ class TUI:
             if len(key) == 1:
                 keycode = ord(key)
             self.show_help = False
+            self.draw_face = False
             if key == 'KEY_RESIZE':
                 reset_screen_size()
             elif self.mode.has_input_prompt and key == 'KEY_BACKSPACE':