diff --git a/src/components/TownSquare.vue b/src/components/TownSquare.vue index f8dc57d..f01c51d 100644 --- a/src/components/TownSquare.vue +++ b/src/components/TownSquare.vue @@ -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(); } }, diff --git a/src/components/Vote.vue b/src/components/Vote.vue index 6a8873e..1d8a987 100644 --- a/src/components/Vote.vue +++ b/src/components/Vote.vue @@ -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; diff --git a/src/store/modules/session.js b/src/store/modules/session.js index 0d45405..4be6f4e 100644 --- a/src/store/modules/session.js +++ b/src/store/modules/session.js @@ -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; }, /** diff --git a/src/store/socket.js b/src/store/socket.js index 0a4db76..a71e862 100644 --- a/src/store/socket.js +++ b/src/store/socket.js @@ -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 (