socket part of toggle recordVoteHistory

analogous to isNight
This commit is contained in:
nicfreeman1209 2021-04-18 17:26:24 +01:00
parent 44a0297be7
commit 230507a67f
5 changed files with 32 additions and 9 deletions

View File

@ -343,9 +343,6 @@ export default {
this.$store.dispatch("players/clearRoles");
}
},
toggleRecordVoteHistory() {
this.$store.commit("session/toggleRecordVoteHistory");
},
clearVoteHistory() {
this.$store.commit("session/clearVoteHistory");
},
@ -355,6 +352,7 @@ export default {
"toggleImageOptIn",
"toggleMuted",
"toggleNight",
"toggleRecordVoteHistory",
"toggleNightOrder",
"setZoom",
"toggleModal"

View File

@ -220,9 +220,7 @@ export default {
},
finish() {
clearInterval(this.voteTimer);
if (this.session.recordVoteHistory) {
this.$store.commit("session/addHistory", this.players);
}
this.$store.commit("session/addHistory", this.players);
this.$store.commit("session/nomination");
},
vote(vote) {

View File

@ -78,6 +78,7 @@ export default new Vuex.Store({
state: {
grimoire: {
isNight: false,
recordVoteHistory: true,
isNightOrder: true,
isPublic: true,
isMenuOpen: false,
@ -147,6 +148,13 @@ export default new Vuex.Store({
toggleNight: toggle("isNight"),
toggleGrimoire: toggle("isPublic"),
toggleImageOptIn: toggle("isImageOptIn"),
toggleRecordVoteHistory(state, param) {
if (param === true || param === false) {
state.session.recordVoteHistory = param;
} else {
state.session.recordVoteHistory = !state.session.recordVoteHistory;
}
},
toggleModal({ modals }, name) {
if (name) {
modals[name] = !modals[name];

View File

@ -71,6 +71,7 @@ const mutations = {
* @param players
*/
addHistory(state, players) {
if (!state.recordVoteHistory) return;
if (!state.nomination || state.lockedVote <= players.length) return;
const isBanishment = players[state.nomination[1]].role.team === "traveler";
state.voteHistory.push({
@ -89,9 +90,6 @@ const mutations = {
clearVoteHistory(state) {
state.voteHistory = [];
},
toggleRecordVoteHistory(state) {
state.recordVoteHistory = !state.recordVoteHistory;
},
/**
* Store a vote with and without syncing it to the live session.
* This is necessary in order to prevent infinite voting loops.

View File

@ -172,6 +172,10 @@ class LiveSession {
if (!this._isSpectator) return;
this._store.commit("toggleNight", params);
break;
case "recordVoteHistory":
if (!this._isSpectator) return;
this._store.commit("toggleRecordVoteHistory", params);
break;
case "votingSpeed":
if (!this._isSpectator) return;
this._store.commit("session/setVotingSpeed", params);
@ -268,6 +272,7 @@ class LiveSession {
this._sendDirect(playerId, "gs", {
gamestate: this._gamestate,
isNight: grimoire.isNight,
recordVoteHistory: session.recordVoteHistory,
nomination: session.nomination,
votingSpeed: session.votingSpeed,
lockedVote: session.lockedVote,
@ -289,6 +294,7 @@ class LiveSession {
gamestate,
isLightweight,
isNight,
recordVoteHistory,
nomination,
votingSpeed,
votes,
@ -340,6 +346,7 @@ class LiveSession {
});
if (!isLightweight) {
this._store.commit("toggleNight", !!isNight);
this._store.commit("toggleRecordVoteHistory", recordVoteHistory);
this._store.commit("session/nomination", {
nomination,
votes,
@ -686,6 +693,17 @@ class LiveSession {
this._send("isNight", this._store.state.grimoire.isNight);
}
/**
* Send the recordVoteHistory state. ST only
*/
setRecordVoteHistory() {
if (this._isSpectator) return;
this._send(
"recordVoteHistory",
this._store.state.session.recordVoteHistory
);
}
/**
* Send the voting speed. ST only
* @param votingSpeed voting speed in seconds, minimum 1
@ -843,6 +861,9 @@ export default store => {
case "toggleNight":
session.setIsNight();
break;
case "toggleRecordVoteHistory":
session.setRecordVoteHistory();
break;
case "setEdition":
session.sendEdition();
break;