This commit is contained in:
nicfreeman1209 2021-05-10 19:33:24 +01:00
parent ebb8d23c70
commit b0a710f94e
4 changed files with 50 additions and 34 deletions

View file

@ -290,7 +290,7 @@ export default {
if (this.session.isSpectator) return; if (this.session.isSpectator) return;
const popup = "Do you want to reveal the GRIMOIRE to players?"; const popup = "Do you want to reveal the GRIMOIRE to players?";
if (confirm(popup)) { if (confirm(popup)) {
this.$store.commit("session/revealGrimoire", true); this.$store.commit("session/setRevealedGrimoire", null);
} }
}, },
imageOptIn() { imageOptIn() {

View file

@ -23,6 +23,11 @@
></Player> ></Player>
</ul> </ul>
<div class="st-reveal" v-if="session.revealedGrimoire !== null">
<div class="button" v-if="players.length" @click="applyRevealedGrimoire">
Reveal storyteller grimoire?
</div>
</div>
<div <div
class="bluffs" class="bluffs"
v-if="players.length" v-if="players.length"
@ -247,6 +252,11 @@ export default {
this.cancel(); this.cancel();
} }
}, },
applyRevealedGrimoire() {
console.log("APPLY");
const {func, data} = this.session.revealedGrimoire;
func(data);
},
cancel() { cancel() {
this.move = -1; this.move = -1;
this.swap = -1; this.swap = -1;

View file

@ -26,8 +26,8 @@ const state = () => ({
isVoteInProgress: false, isVoteInProgress: false,
voteHistory: [], voteHistory: [],
isRolesDistributed: false, isRolesDistributed: false,
isGrimoireRevealed: false
isVoteHistoryAllowed: true, isVoteHistoryAllowed: true,
revealedGrimoire: null
}); });
const getters = {}; const getters = {};
@ -51,7 +51,7 @@ const mutations = {
setVoteHistoryAllowed: set("isVoteHistoryAllowed"), setVoteHistoryAllowed: set("isVoteHistoryAllowed"),
claimSeat: set("claimedSeat"), claimSeat: set("claimedSeat"),
distributeRoles: set("isRolesDistributed"), distributeRoles: set("isRolesDistributed"),
revealGrimoire: set("isGrimoireRevealed"), setRevealedGrimoire: set("revealedGrimoire"),
setSessionId(state, sessionId) { setSessionId(state, sessionId) {
state.sessionId = sessionId state.sessionId = sessionId
.toLocaleLowerCase() .toLocaleLowerCase()

View file

@ -246,7 +246,7 @@ class LiveSession {
/** /**
* Publish the current gamestate. * Publish the current gamestate.
* Optional param isLightweight to reduce traffic (=send only player data) * Optional param isLightweight to reduce traffic (=send only player data)
* Optional param isRevealGrimoire to reveal grimoire (=include ALL player roles, reminders & bluffs), overrides isLightweight * Optional param isRevealGrimoire to reveal grimoire (=include ALL player roles, reminders & bluffs)
* @param playerId * @param playerId
* @param isLightweight * @param isLightweight
* @param isRevealGrimoire * @param isRevealGrimoire
@ -254,26 +254,27 @@ class LiveSession {
sendGamestate( sendGamestate(
playerId = "", playerId = "",
isLightweight = false, isLightweight = false,
isRevealGrimoire = false isRevealedGrimoire = false
) { ) {
if (this._isSpectator) return; if (this._isSpectator) return;
if (isLightweight && isRevealedGrimoire) return; // incompatible
this._gamestate = this._store.state.players.players.map(player => ({ this._gamestate = this._store.state.players.players.map(player => ({
name: player.name, name: player.name,
id: player.id, id: player.id,
isDead: player.isDead, isDead: player.isDead,
isVoteless: player.isVoteless, isVoteless: player.isVoteless,
pronouns: player.pronouns, pronouns: player.pronouns,
...(player.role && (player.role.team === "traveler" || isRevealGrimoire) ...(isRevealedGrimoire || (player.role && player.role.team === "traveler")
? { roleId: player.role.id } ? { roleId: player.role.id }
: {}), : { roleId: -1 }),
reminders: isRevealGrimoire reminders: isRevealedGrimoire
? player.reminders.map(reminder => ({ ? player.reminders.map(reminder => ({
name: reminder.name, name: reminder.name,
role: reminder.role role: reminder.role
})) }))
: {} : -1
})); }));
if (isLightweight && !isRevealGrimoire) { if (isLightweight) {
this._sendDirect(playerId, "gs", { this._sendDirect(playerId, "gs", {
gamestate: this._gamestate, gamestate: this._gamestate,
isLightweight isLightweight
@ -285,7 +286,7 @@ class LiveSession {
this._sendDirect(playerId, "gs", { this._sendDirect(playerId, "gs", {
gamestate: this._gamestate, gamestate: this._gamestate,
isLightweight: isLightweight, isLightweight: isLightweight,
isRevealGrimoire: isRevealGrimoire, isRevealedGrimoire: isRevealedGrimoire,
isNight: grimoire.isNight, isNight: grimoire.isNight,
isVoteHistoryAllowed: session.isVoteHistoryAllowed, isVoteHistoryAllowed: session.isVoteHistoryAllowed,
nomination: session.nomination, nomination: session.nomination,
@ -294,6 +295,9 @@ class LiveSession {
isVoteInProgress: session.isVoteInProgress, isVoteInProgress: session.isVoteInProgress,
fabled: fabled.map(f => (f.isCustom ? f : { id: f.id })), fabled: fabled.map(f => (f.isCustom ? f : { id: f.id })),
...(session.nomination ? { votes: session.votes } : {}) ...(session.nomination ? { votes: session.votes } : {})
bluffs: isRevealedGrimoire
? bluffs.map(bluff => ({ roleId: bluff.id }))
: -1
}); });
} }
} }
@ -308,7 +312,7 @@ class LiveSession {
const { const {
gamestate, gamestate,
isLightweight, isLightweight,
isRevealGrimoire, isRevealedGrimoire,
isNight, isNight,
isVoteHistoryAllowed, isVoteHistoryAllowed,
nomination, nomination,
@ -319,14 +323,14 @@ class LiveSession {
fabled, fabled,
bluffs bluffs
} = data; } = data;
if (isRevealGrimoire) { if (isRevealedGrimoire) {
// includes ALL roles, reminders & bluffs // special case: this includes ALL roles, reminders & bluffs
const popup = // would overwrite users notes, so we have to (store and) ask before applying
"Reveal the Storyteller's grimoire? This will overwrite your grimoire."; this._store.commit("session/setRevealedGrimoire", data );
if (!confirm(popup)) { return;
return;
}
} }
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) {
@ -341,19 +345,26 @@ class LiveSession {
// update status for each player // update status for each player
gamestate.forEach((state, x) => { gamestate.forEach((state, x) => {
const player = players[x]; const player = players[x];
const { roleId } = state; // properties we always update
// update relevant properties
["name", "id", "isDead", "isVoteless", "pronouns"].forEach(property => { ["name", "id", "isDead", "isVoteless", "pronouns"].forEach(property => {
const value = state[property]; const value = state[property];
if (player[property] !== value) { if (player[property] !== value) {
this._store.commit("players/update", { player, property, value }); this._store.commit("players/update", { player, property, value });
} }
}); });
// roles are special, because of travelers // roles
if (roleId && player.role.id !== roleId) { const { roleId } = state;
if ((roleId == {} || roleId !== -1) && player.role.team === "traveler") {
// special case for when a player stopped being a traveler
this._store.commit("players/update", {
player,
property: "role",
value: {}
});
} else if (roleId !== -1 && player.role.id !== roleId) {
const role = const role =
this._store.state.roles.get(roleId) || this._store.state.roles.get(roleId) ||
this._store.getters.rolesJSONbyId.get(roleId); this._store.getters.rolesJSONbyId.get(roleId) || {};
if (role) { if (role) {
this._store.commit("players/update", { this._store.commit("players/update", {
player, player,
@ -361,15 +372,9 @@ class LiveSession {
value: role value: role
}); });
} }
} else if (!roleId && player.role.team === "traveler") {
this._store.commit("players/update", {
player,
property: "role",
value: {}
});
} }
// reminder tokens // reminder tokens
if (isRevealGrimoire) { if (state.reminders !== -1) {
this._store.commit("players/update", { this._store.commit("players/update", {
player, player,
property: "reminders", property: "reminders",
@ -378,6 +383,7 @@ class LiveSession {
} }
}); });
if (!isLightweight) { if (!isLightweight) {
// properties we always update
this._store.commit("toggleNight", !!isNight); this._store.commit("toggleNight", !!isNight);
this._store.commit("session/setVoteHistoryAllowed", isVoteHistoryAllowed); this._store.commit("session/setVoteHistoryAllowed", isVoteHistoryAllowed);
this._store.commit("session/nomination", { this._store.commit("session/nomination", {
@ -390,8 +396,8 @@ class LiveSession {
this._store.commit("players/setFabled", { this._store.commit("players/setFabled", {
fabled: fabled.map(f => this._store.state.fabled.get(f.id) || f) fabled: fabled.map(f => this._store.state.fabled.get(f.id) || f)
}); });
if (isRevealGrimoire) { // bluffs
this._store.commit("session/revealGrimoire", true); if (bluffs !== -1) {
bluffs.forEach((bluff, i) => { bluffs.forEach((bluff, i) => {
const role = const role =
this._store.state.roles.get(bluff.roleId) || this._store.state.roles.get(bluff.roleId) ||
@ -888,7 +894,7 @@ export default store => {
session.distributeRoles(); session.distributeRoles();
} }
break; break;
case "session/revealGrimoire": case "session/setRevealedGrimoire":
session.sendGamestate("", false, true); session.sendGamestate("", false, true);
break; break;
case "session/nomination": case "session/nomination":