From 93640e56be09de8be628092856132c2bdfbadc20 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Mon, 12 Jan 2026 09:53:32 +0100 Subject: [PATCH] Better separation of concerns --- lang/en.json | 1 - module/applications/sheets/api/base-item.mjs | 4 +--- module/data/item/armor.mjs | 13 ++++++------- module/data/item/base.mjs | 18 ++++++++++++++---- module/data/item/weapon.mjs | 13 ++++++------- module/documents/tooltipManager.mjs | 5 ++--- .../less/sheets/items/item-sheet-shared.less | 12 ------------ templates/sheets/items/armor/description.hbs | 5 +---- templates/sheets/items/weapon/description.hbs | 5 +---- 9 files changed, 31 insertions(+), 45 deletions(-) diff --git a/lang/en.json b/lang/en.json index a78ed588..60753d50 100755 --- a/lang/en.json +++ b/lang/en.json @@ -2055,7 +2055,6 @@ "partyMembers": "Party Members", "projects": "Projects", "types": "Types", - "itemFeatures": "Item Features", "questions": "Questions", "configuration": "Configuration", "base": "Base" diff --git a/module/applications/sheets/api/base-item.mjs b/module/applications/sheets/api/base-item.mjs index 00448e95..e3568b23 100644 --- a/module/applications/sheets/api/base-item.mjs +++ b/module/applications/sheets/api/base-item.mjs @@ -79,9 +79,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { switch (partId) { case 'description': - context.enrichedDescription = await this.document.system.getEnrichedDescription({ - headerStyle: 'large' - }); + context.enrichedDescription = await this.document.system.getEnrichedDescription(); break; case 'effects': await this._prepareEffectsContext(context, options); diff --git a/module/data/item/armor.mjs b/module/data/item/armor.mjs index c0de0eeb..3d4a62fa 100644 --- a/module/data/item/armor.mjs +++ b/module/data/item/armor.mjs @@ -55,19 +55,18 @@ export default class DHArmor extends AttachableItem { } /**@inheritdoc */ - async getDescriptionData(options = {}) { - const baseDescription = await super.getDescriptionData(); + async getDescriptionData() { + const baseDescription = this.description; const allFeatures = CONFIG.DH.ITEM.allArmorFeatures(); const features = this.armorFeatures.map(x => allFeatures[x.value]); - if (!features.length) return baseDescription; + if (!features.length) return { prefix: null, value: baseDescription, suffix: null }; - const prepend = await foundry.applications.handlebars.renderTemplate( + const prefix = await foundry.applications.handlebars.renderTemplate( 'systems/daggerheart/templates/sheets/items/armor/description.hbs', - { features, headerStyle: options.headerStyle } + { features } ); - const mainDescription = baseDescription ? `\n
\n${baseDescription}` : ''; - return `${prepend}${mainDescription}`; + return { prefix, value: baseDescription, suffix: null }; } /**@inheritdoc */ diff --git a/module/data/item/base.mjs b/module/data/item/base.mjs index c98631cb..0ad0f38c 100644 --- a/module/data/item/base.mjs +++ b/module/data/item/base.mjs @@ -130,7 +130,7 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel { * @returns {string} */ async getDescriptionData(_options) { - return this.description; + return { prefix: null, value: this.description, suffix: null }; } /** @@ -138,11 +138,21 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel { * @param {object} [options] - Options that modify the styling of the rendered template. { headerStyle: undefined|'none'|'large' } * @returns {string} */ - async getEnrichedDescription(options) { + async getEnrichedDescription() { if (!this.metadata.hasDescription) return ''; - const description = await this.getDescriptionData(options); - return await foundry.applications.ux.TextEditor.implementation.enrichHTML(description, { + const appendWithSeparator = (text, add) => { + if (!add) return text; + if (text) return `${text}\n
\n${add}`; + else return add; + }; + + const { prefix, value, suffix } = await this.getDescriptionData(); + let fullDescription = prefix ?? ''; + fullDescription = appendWithSeparator(fullDescription, value); + fullDescription = appendWithSeparator(fullDescription, suffix); + + return await foundry.applications.ux.TextEditor.implementation.enrichHTML(fullDescription, { relativeTo: this, rollData: this.getRollData(), secrets: this.isOwner diff --git a/module/data/item/weapon.mjs b/module/data/item/weapon.mjs index 48a53e02..f333e5f3 100644 --- a/module/data/item/weapon.mjs +++ b/module/data/item/weapon.mjs @@ -111,19 +111,18 @@ export default class DHWeapon extends AttachableItem { } /**@inheritdoc */ - async getDescriptionData(options = {}) { - const baseDescription = await super.getDescriptionData(); + async getDescriptionData() { + const baseDescription = this.description; const allFeatures = CONFIG.DH.ITEM.allWeaponFeatures(); const features = this.weaponFeatures.map(x => allFeatures[x.value]); - if (!features.length) return baseDescription; + if (!features.length) return { prefix: null, value: baseDescription, suffix: null }; - const prepend = await foundry.applications.handlebars.renderTemplate( + const prefix = await foundry.applications.handlebars.renderTemplate( 'systems/daggerheart/templates/sheets/items/weapon/description.hbs', - { features, headerStyle: options.headerStyle } + { features } ); - const mainDescription = baseDescription ? `\n
\n${baseDescription}` : ''; - return `${prepend}${mainDescription}`; + return { prefix, value: baseDescription, suffix: null }; } prepareDerivedData() { diff --git a/module/documents/tooltipManager.mjs b/module/documents/tooltipManager.mjs index b25a4b21..dac5aea3 100644 --- a/module/documents/tooltipManager.mjs +++ b/module/documents/tooltipManager.mjs @@ -221,15 +221,14 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti const itemIsAction = itemValue instanceof game.system.api.models.actions.actionsTypes.base; const value = itemIsAction || !itemValue?.item ? itemValue : itemValue.item; const enrichedValue = - (await value.system?.getEnrichedDescription?.({ headerStyle: 'none' })) ?? + (await value.system?.getEnrichedDescription?.()) ?? (await TextEditor.enrichHTML(value.system?.description ?? value.description)); if (itemIsAction) value.enrichedDescription = enrichedValue; else foundry.utils.setProperty(item, `${basePath}.${index}.enrichedDescription`, enrichedValue); } } else { const enrichedValue = - (await item.system?.getEnrichedDescription?.({ headerStyle: 'none' })) ?? - (await TextEditor.enrichHTML(pathValue)); + (await item.system?.getEnrichedDescription?.()) ?? (await TextEditor.enrichHTML(pathValue)); foundry.utils.setProperty( item, `${data.path ? `${data.path}.` : ''}enriched${data.name.capitalize()}`, diff --git a/styles/less/sheets/items/item-sheet-shared.less b/styles/less/sheets/items/item-sheet-shared.less index 54b9c8c2..d0a8cc48 100644 --- a/styles/less/sheets/items/item-sheet-shared.less +++ b/styles/less/sheets/items/item-sheet-shared.less @@ -10,16 +10,4 @@ font-family: @font-body; color: light-dark(@chat-blue-bg, @beige-50); } - - .feature-descriptions { - .features-header { - font-size: 14px; - font-weight: bold; - text-decoration: underline; - - &.large { - font-size: 18px; - } - } - } } diff --git a/templates/sheets/items/armor/description.hbs b/templates/sheets/items/armor/description.hbs index d2c67604..c5a9924e 100644 --- a/templates/sheets/items/armor/description.hbs +++ b/templates/sheets/items/armor/description.hbs @@ -1,7 +1,4 @@ -
- {{#unless (eq headerStyle 'none')}} -
{{localize "DAGGERHEART.SETTINGS.Homebrew.itemFeatures"}}
- {{/unless}} +
{{#each features as | feature |}}
{{localize feature.label}}: {{{localize feature.description}}}
{{/each}} diff --git a/templates/sheets/items/weapon/description.hbs b/templates/sheets/items/weapon/description.hbs index d2c67604..c5a9924e 100644 --- a/templates/sheets/items/weapon/description.hbs +++ b/templates/sheets/items/weapon/description.hbs @@ -1,7 +1,4 @@ -
- {{#unless (eq headerStyle 'none')}} -
{{localize "DAGGERHEART.SETTINGS.Homebrew.itemFeatures"}}
- {{/unless}} +
{{#each features as | feature |}}
{{localize feature.label}}: {{{localize feature.description}}}
{{/each}}