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

@ -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<hr>\n${baseDescription}` : '';
return `${prepend}${mainDescription}`;
return { prefix, value: baseDescription, suffix: null };
}
/**@inheritdoc */

View file

@ -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<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,
rollData: this.getRollData(),
secrets: this.isOwner

View file

@ -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<hr>\n${baseDescription}` : '';
return `${prepend}${mainDescription}`;
return { prefix, value: baseDescription, suffix: null };
}
prepareDerivedData() {