Better separation of concerns

This commit is contained in:
WBHarry 2026-01-12 09:53:32 +01:00
parent 4a027e8591
commit 93640e56be
9 changed files with 31 additions and 45 deletions

View file

@ -2055,7 +2055,6 @@
"partyMembers": "Party Members", "partyMembers": "Party Members",
"projects": "Projects", "projects": "Projects",
"types": "Types", "types": "Types",
"itemFeatures": "Item Features",
"questions": "Questions", "questions": "Questions",
"configuration": "Configuration", "configuration": "Configuration",
"base": "Base" "base": "Base"

View file

@ -79,9 +79,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
switch (partId) { switch (partId) {
case 'description': case 'description':
context.enrichedDescription = await this.document.system.getEnrichedDescription({ context.enrichedDescription = await this.document.system.getEnrichedDescription();
headerStyle: 'large'
});
break; break;
case 'effects': case 'effects':
await this._prepareEffectsContext(context, options); await this._prepareEffectsContext(context, options);

View file

@ -55,19 +55,18 @@ export default class DHArmor extends AttachableItem {
} }
/**@inheritdoc */ /**@inheritdoc */
async getDescriptionData(options = {}) { async getDescriptionData() {
const baseDescription = await super.getDescriptionData(); const baseDescription = this.description;
const allFeatures = CONFIG.DH.ITEM.allArmorFeatures(); const allFeatures = CONFIG.DH.ITEM.allArmorFeatures();
const features = this.armorFeatures.map(x => allFeatures[x.value]); 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', 'systems/daggerheart/templates/sheets/items/armor/description.hbs',
{ features, headerStyle: options.headerStyle } { features }
); );
const mainDescription = baseDescription ? `\n<hr>\n${baseDescription}` : ''; return { prefix, value: baseDescription, suffix: null };
return `${prepend}${mainDescription}`;
} }
/**@inheritdoc */ /**@inheritdoc */

View file

@ -130,7 +130,7 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
* @returns {string} * @returns {string}
*/ */
async getDescriptionData(_options) { 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' } * @param {object} [options] - Options that modify the styling of the rendered template. { headerStyle: undefined|'none'|'large' }
* @returns {string} * @returns {string}
*/ */
async getEnrichedDescription(options) { async getEnrichedDescription() {
if (!this.metadata.hasDescription) return ''; if (!this.metadata.hasDescription) return '';
const description = await this.getDescriptionData(options); const appendWithSeparator = (text, add) => {
return await foundry.applications.ux.TextEditor.implementation.enrichHTML(description, { if (!add) return text;
if (text) return `${text}\n<hr>\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, relativeTo: this,
rollData: this.getRollData(), rollData: this.getRollData(),
secrets: this.isOwner secrets: this.isOwner

View file

@ -111,19 +111,18 @@ export default class DHWeapon extends AttachableItem {
} }
/**@inheritdoc */ /**@inheritdoc */
async getDescriptionData(options = {}) { async getDescriptionData() {
const baseDescription = await super.getDescriptionData(); const baseDescription = this.description;
const allFeatures = CONFIG.DH.ITEM.allWeaponFeatures(); const allFeatures = CONFIG.DH.ITEM.allWeaponFeatures();
const features = this.weaponFeatures.map(x => allFeatures[x.value]); 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', 'systems/daggerheart/templates/sheets/items/weapon/description.hbs',
{ features, headerStyle: options.headerStyle } { features }
); );
const mainDescription = baseDescription ? `\n<hr>\n${baseDescription}` : ''; return { prefix, value: baseDescription, suffix: null };
return `${prepend}${mainDescription}`;
} }
prepareDerivedData() { prepareDerivedData() {

View file

@ -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 itemIsAction = itemValue instanceof game.system.api.models.actions.actionsTypes.base;
const value = itemIsAction || !itemValue?.item ? itemValue : itemValue.item; const value = itemIsAction || !itemValue?.item ? itemValue : itemValue.item;
const enrichedValue = const enrichedValue =
(await value.system?.getEnrichedDescription?.({ headerStyle: 'none' })) ?? (await value.system?.getEnrichedDescription?.()) ??
(await TextEditor.enrichHTML(value.system?.description ?? value.description)); (await TextEditor.enrichHTML(value.system?.description ?? value.description));
if (itemIsAction) value.enrichedDescription = enrichedValue; if (itemIsAction) value.enrichedDescription = enrichedValue;
else foundry.utils.setProperty(item, `${basePath}.${index}.enrichedDescription`, enrichedValue); else foundry.utils.setProperty(item, `${basePath}.${index}.enrichedDescription`, enrichedValue);
} }
} else { } else {
const enrichedValue = const enrichedValue =
(await item.system?.getEnrichedDescription?.({ headerStyle: 'none' })) ?? (await item.system?.getEnrichedDescription?.()) ?? (await TextEditor.enrichHTML(pathValue));
(await TextEditor.enrichHTML(pathValue));
foundry.utils.setProperty( foundry.utils.setProperty(
item, item,
`${data.path ? `${data.path}.` : ''}enriched${data.name.capitalize()}`, `${data.path ? `${data.path}.` : ''}enriched${data.name.capitalize()}`,

View file

@ -10,16 +10,4 @@
font-family: @font-body; font-family: @font-body;
color: light-dark(@chat-blue-bg, @beige-50); 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;
}
}
}
} }

View file

@ -1,7 +1,4 @@
<div class="feature-descriptions"> <div>
{{#unless (eq headerStyle 'none')}}
<div class="features-header {{#if (eq headerStyle 'large')}}large{{/if}}">{{localize "DAGGERHEART.SETTINGS.Homebrew.itemFeatures"}}</div>
{{/unless}}
{{#each features as | feature |}} {{#each features as | feature |}}
<div><strong>{{localize feature.label}}</strong>: {{{localize feature.description}}}</div> <div><strong>{{localize feature.label}}</strong>: {{{localize feature.description}}}</div>
{{/each}} {{/each}}

View file

@ -1,7 +1,4 @@
<div class="feature-descriptions"> <div>
{{#unless (eq headerStyle 'none')}}
<div class="features-header {{#if (eq headerStyle 'large')}}large{{/if}}">{{localize "DAGGERHEART.SETTINGS.Homebrew.itemFeatures"}}</div>
{{/unless}}
{{#each features as | feature |}} {{#each features as | feature |}}
<div><strong>{{localize feature.label}}</strong>: {{{localize feature.description}}}</div> <div><strong>{{localize feature.label}}</strong>: {{{localize feature.description}}}</div>
{{/each}} {{/each}}