mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
Fix removing homebrew resources
This commit is contained in:
parent
859263e2fd
commit
279b89bb69
1 changed files with 13 additions and 2 deletions
|
|
@ -192,6 +192,9 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
|
||||||
*/
|
*/
|
||||||
static originalResources = null;
|
static originalResources = null;
|
||||||
|
|
||||||
|
/** Backed up settings used to detect diffs */
|
||||||
|
static originalSettings = null;
|
||||||
|
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
_initializeSource(source, options = {}) {
|
_initializeSource(source, options = {}) {
|
||||||
source = super._initializeSource(source, options);
|
source = super._initializeSource(source, options);
|
||||||
|
|
@ -210,18 +213,26 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
|
||||||
|
|
||||||
this.refreshConfig();
|
this.refreshConfig();
|
||||||
this.#resetActors();
|
this.#resetActors();
|
||||||
|
DhHomebrew.previous
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update config values based on homebrew data */
|
/** Update config values based on homebrew data */
|
||||||
refreshConfig() {
|
refreshConfig() {
|
||||||
DhHomebrew.originalResources ??= foundry.utils.duplicate(CONFIG.DH.RESOURCE);
|
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;
|
||||||
|
|
||||||
|
// 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)) {
|
for (const [resourceKey, resourceData] of Object.entries(actorData.resources)) {
|
||||||
if (resourceKey in DhHomebrew.originalResources[actorType].all) {
|
if (resourceKey in DhHomebrew.originalResources[actorType].all) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CONFIG.DH.RESOURCE[actorType].all[resourceKey] = resourceData.toObject();
|
config[resourceKey] = resourceData.toObject();
|
||||||
CONFIG.DH.RESOURCE[actorType].all[resourceKey].id = resourceKey;
|
config[resourceKey].id = resourceKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue