From 539f3c0b7686c57ea31c32f30a6b64e6f87b512f Mon Sep 17 00:00:00 2001 From: Steffen Date: Sun, 7 Jun 2020 22:22:50 +0200 Subject: [PATCH] add list of players that voted YES --- src/components/Vote.vue | 17 +++++++++++++++++ src/store/socket.js | 25 +++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/components/Vote.vue b/src/components/Vote.vue index e3140b0..a869ecd 100644 --- a/src/components/Vote.vue +++ b/src/components/Vote.vue @@ -17,6 +17,12 @@ {{ Math.ceil(players.length / 2) }} votes required to exile. + +
+ {{ voters.join(", ") || "nobody" }} + voted YES +
+
Start Vote @@ -80,6 +86,17 @@ export default { const indexAdjusted = (index - 1 + players - session.nomination[1]) % players; return indexAdjusted >= session.lockedVote - 1; + }, + voters: function() { + const nomination = this.session.nomination[1]; + const voters = this.session.votes.map((vote, index) => + vote ? this.players[index].name : "" + ); + const reorder = [ + ...voters.slice(nomination + 1, this.players.length), + ...voters.slice(0, nomination + 1) + ]; + return reorder.slice(0, this.session.lockedVote - 1).filter(n => !!n); } }, methods: { diff --git a/src/store/socket.js b/src/store/socket.js index cc9ee9e..3bf6b20 100644 --- a/src/store/socket.js +++ b/src/store/socket.js @@ -106,7 +106,7 @@ class LiveSession { this._handleVote(params); break; case "lock": - this._store.commit("session/lockVote", params); + this._handleLock(params); break; case "bye": this._handleBye(params); @@ -414,7 +414,28 @@ class LiveSession { */ lockVote() { if (this._isSpectator) return; - this._send("lock", this._store.state.session.lockedVote); + const { lockedVote, votes, nomination } = this._store.state.session; + const { players } = this._store.state.players; + const index = (nomination[1] + lockedVote - 1) % players.length; + this._send("lock", [this._store.state.session.lockedVote, votes[index]]); + } + + /** + * Update vote lock and the locked vote, if it differs. + * @param lock + * @param vote + * @private + */ + _handleLock([lock, vote]) { + this._store.commit("session/lockVote", lock); + if (lock > 1) { + const { lockedVote, nomination } = this._store.state.session; + const { players } = this._store.state.players; + const index = (nomination[1] + lockedVote - 1) % players.length; + if (this._store.state.session.votes[index] !== vote) { + this._store.commit("session/vote", [index, vote]); + } + } } }