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;
}
} else {
this.$store.commit("session/nomination", [
this.nominate,
this.players.indexOf(to)
]);
const nomination = [this.nominate, this.players.indexOf(to)];
this.$store.commit("session/nomination", { nomination });
this.cancel();
}
},

View File

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

View File

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

View File

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