]> git.cworth.org Git - lmno.games/commitdiff
empathy: Track the player-exit event
authorCarl Worth <cworth@cworth.org>
Sat, 27 Jun 2020 18:07:49 +0000 (11:07 -0700)
committerCarl Worth <cworth@cworth.org>
Sat, 27 Jun 2020 18:07:49 +0000 (11:07 -0700)
Now that the server is correctly noticing when a client drops it
connection, and notifying clients when a player has dropped every
connection, we now listen for that and drop players from our list
when they have left the game.

empathy/empathy.jsx

index 0c1fccfe0b60e1a399c2d2bf2c27082c46c1c5eb..20612e35336576b229c4a8f9fccc7e7bd1179e97 100644 (file)
@@ -45,6 +45,12 @@ events.addEventListener("player-enter", event => {
   window.game.set_other_player_info(info);
 });
 
+events.addEventListener("player-exit", event => {
+  const info = JSON.parse(event.data);
+
+  window.game.remove_player(info);
+});
+
 events.addEventListener("player-update", event => {
   const info = JSON.parse(event.data);
 
@@ -827,6 +833,12 @@ class Game extends React.PureComponent {
     });
   }
 
+  remove_player(info) {
+    this.setState({
+      other_players: this.state.other_players.filter(o => o.id !== info.id)
+    });
+  }
+
   reset_game_state() {
     this.setState({
       prompts: [],