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

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);
}
}
}