X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=blobdiff_plain;f=empathy%2Fempathy.jsx;h=6133463f35a7a9d6ba4d58cbe8e4188bf4af48a9;hp=20612e35336576b229c4a8f9fccc7e7bd1179e97;hb=f8b6dc7aef51ccc82d163f015612c7640f0be365;hpb=351aafa7ed0e7839d9308d9e2302852eb0688b6a diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx index 20612e3..6133463 100644 --- a/empathy/empathy.jsx +++ b/empathy/empathy.jsx @@ -88,6 +88,10 @@ events.addEventListener("game-state", event => { window.game.set_end_judging(state.end_judging); window.game.set_scores(state.scores); + + window.game.set_new_game_votes(state.new_game_votes); + + window.game.state_ready(); }); events.addEventListener("prompt", event => { @@ -174,6 +178,18 @@ events.addEventListener("scores", event => { window.game.set_scores(scores); }); +events.addEventListener("vote-new-game", event => { + const player = JSON.parse(event.data); + + window.game.set_player_vote_new_game(player); +}); + +events.addEventListener("unvote-new-game", event => { + const player = JSON.parse(event.data); + + window.game.set_player_unvote_new_game(player); +}); + /********************************************************* * Game and supporting classes * *********************************************************/ @@ -558,7 +574,7 @@ class Ambiguities extends React.PureComponent {

Submission received

- The following players have completed judging: + The following players have completed judging:{' '} {[...this.props.players_judged].join(', ')}

@@ -595,6 +611,7 @@ class Ambiguities extends React.PureComponent { what goes around comes around, so it's best to be generous when judging.

+

{this.props.prompt.prompt}

{this.state.word_sets.map(set => { return (

Submission received

- The following players have submitted their answers: + The following players have submitted their answers:{' '} {[...this.props.players_answered].join(', ')}

@@ -751,7 +768,8 @@ class ActivePrompt extends React.PureComponent {

Remember, you're trying to match your answers with what the other players submit. - Give {this.props.prompt.items} answers for the following prompt: + Give {this.props.prompt.items} answer + {this.props.prompt.items > 1 ? 's' : ''} for the following prompt:

{this.props.prompt.prompt}

@@ -804,7 +822,9 @@ class Game extends React.PureComponent { players_judging: {}, judging_idle: false, end_judging_votes: new Set(), - scores: null + scores: null, + new_game_votes: new Set(), + ready: false }; } @@ -852,7 +872,9 @@ class Game extends React.PureComponent { players_judging: {}, judging_idle: false, end_judging_votes: new Set(), - scores: null + scores: null, + new_game_votes: new Set(), + ready: false }); } @@ -982,7 +1004,6 @@ class Game extends React.PureComponent { } set_judging_idle(value) { - console.log("Setting judging idle to " + value); this.setState({ judging_idle: value }); @@ -1012,6 +1033,30 @@ class Game extends React.PureComponent { }); } + set_new_game_votes(players) { + this.setState({ + new_game_votes: new Set(players) + }); + } + + set_player_vote_new_game(player) { + this.setState({ + new_game_votes: new Set([...this.state.new_game_votes, player]) + }); + } + + set_player_unvote_new_game(player) { + this.setState({ + new_game_votes: new Set([...this.state.new_game_votes].filter(p => p !== player)) + }); + } + + state_ready() { + this.setState({ + ready: true + }); + } + render() { const state = this.state; const players_total = 1 + state.other_players.length; @@ -1019,12 +1064,13 @@ class Game extends React.PureComponent { if (state.scores) { return (
+

{state.active_prompt.prompt}

Scores

    {state.scores.scores.map(score => { return (
  • - {score.player}: {score.score} + {score.players.join("/")}: {score.score}
  • ); })} @@ -1034,16 +1080,28 @@ class Game extends React.PureComponent { {state.scores.words.map(word => { return (
  • - {`${word.word}: ${word.players.join(', ')}`} + {word.word} ({word.players.length}): {word.players.join(', ')}
  • ); })}
); @@ -1072,6 +1130,9 @@ class Game extends React.PureComponent { />; } + if (! state.ready) + return null; + return [