diff --git a/lang/en.json b/lang/en.json index 3a1340e0..9f16828e 100755 --- a/lang/en.json +++ b/lang/en.json @@ -2887,7 +2887,9 @@ "iconName": "Icon Name", "iconNameHint": "Icons are from fontawesome", "bagName": "Bag Name", - "chestName": "Chest Name" + "chestName": "Chest Name", + "denomination": "Denomination", + "initialAmount": "Starting Amount" }, "domains": { "domainsTitle": "Base Domains", diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index aed27650..0cae662f 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -64,7 +64,18 @@ export default class DhCharacter extends DhCreature { core: new fields.BooleanField({ initial: false }) }) ), - gold: new GoldField(), + 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 a5f6f379..4a3156e5 100644 --- a/module/data/fields/actorField.mjs +++ b/module/data/fields/actorField.mjs @@ -116,13 +116,28 @@ 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; + } + + getInitialValue(data) { + if (this._initialCallback) { + try { + return this._initialCallback(data); + } catch { + /* settings not yet available */ + } + } + return super.getInitialValue(data); } } diff --git a/module/data/settings/Homebrew.mjs b/module/data/settings/Homebrew.mjs index 31247458..a0761e20 100644 --- a/module/data/settings/Homebrew.mjs +++ b/module/data/settings/Homebrew.mjs @@ -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; } diff --git a/styles/less/ui/settings/settings.less b/styles/less/ui/settings/settings.less index 35c48480..f2ab99e7 100644 --- a/styles/less/ui/settings/settings.less +++ b/styles/less/ui/settings/settings.less @@ -201,6 +201,23 @@ } } + .currency-rows { + display: grid; + grid-template-columns: auto 1fr 1fr auto; + gap: 4px; + align-items: center; + width: 100%; + + .currency-header-label { + text-align: center; + font-size: var(--font-size-14); + } + + input[type='checkbox'] { + justify-self: center; + } + } + .settings-hint { width: 100%; display: flex; diff --git a/templates/settings/homebrew-settings/settings.hbs b/templates/settings/homebrew-settings/settings.hbs index 4b6e7d85..1fd449a9 100644 --- a/templates/settings/homebrew-settings/settings.hbs +++ b/templates/settings/homebrew-settings/settings.hbs @@ -42,29 +42,35 @@