From 83b25f4771cfaffb68a9f4cca0dbfa5ecb884477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iohan=20Tr=C3=A9zze?= Date: Fri, 5 Jun 2026 23:27:37 -0300 Subject: [PATCH] [Fix] Address PR review feedback for starting gold feature - Disabled denominations now receive 0 at character creation - Replace CharacterGoldField subclass with GoldField options callback; initial value logic now lives in character.mjs - Use formInput instead of plain text inputs for denomination labels - Rename "Quantity Name" column header to "Denomination" - Remove initialCurrency from resourceConfig and currency sync from refreshConfig (no longer needed) --- lang/en.json | 2 +- module/config/resourceConfig.mjs | 1 - module/data/actor/character.mjs | 15 ++++++-- module/data/fields/actorField.mjs | 36 ++++++++++--------- module/data/settings/Homebrew.mjs | 5 --- .../settings/homebrew-settings/settings.hbs | 10 +++--- 6 files changed, 39 insertions(+), 30 deletions(-) diff --git a/lang/en.json b/lang/en.json index a7713311..9f16828e 100755 --- a/lang/en.json +++ b/lang/en.json @@ -2888,7 +2888,7 @@ "iconNameHint": "Icons are from fontawesome", "bagName": "Bag Name", "chestName": "Chest Name", - "quantityName": "Quantity Name", + "denomination": "Denomination", "initialAmount": "Starting Amount" }, "domains": { diff --git a/module/config/resourceConfig.mjs b/module/config/resourceConfig.mjs index f03131ff..d33d7ab3 100644 --- a/module/config/resourceConfig.mjs +++ b/module/config/resourceConfig.mjs @@ -65,7 +65,6 @@ const companionBaseResources = Object.freeze({ export const character = { base: characterBaseResources, - initialCurrency: { coins: 0, handfuls: 1, bags: 0, chests: 0 }, custom: {}, // module stuff goes here all: { ...characterBaseResources } }; diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index 0b235ce2..0cae662f 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -3,7 +3,7 @@ import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs'; import DhLevelData from '../levelData.mjs'; import { commonActorRules } from './base.mjs'; import DhCreature from './creature.mjs'; -import { attributeField, stressDamageReductionRule, bonusField, CharacterGoldField } from '../fields/actorField.mjs'; +import { attributeField, stressDamageReductionRule, bonusField, GoldField } from '../fields/actorField.mjs'; import { ActionField } from '../fields/actionField.mjs'; import DHCharacterSettings from '../../applications/sheets-configs/character-settings.mjs'; import { getArmorSources } from '../../helpers/utils.mjs'; @@ -64,7 +64,18 @@ export default class DhCharacter extends DhCreature { core: new fields.BooleanField({ initial: false }) }) ), - gold: new CharacterGoldField(), + gold: new GoldField({ + initial: () => { + const homebrew = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew); + const { coins, handfuls, bags, chests } = homebrew.currency; + return { + coins: coins.enabled ? coins.initialAmount : 0, + handfuls: handfuls.enabled ? handfuls.initialAmount : 0, + bags: bags.enabled ? bags.initialAmount : 0, + chests: chests.enabled ? chests.initialAmount : 0 + }; + } + }), scars: new fields.NumberField({ initial: 0, integer: true, label: 'DAGGERHEART.GENERAL.scars' }), biography: new fields.SchemaField({ background: new fields.HTMLField(), diff --git a/module/data/fields/actorField.mjs b/module/data/fields/actorField.mjs index d634b3fd..4a3156e5 100644 --- a/module/data/fields/actorField.mjs +++ b/module/data/fields/actorField.mjs @@ -116,25 +116,29 @@ class ResourcesField extends fields.TypedObjectField { } class GoldField extends fields.SchemaField { - constructor() { - super({ - coins: new fields.NumberField({ initial: 0, integer: true }), - handfuls: new fields.NumberField({ initial: 1, integer: true }), - bags: new fields.NumberField({ initial: 0, integer: true }), - chests: new fields.NumberField({ initial: 0, integer: true }) - }); + constructor({ initial, ...options } = {}) { + super( + { + coins: new fields.NumberField({ initial: 0, integer: true }), + handfuls: new fields.NumberField({ initial: 1, integer: true }), + bags: new fields.NumberField({ initial: 0, integer: true }), + chests: new fields.NumberField({ initial: 0, integer: true }) + }, + options + ); + this._initialCallback = initial; } -} -class CharacterGoldField extends GoldField { - getInitialValue(options) { - const base = super.getInitialValue(options); - const initialCurrency = CONFIG.DH.RESOURCE.character.initialCurrency; - for (const type of ['coins', 'handfuls', 'bags', 'chests']) { - base[type] = initialCurrency[type]; + getInitialValue(data) { + if (this._initialCallback) { + try { + return this._initialCallback(data); + } catch { + /* settings not yet available */ + } } - return base; + return super.getInitialValue(data); } } -export { attributeField, ResourcesField, GoldField, CharacterGoldField, stressDamageReductionRule, bonusField }; +export { attributeField, ResourcesField, GoldField, stressDamageReductionRule, bonusField }; diff --git a/module/data/settings/Homebrew.mjs b/module/data/settings/Homebrew.mjs index af4a871c..a0761e20 100644 --- a/module/data/settings/Homebrew.mjs +++ b/module/data/settings/Homebrew.mjs @@ -239,11 +239,6 @@ export default class DhHomebrew extends foundry.abstract.DataModel { ...config.base }); } - - const currencyInitial = CONFIG.DH.RESOURCE.character.initialCurrency; - for (const type of ['coins', 'handfuls', 'bags', 'chests']) { - currencyInitial[type] = this.currency[type].initialAmount; - } } } diff --git a/templates/settings/homebrew-settings/settings.hbs b/templates/settings/homebrew-settings/settings.hbs index 7766c934..1fd449a9 100644 --- a/templates/settings/homebrew-settings/settings.hbs +++ b/templates/settings/homebrew-settings/settings.hbs @@ -49,27 +49,27 @@
- {{localize "DAGGERHEART.SETTINGS.Homebrew.currency.quantityName"}} + {{localize "DAGGERHEART.SETTINGS.Homebrew.currency.denomination"}} {{localize "DAGGERHEART.SETTINGS.Homebrew.currency.initialAmount"}} - + {{formInput settingFields.schema.fields.currency.fields.coins.fields.label value=settingFields._source.currency.coins.label name="currency.coins.label"}} - + {{formInput settingFields.schema.fields.currency.fields.handfuls.fields.label value=settingFields._source.currency.handfuls.label name="currency.handfuls.label"}} - + {{formInput settingFields.schema.fields.currency.fields.bags.fields.label value=settingFields._source.currency.bags.label name="currency.bags.label"}} - + {{formInput settingFields.schema.fields.currency.fields.chests.fields.label value=settingFields._source.currency.chests.label name="currency.chests.label"}}