mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
Use custom config for module data instead of including in all
This commit is contained in:
parent
f478317f19
commit
1997abafac
2 changed files with 16 additions and 21 deletions
|
|
@ -71,15 +71,18 @@ const companionBaseResources = Object.freeze({
|
|||
|
||||
export const character = {
|
||||
base: characterBaseResources,
|
||||
custom: {}, // module stuff goes here
|
||||
all: { ...characterBaseResources },
|
||||
};
|
||||
|
||||
export const adversary = {
|
||||
base: adversaryBaseResources,
|
||||
custom: {}, // module stuff goes here
|
||||
all: { ...adversaryBaseResources },
|
||||
};
|
||||
|
||||
export const companion = {
|
||||
base: companionBaseResources,
|
||||
custom: {}, // module stuff goes here
|
||||
all: { ...companionBaseResources },
|
||||
};
|
||||
|
|
|
|||
|
|
@ -186,12 +186,6 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Backed up configured resources stored to prevent overwriting module settings.
|
||||
* As of V13, setting objects are not preserved between reprepares.
|
||||
*/
|
||||
static originalResources = null;
|
||||
|
||||
/** @inheritDoc */
|
||||
_initializeSource(source, options = {}) {
|
||||
source = super._initializeSource(source, options);
|
||||
|
|
@ -212,24 +206,22 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
|
|||
this.#resetActors();
|
||||
}
|
||||
|
||||
/** Update config values based on homebrew data */
|
||||
/** Update config values based on homebrew data. Make sure the references don't change */
|
||||
refreshConfig() {
|
||||
DhHomebrew.originalResources ??= foundry.utils.duplicate(CONFIG.DH.RESOURCE);
|
||||
for (const [actorType, actorData] of Object.entries(this.resources)) {
|
||||
const config = CONFIG.DH.RESOURCE[actorType].all;
|
||||
|
||||
// Remove anything in config that was not in original first
|
||||
const removal = Object.keys(config).filter(k => !(k in DhHomebrew.originalResources[actorType].all));
|
||||
for (const key of removal) delete config[key];
|
||||
|
||||
// Add homebrew settings
|
||||
for (const [resourceKey, resourceData] of Object.entries(actorData.resources)) {
|
||||
if (resourceKey in DhHomebrew.originalResources[actorType].all) {
|
||||
continue;
|
||||
}
|
||||
config[resourceKey] = resourceData.toObject();
|
||||
config[resourceKey].id = resourceKey;
|
||||
const config = CONFIG.DH.RESOURCE[actorType];
|
||||
for (const key of Object.keys(config.all)) {
|
||||
delete config.all[key];
|
||||
}
|
||||
Object.assign(config.all, {
|
||||
...Object.entries(actorData.resources).reduce((result, [key, value]) => {
|
||||
result[key] = value.toObject();
|
||||
result[key].id = key;
|
||||
return result;
|
||||
}, {}),
|
||||
...CONFIG.DH.RESOURCE[actorType].base,
|
||||
...CONFIG.DH.RESOURCE[actorType].custom,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue