From: Carl Worth Date: Wed, 10 Jun 2020 03:03:02 +0000 (-0700) Subject: Display the number of players who have already submitted answers X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=commitdiff_plain;h=a3d68ced6e2f65187e4fc076a488715a777b8a62 Display the number of players who have already submitted answers With a message that could look like this: 2/5 players have responded And of course, that dynamically updates. This lets players at least know that something is happening, or whether they are still waiting for somebody. --- diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx index 3946189..2aec434 100644 --- a/empathy/empathy.jsx +++ b/empathy/empathy.jsx @@ -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 (
-

Answers submitted

+

{this.props.players_answered}/ + {this.props.players_total} players have responded

Please wait for the rest of the players to submit their answers.

@@ -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 ; }