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 (#1724)
* Use custom config for module data instead of including in all * More simple
This commit is contained in:
parent
f478317f19
commit
97c91e040a
2 changed files with 16 additions and 21 deletions
|
|
@ -71,15 +71,18 @@ const companionBaseResources = Object.freeze({
|
||||||
|
|
||||||
export const character = {
|
export const character = {
|
||||||
base: characterBaseResources,
|
base: characterBaseResources,
|
||||||
|
custom: {}, // module stuff goes here
|
||||||
all: { ...characterBaseResources },
|
all: { ...characterBaseResources },
|
||||||
};
|
};
|
||||||
|
|
||||||
export const adversary = {
|
export const adversary = {
|
||||||
base: adversaryBaseResources,
|
base: adversaryBaseResources,
|
||||||
|
custom: {}, // module stuff goes here
|
||||||
all: { ...adversaryBaseResources },
|
all: { ...adversaryBaseResources },
|
||||||
};
|
};
|
||||||
|
|
||||||
export const companion = {
|
export const companion = {
|
||||||
base: companionBaseResources,
|
base: companionBaseResources,
|
||||||
|
custom: {}, // module stuff goes here
|
||||||
all: { ...companionBaseResources },
|
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 */
|
/** @inheritDoc */
|
||||||
_initializeSource(source, options = {}) {
|
_initializeSource(source, options = {}) {
|
||||||
source = super._initializeSource(source, options);
|
source = super._initializeSource(source, options);
|
||||||
|
|
@ -212,24 +206,22 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
|
||||||
this.#resetActors();
|
this.#resetActors();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update config values based on homebrew data */
|
/** Update config values based on homebrew data. Make sure the references don't change */
|
||||||
refreshConfig() {
|
refreshConfig() {
|
||||||
DhHomebrew.originalResources ??= foundry.utils.duplicate(CONFIG.DH.RESOURCE);
|
|
||||||
for (const [actorType, actorData] of Object.entries(this.resources)) {
|
for (const [actorType, actorData] of Object.entries(this.resources)) {
|
||||||
const config = CONFIG.DH.RESOURCE[actorType].all;
|
const config = CONFIG.DH.RESOURCE[actorType];
|
||||||
|
for (const key of Object.keys(config.all)) {
|
||||||
// Remove anything in config that was not in original first
|
delete config.all[key];
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
Object.assign(config.all, {
|
||||||
|
...Object.entries(actorData.resources).reduce((result, [key, value]) => {
|
||||||
|
result[key] = value.toObject();
|
||||||
|
result[key].id = key;
|
||||||
|
return result;
|
||||||
|
}, {}),
|
||||||
|
...config.base,
|
||||||
|
...config.custom,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue