2020-05-02 19:11:20 +00:00
|
|
|
import Vue from "vue";
|
|
|
|
import Vuex from "vuex";
|
2020-05-02 19:46:51 +00:00
|
|
|
import persistence from "./persistence";
|
2020-05-30 20:47:42 +00:00
|
|
|
import socket from "./socket";
|
2020-05-02 20:23:05 +00:00
|
|
|
import players from "./modules/players";
|
2020-05-30 20:47:42 +00:00
|
|
|
import session from "./modules/session";
|
2020-05-02 19:11:20 +00:00
|
|
|
import editionJSON from "../editions.json";
|
|
|
|
import rolesJSON from "../roles.json";
|
|
|
|
|
|
|
|
Vue.use(Vuex);
|
|
|
|
|
2020-06-24 12:32:08 +00:00
|
|
|
const rolesJSONbyId = new Map(rolesJSON.map(role => [role.id, role]));
|
|
|
|
|
2020-05-02 19:11:20 +00:00
|
|
|
const getRolesByEdition = (edition = "tb") => {
|
2020-05-02 19:46:51 +00:00
|
|
|
const selectedEdition =
|
|
|
|
editionJSON.find(({ id }) => id === edition) || editionJSON[0];
|
2020-05-02 19:11:20 +00:00
|
|
|
return new Map(
|
|
|
|
rolesJSON
|
|
|
|
.filter(
|
|
|
|
r => r.edition === edition || selectedEdition.roles.includes(r.id)
|
|
|
|
)
|
|
|
|
.sort((a, b) => b.team.localeCompare(a.team))
|
|
|
|
.map(role => [role.id, role])
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default new Vuex.Store({
|
2020-05-02 20:23:05 +00:00
|
|
|
modules: {
|
2020-05-30 20:47:42 +00:00
|
|
|
players,
|
|
|
|
session
|
2020-05-02 20:23:05 +00:00
|
|
|
},
|
2020-05-02 19:11:20 +00:00
|
|
|
state: {
|
|
|
|
grimoire: {
|
|
|
|
isNightOrder: true,
|
|
|
|
isPublic: true,
|
2020-05-02 19:33:44 +00:00
|
|
|
isMenuOpen: false,
|
2020-05-02 19:11:20 +00:00
|
|
|
isScreenshot: false,
|
|
|
|
isScreenshotSuccess: false,
|
2020-06-08 10:35:13 +00:00
|
|
|
zoom: 0,
|
2020-05-03 21:05:17 +00:00
|
|
|
background: "",
|
2020-05-12 18:48:00 +00:00
|
|
|
bluffs: []
|
2020-05-12 17:59:48 +00:00
|
|
|
},
|
2020-05-02 19:11:20 +00:00
|
|
|
modals: {
|
2020-05-27 19:42:09 +00:00
|
|
|
reference: false,
|
2020-05-02 19:11:20 +00:00
|
|
|
edition: false,
|
2020-05-03 21:05:17 +00:00
|
|
|
roles: false,
|
|
|
|
role: false,
|
|
|
|
reminder: false
|
2020-05-02 19:11:20 +00:00
|
|
|
},
|
|
|
|
edition: "tb",
|
2020-05-02 20:23:05 +00:00
|
|
|
roles: getRolesByEdition()
|
2020-05-02 19:11:20 +00:00
|
|
|
},
|
|
|
|
mutations: {
|
2020-05-02 19:33:44 +00:00
|
|
|
toggleMenu({ grimoire }) {
|
|
|
|
grimoire.isMenuOpen = !grimoire.isMenuOpen;
|
|
|
|
},
|
2020-05-05 18:13:30 +00:00
|
|
|
toggleGrimoire({ grimoire }, isPublic) {
|
|
|
|
if (isPublic === true || isPublic === false) {
|
|
|
|
grimoire.isPublic = isPublic;
|
|
|
|
} else {
|
|
|
|
grimoire.isPublic = !grimoire.isPublic;
|
|
|
|
}
|
|
|
|
document.title = `Blood on the Clocktower ${
|
|
|
|
grimoire.isPublic ? "Town Square" : "Grimoire"
|
|
|
|
}`;
|
2020-05-02 19:11:20 +00:00
|
|
|
},
|
|
|
|
toggleNightOrder({ grimoire }) {
|
|
|
|
grimoire.isNightOrder = !grimoire.isNightOrder;
|
|
|
|
},
|
2020-06-07 19:51:19 +00:00
|
|
|
setZoom({ grimoire }, zoom) {
|
|
|
|
grimoire.zoom = zoom;
|
2020-05-02 19:11:20 +00:00
|
|
|
},
|
|
|
|
setBackground({ grimoire }, background) {
|
|
|
|
grimoire.background = background;
|
|
|
|
},
|
2020-05-12 17:59:48 +00:00
|
|
|
setBluff({ grimoire }, { index, role } = {}) {
|
|
|
|
if (index !== undefined) {
|
|
|
|
grimoire.bluffs.splice(index, 1, role);
|
|
|
|
} else {
|
|
|
|
grimoire.bluffs = [];
|
|
|
|
}
|
2020-05-03 21:05:17 +00:00
|
|
|
},
|
2020-05-02 19:11:20 +00:00
|
|
|
toggleModal({ modals }, name) {
|
2020-06-04 19:56:07 +00:00
|
|
|
if (name) {
|
|
|
|
modals[name] = !modals[name];
|
|
|
|
}
|
|
|
|
for (let modal in modals) {
|
|
|
|
if (modal === name) continue;
|
|
|
|
modals[modal] = false;
|
2020-05-27 19:42:09 +00:00
|
|
|
}
|
2020-05-02 19:11:20 +00:00
|
|
|
},
|
|
|
|
updateScreenshot({ grimoire }, status) {
|
|
|
|
if (status !== true && status !== false) {
|
|
|
|
grimoire.isScreenshotSuccess = false;
|
|
|
|
grimoire.isScreenshot = true;
|
|
|
|
} else {
|
|
|
|
grimoire.isScreenshotSuccess = status;
|
|
|
|
grimoire.isScreenshot = false;
|
|
|
|
}
|
|
|
|
},
|
2020-06-24 12:33:31 +00:00
|
|
|
setRoles(state, roleIds) {
|
2020-05-15 21:36:45 +00:00
|
|
|
state.roles = new Map(
|
|
|
|
rolesJSON
|
2020-06-24 12:33:31 +00:00
|
|
|
.filter(r => roleIds.includes(r.id))
|
2020-05-15 21:36:45 +00:00
|
|
|
.sort((a, b) => b.team.localeCompare(a.team))
|
|
|
|
.map(role => [role.id, role])
|
|
|
|
);
|
|
|
|
},
|
2020-05-02 19:11:20 +00:00
|
|
|
setEdition(state, edition) {
|
|
|
|
state.edition = edition;
|
|
|
|
state.modals.edition = false;
|
2020-05-15 21:36:45 +00:00
|
|
|
if (edition !== "custom") {
|
|
|
|
state.roles = getRolesByEdition(edition);
|
|
|
|
}
|
2020-05-02 19:11:20 +00:00
|
|
|
}
|
2020-05-02 19:46:51 +00:00
|
|
|
},
|
2020-05-30 20:47:42 +00:00
|
|
|
plugins: [persistence, socket]
|
2020-05-02 19:11:20 +00:00
|
|
|
});
|