Changed so that icons don't have to have an icon

This commit is contained in:
WBHarry 2025-12-13 23:01:58 +01:00
parent b721b91a32
commit df4041b0d4
2 changed files with 31 additions and 19 deletions

View file

@ -122,24 +122,24 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
const icon = await foundry.applications.api.DialogV2.input({ const icon = await foundry.applications.api.DialogV2.input({
classes: ['daggerheart', 'dh-style', 'change-currency-icon'], classes: ['daggerheart', 'dh-style', 'change-currency-icon'],
content: await foundry.applications.handlebars.renderTemplate( content: await foundry.applications.handlebars.renderTemplate(
"systems/daggerheart/templates/settings/homebrew-settings/change-currency-icon.hbs", 'systems/daggerheart/templates/settings/homebrew-settings/change-currency-icon.hbs',
{ currentIcon } { currentIcon }
), ),
window: { window: {
title: game.i18n.localize("DAGGERHEART.SETTINGS.Homebrew.currency.changeIcon"), title: game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.currency.changeIcon'),
icon: "fa-solid fa-coins" icon: 'fa-solid fa-coins'
}, },
render: (_, dialog) => { render: (_, dialog) => {
const icon = dialog.element.querySelector(".displayed-icon i"); const icon = dialog.element.querySelector('.displayed-icon i');
const input = dialog.element.querySelector("input"); const input = dialog.element.querySelector('input');
const reset = dialog.element.querySelector("button[data-action=reset]"); const reset = dialog.element.querySelector('button[data-action=reset]');
input.addEventListener("input", () => { input.addEventListener('input', () => {
icon.classList.value = input.value; icon.classList.value = input.value;
}); });
reset.addEventListener("click", () => { reset.addEventListener('click', () => {
const currencyField = DhHomebrew.schema.fields.currency.fields[type]; const currencyField = DhHomebrew.schema.fields.currency.fields[type];
const initial = currencyField.fields.icon.getInitialValue(); const initial = currencyField.fields.icon.getInitialValue();
input.value = icon.classList.value = initial; input.value = icon.classList.value = initial;
}); });
}, },
ok: { ok: {
@ -147,10 +147,10 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
} }
}); });
if (icon) { if (icon !== null) {
await this.settings.updateSource({ await this.settings.updateSource({
[`currency.${type}.icon`]: icon, [`currency.${type}.icon`]: icon
}); });
this.render(); this.render();
} }
} }

View file

@ -9,7 +9,7 @@ const currencyField = (initial, label, icon) =>
initial, initial,
label label
}), }),
icon: new foundry.data.fields.StringField({ required: true, nullable: false, blank: false, initial: icon }), icon: new foundry.data.fields.StringField({ required: true, nullable: false, blank: true, initial: icon })
}); });
export default class DhHomebrew extends foundry.abstract.DataModel { export default class DhHomebrew extends foundry.abstract.DataModel {
@ -46,10 +46,22 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
initial: 'Gold', initial: 'Gold',
label: 'DAGGERHEART.SETTINGS.Homebrew.currency.currencyName' label: 'DAGGERHEART.SETTINGS.Homebrew.currency.currencyName'
}), }),
coins: currencyField('Coins', 'DAGGERHEART.SETTINGS.Homebrew.currency.coinName', "fa-solid fa-coin-front"), coins: currencyField(
handfuls: currencyField('Handfuls', 'DAGGERHEART.SETTINGS.Homebrew.currency.handfulName', "fa-solid fa-coins"), 'Coins',
bags: currencyField('Bags', 'DAGGERHEART.SETTINGS.Homebrew.currency.bagName', "fa-solid fa-sack"), 'DAGGERHEART.SETTINGS.Homebrew.currency.coinName',
chests: currencyField('Chests', 'DAGGERHEART.SETTINGS.Homebrew.currency.chestName', "fa-solid fa-treasure-chest") 'fa-solid fa-coin-front'
),
handfuls: currencyField(
'Handfuls',
'DAGGERHEART.SETTINGS.Homebrew.currency.handfulName',
'fa-solid fa-coins'
),
bags: currencyField('Bags', 'DAGGERHEART.SETTINGS.Homebrew.currency.bagName', 'fa-solid fa-sack'),
chests: currencyField(
'Chests',
'DAGGERHEART.SETTINGS.Homebrew.currency.chestName',
'fa-solid fa-treasure-chest'
)
}), }),
restMoves: new fields.SchemaField({ restMoves: new fields.SchemaField({
longRest: new fields.SchemaField({ longRest: new fields.SchemaField({
@ -140,7 +152,7 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
/** @inheritDoc */ /** @inheritDoc */
_initializeSource(source, options = {}) { _initializeSource(source, options = {}) {
source = super._initializeSource(source, options); source = super._initializeSource(source, options);
for (const type of ["coins", "handfuls", "bags", "chests"]) { for (const type of ['coins', 'handfuls', 'bags', 'chests']) {
const initial = this.schema.fields.currency.fields[type].getInitialValue(); const initial = this.schema.fields.currency.fields[type].getInitialValue();
source.currency[type] = foundry.utils.mergeObject(initial, source.currency[type], { inplace: false }); source.currency[type] = foundry.utils.mergeObject(initial, source.currency[type], { inplace: false });
} }