X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=blobdiff_plain;f=empathy%2Fempathy.jsx;h=6133463f35a7a9d6ba4d58cbe8e4188bf4af48a9;hp=82bb5ff681989470aa2a78e10d9f7eedc5f42d51;hb=f8b6dc7aef51ccc82d163f015612c7640f0be365;hpb=9e08b1b85cc467336129e22bc0ece6dfe74d204e diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx index 82bb5ff..6133463 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 * *********************************************************/ @@ -205,20 +227,23 @@ const PlayerInfo = React.memo(props => { if (! props.player.id) return null; - const sorted_players = [props.player, ...props.other_players].sort((a,b) => { + const all_players = [props.player, ...props.other_players]; + + const sorted_players = all_players.sort((a,b) => { return b.score - a.score; }); + const names_and_scores = sorted_players.map(player => { + if (player.score) + return `${player.name} (${player.score})`; + else + return player.name; + }).join(', '); + return (
Players: - {sorted_players.map(player => ( - - {player.name} - {player.score > 0 ? ` (${player.score})` : ""} - {" "} - - ))} + {names_and_scores}
); }); @@ -549,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(', ')}

@@ -586,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(', ')}

@@ -742,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}

@@ -795,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 }; } @@ -824,6 +853,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: [], @@ -837,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 }); } @@ -967,7 +1004,6 @@ class Game extends React.PureComponent { } set_judging_idle(value) { - console.log("Setting judging idle to " + value); this.setState({ judging_idle: value }); @@ -997,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; @@ -1004,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}
  • ); })} @@ -1019,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(', ')}
  • ); })}
); @@ -1057,6 +1130,9 @@ class Game extends React.PureComponent { />; } + if (! state.ready) + return null; + return [