townsquare/src/store/index.js

119 lines
3.0 KiB
JavaScript
Raw Normal View History

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,
zoom: 0,
2020-05-03 21:05:17 +00:00
background: "",
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;
},
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;
}
},
setRoles(state, roles) {
state.roles = new Map(
rolesJSON
.filter(r => roles.includes(r.id))
.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;
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
});