mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 15:39:02 +01:00
Fixed tooltip enrichment
This commit is contained in:
parent
a5b656f533
commit
6f9a249868
11 changed files with 70 additions and 25 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,5 +33,5 @@
|
|||
{{/each}}
|
||||
</div>
|
||||
|
||||
{{> "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")}}
|
||||
</div>
|
||||
|
|
@ -10,5 +10,5 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{{> "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") }}
|
||||
</div>
|
||||
|
|
@ -27,5 +27,5 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{{> "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") }}
|
||||
</div>
|
||||
5
templates/ui/tooltip/effect.hbs
Normal file
5
templates/ui/tooltip/effect.hbs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<div class="daggerheart dh-style tooltip">
|
||||
<h2 class="tooltip-title">{{item.name}}</h2>
|
||||
<img class="tooltip-image" src="{{item.img}}" />
|
||||
<div class="tooltip-description">{{{description}}}</div>
|
||||
</div>
|
||||
|
|
@ -3,6 +3,6 @@
|
|||
<img class="tooltip-image" src="{{item.img}}" />
|
||||
<div class="tooltip-description">{{{description}}}</div>
|
||||
|
||||
{{> "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") }}
|
||||
</div>
|
||||
|
|
@ -3,5 +3,5 @@
|
|||
<img class="tooltip-image" src="{{item.img}}" />
|
||||
<div class="tooltip-description">{{{description}}}</div>
|
||||
|
||||
{{> "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") }}
|
||||
</div>
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
{{#if (gt features.length 0)}}<h4 class="tooltip-sub-title">{{label}}</h4>{{/if}}
|
||||
<div class="tooltip-tags">
|
||||
{{#each features as | feature |}}
|
||||
<div class="tooltip-tag">
|
||||
<div class="tooltip-tag-label-container">
|
||||
<div class="tooltip-tag-label">{{localize feature.name}}</div>
|
||||
{{#if feature.img}}<img class="tooltip-tag-image" src="{{feature.img}}" />{{/if}}
|
||||
</div>
|
||||
<div class="tooltip-tag-description">{{{localize (ifThen feature.description feature.description (ifThen feature.system.enrichedDescription feature.system.enrichedDescription feature.system.description))}}}</div>
|
||||
</div>
|
||||
{{#with (ifThen ../isAction feature (ifThen feature.item feature.item feature))}}
|
||||
<div class="tooltip-tag">
|
||||
<div class="tooltip-tag-label-container">
|
||||
<div class="tooltip-tag-label">{{localize this.name}}</div>
|
||||
{{#if this.img}}<img class="tooltip-tag-image" src="{{this.img}}" />{{/if}}
|
||||
</div>
|
||||
<div class="tooltip-tag-description">{{{localize (ifThen this.enrichedDescription this.enrichedDescription this.system.enrichedDescription)}}}</div>
|
||||
</div>
|
||||
{{/with}}
|
||||
{{/each}}
|
||||
</div>
|
||||
|
|
@ -52,5 +52,5 @@
|
|||
{{/each}}
|
||||
</div>
|
||||
|
||||
{{> "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") }}
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue