From 97c91e040a0ada6e1b3fa1b8100945e7d6543b83 Mon Sep 17 00:00:00 2001 From: Carlos Fernandez Date: Wed, 11 Mar 2026 05:56:14 -0400 Subject: [PATCH] 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 --- module/config/resourceConfig.mjs | 3 +++ module/data/settings/Homebrew.mjs | 34 ++++++++++++------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/module/config/resourceConfig.mjs b/module/config/resourceConfig.mjs index 65f9584a..f7d56b44 100644 --- a/module/config/resourceConfig.mjs +++ b/module/config/resourceConfig.mjs @@ -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 }, }; diff --git a/module/data/settings/Homebrew.mjs b/module/data/settings/Homebrew.mjs index 95dabb89..c93bc417 100644 --- a/module/data/settings/Homebrew.mjs +++ b/module/data/settings/Homebrew.mjs @@ -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.base, + ...config.custom, + }); } }