[Feature] Configurable starting gold amounts in Homebrew settings

Added `initialAmount` field to each currency type (coins, handfuls, bags, chests)
in the Homebrew settings schema. Defaults match book values (0, 1, 0, 0).

- Homebrew.mjs: added `initialAmount` NumberField per currency; `_initializeSource`
  coerces empty submissions to 0; `refreshConfig()` syncs values to
  `CONFIG.DH.RESOURCE.character.initialCurrency`
- resourceConfig.mjs: added mutable `initialCurrency` object on `character` export
- actorField.mjs: added `CharacterGoldField` subclass that reads initial values
  from config at actor creation time
- character.mjs: switched from `GoldField` to `CharacterGoldField`
- settings.hbs: restructured currency section to CSS Grid with column headers
  ("Quantity Name" / "Starting Amount") instead of per-field inline labels
- settings.less: added `.currency-rows` grid styles
- en.json: added `quantityName` and `initialAmount` localisation keys
This commit is contained in:
Iohan Trézze 2026-06-03 23:56:25 -03:00
parent a4428fd5be
commit d549a609e3
7 changed files with 70 additions and 19 deletions

View file

@ -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, GoldField } from '../fields/actorField.mjs';
import { attributeField, stressDamageReductionRule, bonusField, CharacterGoldField } 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,7 @@ export default class DhCharacter extends DhCreature {
core: new fields.BooleanField({ initial: false })
})
),
gold: new GoldField(),
gold: new CharacterGoldField(),
scars: new fields.NumberField({ initial: 0, integer: true, label: 'DAGGERHEART.GENERAL.scars' }),
biography: new fields.SchemaField({
background: new fields.HTMLField(),

View file

@ -126,4 +126,15 @@ class GoldField extends fields.SchemaField {
}
}
export { attributeField, ResourcesField, GoldField, stressDamageReductionRule, bonusField };
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];
}
return base;
}
}
export { attributeField, ResourcesField, GoldField, CharacterGoldField, stressDamageReductionRule, bonusField };

View file

@ -2,7 +2,7 @@ import { defaultRestOptions } from '../../config/generalConfig.mjs';
import { resetAndRerenderActors } from '../../helpers/utils.mjs';
import { ActionsField } from '../fields/actionField.mjs';
const currencyField = (initial, label, icon) =>
const currencyField = (initial, label, icon, initialAmount = 0) =>
new foundry.data.fields.SchemaField({
enabled: new foundry.data.fields.BooleanField({ required: true, initial: true }),
label: new foundry.data.fields.StringField({
@ -10,7 +10,14 @@ const currencyField = (initial, label, icon) =>
initial,
label
}),
icon: new foundry.data.fields.StringField({ required: true, nullable: false, blank: true, initial: icon })
icon: new foundry.data.fields.StringField({ required: true, nullable: false, blank: true, initial: icon }),
initialAmount: new foundry.data.fields.NumberField({
required: true,
integer: true,
min: 0,
initial: initialAmount,
label: 'DAGGERHEART.SETTINGS.Homebrew.currency.initialAmount'
})
});
const restMoveField = () =>
@ -108,7 +115,8 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
handfuls: currencyField(
'Handfuls',
'DAGGERHEART.SETTINGS.Homebrew.currency.handfulName',
'fa-solid fa-coins'
'fa-solid fa-coins',
1
),
bags: currencyField('Bags', 'DAGGERHEART.SETTINGS.Homebrew.currency.bagName', 'fa-solid fa-sack'),
chests: currencyField(
@ -193,6 +201,7 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
for (const type of ['coins', 'handfuls', 'bags', 'chests']) {
const initial = this.schema.fields.currency.fields[type].getInitialValue();
source.currency[type] = foundry.utils.mergeObject(initial, source.currency[type], { inplace: false });
source.currency[type].initialAmount ??= 0;
}
return source;
}
@ -230,6 +239,11 @@ 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;
}
}
}