diff --git a/module/sheets/agent-sheet.js b/module/sheets/agent-sheet.js index f75ad99..0938c04 100644 --- a/module/sheets/agent-sheet.js +++ b/module/sheets/agent-sheet.js @@ -29,6 +29,7 @@ export default class DGAgentSheet extends DGActorSheet { }, }); + /** @override */ static PARTS = /** @type {const} */ ({ header: this.BASE_PARTS.header, tabs: this.BASE_PARTS.tabs, diff --git a/module/sheets/base-actor-sheet.js b/module/sheets/base-actor-sheet.js index 984ffeb..e8ee233 100644 --- a/module/sheets/base-actor-sheet.js +++ b/module/sheets/base-actor-sheet.js @@ -69,6 +69,9 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { // Prepare subname info placeholder. context.subnameInfoPlaceholder = this._prepareSubnameInfoPlaceholder(); + // Prepare descriptions for each sheet. + context.enrichedDescription = await this._prepareDescriptions(); + // Early return if this is a vehicle. if (this.actor.type === "vehicle") return context; @@ -200,9 +203,53 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { return game.i18n.localize(subnameInfoPlaceholder); } + /** + * Prepares and enriches the description for an actor based on its type. + * + * @returns {Promise} The outer HTML of the enriched description. + */ + async _prepareDescriptions() { + let descriptionPath; + + switch (this.actor.type) { + case "agent": + descriptionPath = "system.physicalDescription"; + break; + case "npc": + case "unnatural": + descriptionPath = "system.notes"; + break; + case "vehicle": + descriptionPath = "system.description"; + break; + default: + break; + } + + const descriptionValue = foundry.utils.getProperty( + this.actor, + descriptionPath, + ); + + const enrichedDescription = + await foundry.applications.ux.TextEditor.implementation.enrichHTML( + descriptionValue, + { + rollData: this.document.getRollData(), + relativeTo: this.document, + }, + ); + const { HTMLProseMirrorElement } = foundry.applications.elements; + return HTMLProseMirrorElement.create({ + name: descriptionPath, + value: descriptionValue, + enriched: enrichedDescription, + toggled: true, + }).outerHTML; + } + /** * Sorts the skills on the actor sheet based on the appropriate localized entry. - * For the Japanese language, the sort label is the ruby text. * If the localized entry is not found, the sort label is the skill key. * * @returns {void} @@ -1217,7 +1264,7 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { * Toggle a boolean property on an item or actor. * * @param {string} prop The property to toggle. - * @param {string} itemId The ID of the item to toggle. + * @param {string} [itemId] The ID of item on which to apply toggle, if it exists. */ toggle(prop, itemId) { const item = this.actor.items.get(itemId); diff --git a/module/sheets/npc-sheet.js b/module/sheets/npc-sheet.js index c67227b..fe8418b 100644 --- a/module/sheets/npc-sheet.js +++ b/module/sheets/npc-sheet.js @@ -38,12 +38,6 @@ export default class DGNPCSheet extends DGActorSheet { "DG.Sheet.BlockHeaders.Statistics", ); - context.enrichedDescription = - await foundry.applications.ux.TextEditor.implementation.enrichHTML( - this.actor.system.notes, - { async: true }, - ); - return context; } } diff --git a/module/sheets/vehicle-sheet.js b/module/sheets/vehicle-sheet.js index 45b9f7b..28fbe66 100644 --- a/module/sheets/vehicle-sheet.js +++ b/module/sheets/vehicle-sheet.js @@ -23,19 +23,4 @@ export default class DGVehicleSheet extends DGActorSheet { gear: this.BASE_PARTS.gear, about: this.BASE_PARTS.about, }); - - /* -------------------------------------------- */ - - /** @override */ - async _prepareContext(options) { - const context = await super._prepareContext(options); - - context.enrichedDescription = - await foundry.applications.ux.TextEditor.implementation.enrichHTML( - this.actor.system.description, - { async: true }, - ); - - return context; - } }