Added collapsible skill group & volatile storage.

This commit is contained in:
Vlyan
2022-03-12 15:19:30 +01:00
parent ccc81d439f
commit 3b3cb67787
14 changed files with 75 additions and 25 deletions

View File

@@ -31,6 +31,9 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
// Split Items by types
sheetData.data.splitItemsList = this._splitItems(sheetData);
// Store infos for this app (collapsible)
sheetData.data.storeInfos = game.l5r5e.storage.getAppKeys(this.id);
return sheetData;
}

View File

@@ -58,6 +58,12 @@ export const RegisterHandlebars = function () {
return a === b ? new Handlebars.SafeString('checked="checked"') : "";
});
// Concatenation
Handlebars.registerHelper("concat", function (...objects) {
objects.pop(); // remove this function call
return objects.join("");
});
// Add a setter
Handlebars.registerHelper("setVar", function (varName, varValue, options) {
options.data.root[varName] = varValue;

View File

@@ -442,7 +442,12 @@ export class HelpersL5r5e {
html.find(".toggle-on-click").on("click", (event) => {
const elmt = $(event.currentTarget).data("toggle");
const tgt = html.find("." + elmt);
tgt.toggleClass("toggle-active");
tgt.toggleClass("toggle-hidden");
const appId = $(event.currentTarget).closest(".window-app").attr("id");
if (appId) {
game.l5r5e.storage.toggleKey(appId, elmt.toString());
}
});
// Compendium folder link

View File

@@ -42,6 +42,7 @@ import { BaseJournalSheetL5r5e } from "./journals/base-journal-sheet.js";
import { MigrationL5r5e } from "./migration.js";
import { GmToolbox } from "./gm/gm-toolbox.js";
import { GmMonitor } from "./gm/gm-monitor.js";
import { Storage } from "./storage.js";
/* ------------------------------------ */
/* Initialize system */
@@ -91,6 +92,7 @@ Hooks.once("init", async () => {
GmToolbox,
GmMonitor,
HelpDialog,
storage: new Storage(),
sockets: new SocketHandlerL5r5e(),
migrations: MigrationL5r5e,
};

39
system/scripts/storage.js Normal file
View File

@@ -0,0 +1,39 @@
/**
* Volatile Storage - Store things like collapsible state (refresh kill it)
*/
export class Storage {
store = new Map();
/**
* Get list of active keys for this app
* @param {string} app
* @return {string[]}
*/
getAppKeys(app) {
if (!this.store.has(app)) {
return [];
}
return Array.from(this.store.get(app).keys());
}
/**
* Toggle a key for this app
* @param {string} app app name, ex "actor-Zca44Nv7ydMcNN9p"
* @param {string} key Key name, ex "toggle-skill-category-martial"
*/
toggleKey(app, key) {
if (this.store.has(app)) {
const appMap = this.store.get(app);
if (appMap.has(key)) {
appMap.delete(key);
} else {
appMap.set(key, true);
}
} else {
// Create app map
const appMap = new Map();
appMap.set(key, true);
this.store.set(app, appMap);
}
}
}