home · contact · privacy
Add player faces/hats popping up n their chat messages, if in FOV.
[plomrogue2] / rogue_chat.html
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();
     }