mirror of https://github.com/bra1n/townsquare.git
added support for custom roles in live sessions
This commit is contained in:
parent
615ab168e2
commit
af1717134c
|
@ -24,6 +24,23 @@ const getRolesByEdition = (edition = "tb") => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// base definition for custom roles
|
||||||
|
const imageBase =
|
||||||
|
"https://raw.githubusercontent.com/bra1n/townsquare/main/src/assets/icons/";
|
||||||
|
const customRole = {
|
||||||
|
image: "",
|
||||||
|
edition: "custom",
|
||||||
|
firstNight: 0,
|
||||||
|
firstNightReminder: "",
|
||||||
|
otherNight: 0,
|
||||||
|
otherNightReminder: "",
|
||||||
|
reminders: [],
|
||||||
|
remindersGlobal: [],
|
||||||
|
setup: false,
|
||||||
|
team: "townsfolk",
|
||||||
|
isCustom: true
|
||||||
|
};
|
||||||
|
|
||||||
export default new Vuex.Store({
|
export default new Vuex.Store({
|
||||||
modules: {
|
modules: {
|
||||||
players,
|
players,
|
||||||
|
@ -51,6 +68,34 @@ export default new Vuex.Store({
|
||||||
edition: "tb",
|
edition: "tb",
|
||||||
roles: getRolesByEdition()
|
roles: getRolesByEdition()
|
||||||
},
|
},
|
||||||
|
getters: {
|
||||||
|
/**
|
||||||
|
* Return all custom roles, with default values stripped.
|
||||||
|
* @param roles
|
||||||
|
* @returns {[]}
|
||||||
|
*/
|
||||||
|
customRoles: ({ roles }) => {
|
||||||
|
const customRoles = [];
|
||||||
|
roles.forEach(role => {
|
||||||
|
if (!role.isCustom) {
|
||||||
|
customRoles.push({ id: role.id });
|
||||||
|
} else {
|
||||||
|
const strippedRole = {};
|
||||||
|
for (let prop in role) {
|
||||||
|
const value = role[prop];
|
||||||
|
if (prop === "image" && value.match(new RegExp("^" + imageBase))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (prop !== "isCustom" && value !== customRole[prop]) {
|
||||||
|
strippedRole[prop] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
customRoles.push(strippedRole);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return customRoles;
|
||||||
|
}
|
||||||
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
toggleMenu({ grimoire }) {
|
toggleMenu({ grimoire }) {
|
||||||
grimoire.isMenuOpen = !grimoire.isMenuOpen;
|
grimoire.isMenuOpen = !grimoire.isMenuOpen;
|
||||||
|
@ -105,19 +150,6 @@ export default new Vuex.Store({
|
||||||
* @param roles Array of role IDs or full role definitions
|
* @param roles Array of role IDs or full role definitions
|
||||||
*/
|
*/
|
||||||
setCustomRoles(state, roles) {
|
setCustomRoles(state, roles) {
|
||||||
const imageBase =
|
|
||||||
"https://raw.githubusercontent.com/bra1n/townsquare/main/src/assets/icons/";
|
|
||||||
const customRole = {
|
|
||||||
image: "",
|
|
||||||
edition: "custom",
|
|
||||||
firstNight: 0,
|
|
||||||
firstNightReminder: "",
|
|
||||||
otherNight: 0,
|
|
||||||
otherNightReminder: "",
|
|
||||||
reminders: [],
|
|
||||||
remindersGlobal: [],
|
|
||||||
setup: false
|
|
||||||
};
|
|
||||||
state.roles = new Map(
|
state.roles = new Map(
|
||||||
roles
|
roles
|
||||||
// map existing roles to base definition or pre-populate custom roles to ensure all properties
|
// map existing roles to base definition or pre-populate custom roles to ensure all properties
|
||||||
|
|
|
@ -250,7 +250,7 @@ class LiveSession {
|
||||||
const { edition } = this._store.state;
|
const { edition } = this._store.state;
|
||||||
let roles;
|
let roles;
|
||||||
if (edition === "custom") {
|
if (edition === "custom") {
|
||||||
roles = Array.from(this._store.state.roles.keys());
|
roles = this._store.getters.customRoles;
|
||||||
}
|
}
|
||||||
this._send("edition", {
|
this._send("edition", {
|
||||||
edition,
|
edition,
|
||||||
|
@ -268,10 +268,7 @@ class LiveSession {
|
||||||
if (!this._isSpectator) return;
|
if (!this._isSpectator) return;
|
||||||
this._store.commit("setEdition", edition);
|
this._store.commit("setEdition", edition);
|
||||||
if (roles) {
|
if (roles) {
|
||||||
this._store.commit(
|
this._store.commit("setCustomRoles", roles);
|
||||||
"setCustomRoles",
|
|
||||||
roles.map(id => ({ id }))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue