diff --git a/module/applications/sheets/api/application-mixin.mjs b/module/applications/sheets/api/application-mixin.mjs index 603e7f00..5ad79a26 100644 --- a/module/applications/sheets/api/application-mixin.mjs +++ b/module/applications/sheets/api/application-mixin.mjs @@ -149,6 +149,7 @@ export default function DHApplicationMixin(Base) { async _onRender(context, options) { await super._onRender(context, options); this._createTagifyElements(this.options.tagifyConfigs); + await this.#prepareInventoryDescription(); } /* -------------------------------------------- */ @@ -162,13 +163,7 @@ export default function DHApplicationMixin(Base) { const { actionId, itemUuid } = el.parentElement.dataset; const selector = `${actionId ? `[data-action-id="${actionId}"]` : `[data-item-uuid="${itemUuid}"]`} .extensible`; const newExtensible = newElement.querySelector(selector); - - if (!newExtensible) continue; - newExtensible.classList.add('extended'); - const descriptionElement = newExtensible.querySelector('.invetory-description'); - if (descriptionElement) { - this.#prepareInventoryDescription(newExtensible, descriptionElement); - } + newExtensible?.classList.add('extended'); } } @@ -407,32 +402,37 @@ export default function DHApplicationMixin(Base) { /** * Prepares and enriches an inventory item or action description for display. - * @param {HTMLElement} extensibleElement - The parent element containing the description. - * @param {HTMLElement} descriptionElement - The element where the enriched description will be rendered. * @returns {Promise} */ - async #prepareInventoryDescription(extensibleElement, descriptionElement) { - const parent = extensibleElement.closest('[data-item-uuid], [data-action-id]'); - const { actionId, itemUuid } = parent?.dataset || {}; - if (!actionId && !itemUuid) return; + async #prepareInventoryDescription() { + // Get all inventory item elements with a data-item-uuid attribute + const inventoryItems = this.element.querySelectorAll('.inventory-item[data-item-uuid]'); + for (const el of inventoryItems) { + // Get the doc uuid from the element + const { itemUuid } = el?.dataset || {}; + if (!itemUuid) continue; - const doc = itemUuid - ? await getDocFromElement(extensibleElement) - : this.document.system.attack?.id === actionId - ? this.document.system.attack - : this.document.system.actions?.get(actionId); - if (!doc) return; + //get doc by uuid + const doc = await fromUuid(itemUuid); - const description = game.i18n.localize(doc.system?.description ?? doc.description); - const isAction = !!actionId; - descriptionElement.innerHTML = await foundry.applications.ux.TextEditor.implementation.enrichHTML( - description, - { - relativeTo: isAction ? doc.parent : doc, - rollData: doc.getRollData?.(), - secrets: isAction ? doc.parent.isOwner : doc.isOwner - } - ); + //get inventory-item description element + const descriptionElement = el.querySelector('.invetory-description'); + if (!doc || !descriptionElement) continue; + + // localize the description (idk if it's still necessary) + const description = game.i18n.localize(doc.system?.description ?? doc.description); + + // Enrich the description and attach it; + const isAction = doc.documentName === 'Action'; + descriptionElement.innerHTML = await foundry.applications.ux.TextEditor.implementation.enrichHTML( + description, + { + relativeTo: isAction ? doc.parent : doc, + rollData: doc.getRollData?.(), + secrets: isAction ? doc.parent.isOwner : doc.isOwner + } + ); + } } /* -------------------------------------------- */ @@ -440,8 +440,6 @@ export default function DHApplicationMixin(Base) { /* -------------------------------------------- */ static async #addNewItem(event, target) { - const { type } = target.dataset; - const createChoice = await foundry.applications.api.DialogV2.wait({ classes: ['dh-style', 'two-big-buttons'], buttons: [ @@ -609,10 +607,7 @@ export default function DHApplicationMixin(Base) { static async #toggleExtended(_, target) { const container = target.closest('.inventory-item'); const extensible = container?.querySelector('.extensible'); - const t = extensible?.classList.toggle('extended'); - - const descriptionElement = extensible?.querySelector('.invetory-description'); - if (t && !!descriptionElement) await this.#prepareInventoryDescription(extensible, descriptionElement); + extensible?.classList.toggle('extended'); } }