diff --git a/module/applications/sheets/api/application-mixin.mjs b/module/applications/sheets/api/application-mixin.mjs index 32779d6b..7267ff2b 100644 --- a/module/applications/sheets/api/application-mixin.mjs +++ b/module/applications/sheets/api/application-mixin.mjs @@ -124,7 +124,7 @@ export default function DHApplicationMixin(Base) { /**@inheritdoc */ async _onFirstRender(context, options) { await super._onFirstRender(context, options); - this.relatedDocs.map(doc => (doc.apps[this.id] = this)); + this.relatedDocs.filter(doc => doc).map(doc => (doc.apps[this.id] = this)); if (!!this.options.contextMenus.length) this._createContextMenus(); } @@ -132,7 +132,7 @@ export default function DHApplicationMixin(Base) { /** @inheritDoc */ _onClose(options) { super._onClose(options); - this.relatedDocs.map(doc => delete doc.apps[this.id]); + this.relatedDocs.filter(doc => doc).map(doc => delete doc.apps[this.id]); } /**@inheritdoc */ diff --git a/module/documents/tooltipManager.mjs b/module/documents/tooltipManager.mjs index 71dd71d2..f685c8a6 100644 --- a/module/documents/tooltipManager.mjs +++ b/module/documents/tooltipManager.mjs @@ -8,19 +8,15 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti const item = await foundry.utils.fromUuid(itemUuid); if (item) { const isAction = item instanceof game.system.api.models.actions.actionsTypes.base; - const description = await TextEditor.enrichHTML(isAction ? item.description : item.system.description); - if (item.system?.features) { - for (let feature of item.system.features) { - feature.system.enrichedDescription = await TextEditor.enrichHTML(feature.system.description); - } - } + const isEffect = item instanceof ActiveEffect; + await this.enrichText(item, isAction || isEffect); - const type = isAction ? 'action' : item.type; + const type = isAction ? 'action' : isEffect ? 'effect' : item.type; html = await foundry.applications.handlebars.renderTemplate( `systems/daggerheart/templates/ui/tooltip/${type}.hbs`, { item: item, - description: description, + description: item.system?.enrichedDescription ?? item.enrichedDescription, config: CONFIG.DH } ); @@ -126,4 +122,37 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti ]; } } + + async enrichText(item, flatStructure) { + const { TextEditor } = foundry.applications.ux; + const enrichPaths = [ + { path: flatStructure ? '' : 'system', name: 'description' }, + { path: 'system', name: 'features' }, + { path: 'system', name: 'actions' }, + { path: 'system', name: 'customActions' } + ]; + + for (let data of enrichPaths) { + const basePath = `${data.path ? `${data.path}.` : ''}${data.name}`; + const pathValue = foundry.utils.getProperty(item, basePath); + if (!pathValue) continue; + + if (Array.isArray(pathValue) || pathValue.size) { + for (const [index, itemValue] of pathValue.entries()) { + const itemIsAction = itemValue instanceof game.system.api.models.actions.actionsTypes.base; + const value = itemIsAction || !itemValue?.item ? itemValue : itemValue.item; + const enrichedValue = await TextEditor.enrichHTML(value.description); + if (itemIsAction) value.enrichedDescription = enrichedValue; + else foundry.utils.setProperty(item, `${basePath}.${index}.enrichedDescription`, enrichedValue); + } + } else { + const enrichedValue = await TextEditor.enrichHTML(pathValue); + foundry.utils.setProperty( + item, + `${data.path ? `${data.path}.` : ''}enriched${data.name.capitalize()}`, + enrichedValue + ); + } + } + } } diff --git a/module/helpers/utils.mjs b/module/helpers/utils.mjs index 4fcce619..f9349da9 100644 --- a/module/helpers/utils.mjs +++ b/module/helpers/utils.mjs @@ -252,9 +252,18 @@ export function addLinkedItemsDiff(changedItems, currentItems, options) { if (changedItems) { const prevItems = new Set(currentItems); const newItems = new Set(changedItems); - options.toLink = Array.from(newItems.difference(prevItems).map(item => item?.item ?? item)); + options.toLink = Array.from( + newItems + .difference(prevItems) + .map(item => item?.item ?? item) + .filter(x => (typeof x === 'object' ? x.item : x)) + ); + options.toUnlink = Array.from( - prevItems.difference(newItems).map(item => item?.item?.uuid ?? item?.uuid ?? item) + prevItems + .difference(newItems) + .map(item => item?.item?.uuid ?? item?.uuid ?? item) + .filter(x => (typeof x === 'object' ? x.item : x)) ); } } diff --git a/templates/ui/tooltip/armor.hbs b/templates/ui/tooltip/armor.hbs index 6bdf9ce3..8163feff 100644 --- a/templates/ui/tooltip/armor.hbs +++ b/templates/ui/tooltip/armor.hbs @@ -33,5 +33,5 @@ {{/each}} - {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.system.customActions label=(localize "DAGGERHEART.GENERAL.Action.plural")}} + {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.system.customActions isAction=true label=(localize "DAGGERHEART.GENERAL.Action.plural")}} \ No newline at end of file diff --git a/templates/ui/tooltip/consumable.hbs b/templates/ui/tooltip/consumable.hbs index f4c4c700..e51ec255 100644 --- a/templates/ui/tooltip/consumable.hbs +++ b/templates/ui/tooltip/consumable.hbs @@ -10,5 +10,5 @@ - {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.system.actions label=(localize "DAGGERHEART.GENERAL.Action.plural") }} + {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.system.actions isAction=true label=(localize "DAGGERHEART.GENERAL.Action.plural") }} \ No newline at end of file diff --git a/templates/ui/tooltip/domainCard.hbs b/templates/ui/tooltip/domainCard.hbs index ae2fe349..fabc1671 100644 --- a/templates/ui/tooltip/domainCard.hbs +++ b/templates/ui/tooltip/domainCard.hbs @@ -27,5 +27,5 @@ - {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.system.actions label=(localize "DAGGERHEART.GENERAL.Action.plural") }} + {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.system.actions isAction=true label=(localize "DAGGERHEART.GENERAL.Action.plural") }} \ No newline at end of file diff --git a/templates/ui/tooltip/effect.hbs b/templates/ui/tooltip/effect.hbs new file mode 100644 index 00000000..fb07d895 --- /dev/null +++ b/templates/ui/tooltip/effect.hbs @@ -0,0 +1,5 @@ +
+

{{item.name}}

+ +
{{{description}}}
+
\ No newline at end of file diff --git a/templates/ui/tooltip/feature.hbs b/templates/ui/tooltip/feature.hbs index ce475664..3e8867c1 100644 --- a/templates/ui/tooltip/feature.hbs +++ b/templates/ui/tooltip/feature.hbs @@ -3,6 +3,6 @@
{{{description}}}
- {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.system.actions label=(localize "DAGGERHEART.GENERAL.Action.plural") }} + {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.system.actions isAction=true label=(localize "DAGGERHEART.GENERAL.Action.plural") }} {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.effects label=(localize "DAGGERHEART.GENERAL.Effect.plural") }} \ No newline at end of file diff --git a/templates/ui/tooltip/miscellaneous.hbs b/templates/ui/tooltip/miscellaneous.hbs index b4912b4d..38e7cfb0 100644 --- a/templates/ui/tooltip/miscellaneous.hbs +++ b/templates/ui/tooltip/miscellaneous.hbs @@ -3,5 +3,5 @@
{{{description}}}
- {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.system.actions label=(localize "DAGGERHEART.GENERAL.Action.plural") }} + {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.system.actions isAction=true label=(localize "DAGGERHEART.GENERAL.Action.plural") }} \ No newline at end of file diff --git a/templates/ui/tooltip/parts/tooltipTags.hbs b/templates/ui/tooltip/parts/tooltipTags.hbs index 711945a0..b77c2215 100644 --- a/templates/ui/tooltip/parts/tooltipTags.hbs +++ b/templates/ui/tooltip/parts/tooltipTags.hbs @@ -1,12 +1,14 @@ {{#if (gt features.length 0)}}

{{label}}

{{/if}}
{{#each features as | feature |}} -
-
-
{{localize feature.name}}
- {{#if feature.img}}{{/if}} -
-
{{{localize (ifThen feature.description feature.description (ifThen feature.system.enrichedDescription feature.system.enrichedDescription feature.system.description))}}}
-
+ {{#with (ifThen ../isAction feature (ifThen feature.item feature.item feature))}} +
+
+
{{localize this.name}}
+ {{#if this.img}}{{/if}} +
+
{{{localize (ifThen this.enrichedDescription this.enrichedDescription this.system.enrichedDescription)}}}
+
+ {{/with}} {{/each}}
\ No newline at end of file diff --git a/templates/ui/tooltip/weapon.hbs b/templates/ui/tooltip/weapon.hbs index 8b152f22..a8fe9c46 100644 --- a/templates/ui/tooltip/weapon.hbs +++ b/templates/ui/tooltip/weapon.hbs @@ -52,5 +52,5 @@ {{/each}} - {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.system.customActions label=(localize "DAGGERHEART.GENERAL.Action.plural") }} + {{> "systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs" features=item.system.customActions isAction=true label=(localize "DAGGERHEART.GENERAL.Action.plural") }} \ No newline at end of file