From: Carl Worth Date: Sat, 27 Jun 2020 23:32:05 +0000 (-0700) Subject: Implement voting for the "New Game" button X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=commitdiff_plain;h=e41040d89d5aaceabe7f5bb7a12230e2079ffd7e;hp=71a123df898044213dd6703c036d6bbbea7f7f8f Implement voting for the "New Game" button Making this phase advance much like the other phases, and dependent on a majority of the players rather than just letting one player stomp all over things. Beyond this, we still do want to allow players to inspect the state of past rounds, but the UI for that that will have to come later. --- diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx index c216e49..2c70bc3 100644 --- a/empathy/empathy.jsx +++ b/empathy/empathy.jsx @@ -89,6 +89,8 @@ events.addEventListener("game-state", event => { window.game.set_scores(state.scores); + window.game.set_new_game_votes(state.new_game_votes); + window.game.state_ready(); }); @@ -176,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 * *********************************************************/ @@ -807,6 +821,7 @@ class Game extends React.PureComponent { judging_idle: false, end_judging_votes: new Set(), scores: null, + new_game_votes: new Set(), ready: false }; } @@ -856,6 +871,7 @@ class Game extends React.PureComponent { judging_idle: false, end_judging_votes: new Set(), scores: null, + new_game_votes: new Set(), ready: false }); } @@ -1015,6 +1031,24 @@ 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 @@ -1049,10 +1083,22 @@ class Game extends React.PureComponent { })} );