sync votes along with gamestate (fixes #35)

This commit is contained in:
Steffen 2020-06-30 10:16:56 +02:00
parent 85909778ee
commit b986715ee5
No known key found for this signature in database
GPG Key ID: 764D74E98267DFC6
4 changed files with 19 additions and 15 deletions

View File

@ -154,10 +154,8 @@ export default {
this.nominate = from; this.nominate = from;
} }
} else { } else {
this.$store.commit("session/nomination", [ const nomination = [this.nominate, this.players.indexOf(to)];
this.nominate, this.$store.commit("session/nomination", { nomination });
this.players.indexOf(to)
]);
this.cancel(); this.cancel();
} }
}, },

View File

@ -138,7 +138,7 @@ export default {
}, },
finish() { finish() {
clearInterval(this.voteTimer); clearInterval(this.voteTimer);
this.$store.commit("session/nomination", false); this.$store.commit("session/nomination");
}, },
vote(vote) { vote(vote) {
if (!this.canVote) return false; if (!this.canVote) return false;

View File

@ -32,9 +32,10 @@ const mutations = {
setPlayerCount: set("playerCount"), setPlayerCount: set("playerCount"),
setVotingSpeed: set("votingSpeed"), setVotingSpeed: set("votingSpeed"),
claimSeat: set("claimedSeat"), claimSeat: set("claimedSeat"),
nomination(state, nomination) { nomination(state, { nomination, votes, votingSpeed } = {}) {
state.nomination = nomination; state.nomination = nomination || false;
state.votes = []; state.votes = votes || [];
state.votingSpeed = votingSpeed || state.votingSpeed;
state.lockedVote = 0; state.lockedVote = 0;
}, },
/** /**

View File

@ -105,7 +105,7 @@ class LiveSession {
this._handlePing(params); this._handlePing(params);
break; break;
case "nomination": case "nomination":
this._store.commit("session/nomination", params); this._store.commit("session/nomination", { nomination: params });
break; break;
case "votingSpeed": case "votingSpeed":
this._store.commit("session/setVotingSpeed", params); this._store.commit("session/setVotingSpeed", params);
@ -167,11 +167,13 @@ class LiveSession {
? { roleId: player.role.id } ? { roleId: player.role.id }
: {}) : {})
})); }));
const { session } = this._store.state;
this.sendEdition(); this.sendEdition();
this._send("gs", { this._send("gs", {
gamestate: this._gamestate, gamestate: this._gamestate,
nomination: this._store.state.session.nomination, nomination: session.nomination,
votingSpeed: this._store.state.session.votingSpeed votingSpeed: session.votingSpeed,
...(session.nomination ? { votes: session.votes } : {})
}); });
} }
@ -182,9 +184,12 @@ class LiveSession {
*/ */
_updateGamestate(data) { _updateGamestate(data) {
if (!this._isSpectator) return; if (!this._isSpectator) return;
const { gamestate, nomination, votingSpeed } = data; const { gamestate, nomination, votingSpeed, votes } = data;
this._store.commit("session/nomination", nomination); this._store.commit("session/nomination", {
this._store.commit("session/setVotingSpeed", votingSpeed); nomination,
votes,
votingSpeed
});
const players = this._store.state.players.players; const players = this._store.state.players.players;
// adjust number of players // adjust number of players
if (players.length < gamestate.length) { if (players.length < gamestate.length) {
@ -411,7 +416,7 @@ class LiveSession {
* This also syncs the voting speed to the players. * This also syncs the voting speed to the players.
* @param nomination [nominator, nominee] * @param nomination [nominator, nominee]
*/ */
nomination(nomination) { nomination({ nomination } = {}) {
if (this._isSpectator) return; if (this._isSpectator) return;
const players = this._store.state.players.players; const players = this._store.state.players.players;
if ( if (