Copy several game-state members into client state
authorCarl Worth <cworth@cworth.org>
Sun, 14 Jun 2020 22:00:04 +0000 (15:00 -0700)
committerCarl Worth <cworth@cworth.org>
Sun, 14 Jun 2020 22:00:04 +0000 (15:00 -0700)
The server has been telling us (or trying to at least: see recent bug
fixes with JSON serialization of Set objects) the lists of players who
are in the process of answering or judging within the game-state
object, but the client has been ignoring this.

Without this fix, reloading of a status page could cause names to
disappear from the "still waiting" lists or the "move on" buttons.

empathy/empathy.jsx

index 973a9537f591e34917ff5a476c997cb795ac3de5..566ad105c5e3cdb3727ffe504d74ca52e9c0efc4 100644 (file)
@@ -63,9 +63,21 @@ events.addEventListener("game-state", event => {
 
   window.game.set_active_prompt(state.active_prompt);
 
-  window.game.set_scores(state.scores);
+  window.game.set_players_answered(state.players_answered);
+
+  window.game.set_players_answering(state.players_answering);
+
+  window.game.set_end_answers(state.end_answers);
 
   window.game.set_ambiguities(state.ambiguities);
+
+  window.game.set_players_judged(state.players_judged);
+
+  window.game.set_players_judging(state.players_judging);
+
+  window.game.set_end_judging(state.end_judging);
+
+  window.game.set_scores(state.scores);
 });
 
 events.addEventListener("prompt", event => {
@@ -812,6 +824,12 @@ class Game extends React.PureComponent {
     });
   }
 
+  set_players_answered(players) {
+    this.setState({
+      players_answered: new Set(players)
+    });
+  }
+
   set_player_answered(player) {
     const new_players_answering = {...this.state.players_answering};
     delete new_players_answering[player];
@@ -822,6 +840,16 @@ class Game extends React.PureComponent {
     });
   }
 
+  set_players_answering(players) {
+    const players_answering = {};
+    for (let player of players) {
+      players_answering[player] = {active: false};
+    }
+    this.setState({
+      players_answering: players_answering
+    });
+  }
+
   set_player_answering(player) {
     this.setState({
       players_answering: {
@@ -831,6 +859,12 @@ class Game extends React.PureComponent {
     });
   }
 
+  set_end_answers(players) {
+    this.setState({
+      end_answers_votes: new Set(players)
+    });
+  }
+
   set_player_vote_end_answers(player) {
     this.setState({
       end_answers_votes: new Set([...this.state.end_answers_votes, player])
@@ -849,6 +883,12 @@ class Game extends React.PureComponent {
     });
   }
 
+  set_players_judged(players) {
+    this.setState({
+      players_judged: new Set(players)
+    });
+  }
+
   set_player_judged(player) {
     const new_players_judging = {...this.state.players_judging};
     delete new_players_judging[player];
@@ -859,6 +899,16 @@ class Game extends React.PureComponent {
     });
   }
 
+  set_players_judging(players) {
+    const players_judging = {};
+    for (let player of players) {
+      players_judging[player] = {active: false};
+    }
+    this.setState({
+      players_judging: players_judging
+    });
+  }
+
   set_player_judging(player) {
     this.setState({
       players_judging: {
@@ -868,6 +918,11 @@ class Game extends React.PureComponent {
     });
   }
 
+  set_end_judging(players) {
+    this.setState({
+      end_judging_votes: new Set(players)
+    });
+  }
 
   set_player_vote_end_judging(player) {
     this.setState({