home · contact · privacy
Identify player in client so scrolling can follow them.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 26 Oct 2020 23:14:38 +0000 (00:14 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 26 Oct 2020 23:14:38 +0000 (00:14 +0100)
new2/plomrogue/commands.py
new2/rogue_chat_nocanvas_monochrome.html

index 397dbe45f332aae29d22e6fba8671786496a4316..352f40dc1af3a64e99564a7033f2fb8626422f3c 100644 (file)
@@ -18,6 +18,7 @@ def cmd_LOGIN(game, nick, connection_id):
     game.things += [t]  # TODO refactor into Thing.__init__?
     game.sessions[connection_id] = t.id_ 
     game.io.send('META ' + quote('you are now: ' + nick), connection_id)
+    game.io.send('PLAYER_ID %s' % t.id_, connection_id)
 cmd_LOGIN.argtypes = 'string'
 
 def cmd_QUERY(game, target_nick, msg, connection_id):
index df29814dc9fe87b926092c48e75e76c70f3dda53..d873b3761d658d5daae3b7ee7ce45cd4b630b9c4 100644 (file)
@@ -127,7 +127,9 @@ let tui = {
     for (const thing_id in game.things) {
         let t = game.things[thing_id];
         map_lines[t[0]][t[1]] = '@';
-        player_position = t;
+        if (game.player_id == thing_id) {
+            player_position = t;
+        }
     }
     let offset = [(terminal.rows / 2) - player_position[0],
                   terminal.cols / 4 - player_position[1]];
@@ -174,7 +176,8 @@ let game = {
   things: {},
   turn: 0,
   map: "",
-  map_size: [0,0]
+  map_size: [0,0],
+  player_id: 0
 }
 
 let chat = {
@@ -223,6 +226,8 @@ websocket.onmessage = function (event) {
   } else if (tokens[0] === 'LOG') {
      tui.log_msg(tokens[1], 1);
      tui.refresh();
+  } else if (tokens[0] === 'PLAYER_ID') {
+      game.player_id = parseInt(tokens[1]);
   } else if (tokens[0] === 'META') {
      tui.log_msg(tokens[1]);
      tui.refresh();