X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=blobdiff_plain;f=empathy%2Fempathy.jsx;h=9b37d0753f3f2839b4fb0e53c8966ff26f34b364;hp=0c1fccfe0b60e1a399c2d2bf2c27082c46c1c5eb;hb=0e96dcd31acbae3c82d430db85da5be398e88264;hpb=13c7633c804d5d1e51f2af1083f96e20b784ecfb diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx index 0c1fccf..9b37d07 100644 --- a/empathy/empathy.jsx +++ b/empathy/empathy.jsx @@ -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); @@ -82,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 => { @@ -168,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 * *********************************************************/ @@ -552,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(', ')}

@@ -714,7 +736,7 @@ class ActivePrompt extends React.PureComponent {

Submission received

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

@@ -798,7 +820,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 }; } @@ -827,6 +851,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: [], @@ -840,7 +870,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 }); } @@ -970,7 +1002,6 @@ class Game extends React.PureComponent { } set_judging_idle(value) { - console.log("Setting judging idle to " + value); this.setState({ judging_idle: value }); @@ -1000,6 +1031,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; @@ -1012,7 +1067,7 @@ class Game extends React.PureComponent { {state.scores.scores.map(score => { return (

  • - {score.player}: {score.score} + {score.players.join("/")}: {score.score}
  • ); })} @@ -1022,16 +1077,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(', ')}
  • ); })}
    ); @@ -1060,6 +1127,9 @@ class Game extends React.PureComponent { />; } + if (! state.ready) + return null; + return [