prepare descriptions per-sheet

This commit is contained in:
jalensailin
2025-07-23 18:30:15 -04:00
parent 9df7e3a397
commit 0b654acf8c
4 changed files with 50 additions and 23 deletions
+1
View File
@@ -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,
+49 -2
View File
@@ -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<string>} 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);
-6
View File
@@ -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;
}
}
-15
View File
@@ -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;
}
}