]> git.cworth.org Git - lmno.games/blobdiff - empathy/empathy.jsx
Display the number of players who have already submitted answers
[lmno.games] / empathy / empathy.jsx
index 39461898cf5efd9d7478a2acd68a333c791be74c..2aec434654cf26d7bc5078298ab89f5d3739ce9d 100644 (file)
@@ -74,6 +74,12 @@ events.addEventListener("start", event => {
   window.game.set_active_prompt(prompt);
 });
 
+events.addEventListener("answered", event => {
+  const players_answered = JSON.parse(event.data);
+
+  window.game.set_players_answered(players_answered);
+});
+
 /*********************************************************
  * Game and supporting classes                           *
  *********************************************************/
@@ -336,7 +342,8 @@ class ActivePrompt extends React.PureComponent {
     if (this.state.submitted)
       return (
         <div className="please-wait">
-          <h2>Answers submitted</h2>
+          <h2>{this.props.players_answered}/
+            {this.props.players_total} players have responded</h2>
           <p>
             Please wait for the rest of the players to submit their answers.
           </p>
@@ -390,7 +397,9 @@ class Game extends React.PureComponent {
       game_info: {},
       player_info: {},
       other_players: [],
-      prompts: []
+      prompts: [],
+      active_prompt: null,
+      players_answered: 0
     };
   }
 
@@ -438,12 +447,21 @@ class Game extends React.PureComponent {
     });
   }
 
+  set_players_answered(players_answered) {
+    this.setState({
+      players_answered: players_answered
+    });
+  }
+
   render() {
     const state = this.state;
+    const players_total = 1 + state.other_players.length;
 
     if (state.active_prompt) {
       return <ActivePrompt
                prompt={state.active_prompt}
+               players_answered={state.players_answered}
+               players_total={players_total}
              />;
     }