mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 23:49: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))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue