From f65671f7ee4a35afac193dd298401b389c62fff9 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Tue, 13 Jan 2026 17:50:28 +0100 Subject: [PATCH] Various fixes --- daggerheart.mjs | 4 +++- .../applications/scene/sceneConfigSettings.mjs | 15 +++++++-------- module/applications/ui/itemBrowser.mjs | 8 ++++++++ module/applications/ui/sceneNavigation.mjs | 2 +- module/data/action/attackAction.mjs | 1 + module/documents/tooltipManager.mjs | 16 +++++++++++++--- templates/ui/itemBrowser/itemContainer.hbs | 2 +- 7 files changed, 34 insertions(+), 14 deletions(-) diff --git a/daggerheart.mjs b/daggerheart.mjs index cd4dbc19..e7be2f45 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -359,7 +359,9 @@ const updateAllRangeDependentEffects = async () => { const effectsAutomation = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).effects; if (!effectsAutomation.rangeDependent) return; - const tokens = canvas.scene.tokens; + const tokens = canvas.scene?.tokens; + if (!tokens) return; + if (game.user.character) { // The character updates their character's token. There can be only one token. const characterToken = tokens.find(x => x.actor === game.user.character); diff --git a/module/applications/scene/sceneConfigSettings.mjs b/module/applications/scene/sceneConfigSettings.mjs index 1b93aa8c..8a58db5c 100644 --- a/module/applications/scene/sceneConfigSettings.mjs +++ b/module/applications/scene/sceneConfigSettings.mjs @@ -5,10 +5,7 @@ export default class DhSceneConfigSettings extends foundry.applications.sheets.S super(options); Hooks.on(socketEvent.Refresh, ({ refreshType }) => { - if (refreshType === RefreshType.Scene) { - this.daggerheartFlag = new game.system.api.data.scenes.DHScene(this.document.flags.daggerheart); - this.render(); - } + if (refreshType === RefreshType.Scene) this.render(); }); } @@ -42,7 +39,9 @@ export default class DhSceneConfigSettings extends foundry.applications.sheets.S async _preRender(context, options) { await super._preFirstRender(context, options); - this.daggerheartFlag = new game.system.api.data.scenes.DHScene(this.document.flags.daggerheart); + + if (!options.internalRefresh) + this.daggerheartFlag = new game.system.api.data.scenes.DHScene(this.document.flags.daggerheart); } _attachPartListeners(partId, htmlElement, options) { @@ -52,7 +51,7 @@ export default class DhSceneConfigSettings extends foundry.applications.sheets.S case 'dh': htmlElement.querySelector('#rangeMeasurementSetting')?.addEventListener('change', async event => { this.daggerheartFlag.updateSource({ rangeMeasurement: { setting: event.target.value } }); - this.render(); + this.render({ internalRefresh: true }); }); const dragArea = htmlElement.querySelector('.scene-environments'); @@ -69,7 +68,7 @@ export default class DhSceneConfigSettings extends foundry.applications.sheets.S await this.daggerheartFlag.updateSource({ sceneEnvironments: [...this.daggerheartFlag.sceneEnvironments, data.uuid] }); - this.render(); + this.render({ internalRefresh: true }); } } @@ -92,7 +91,7 @@ export default class DhSceneConfigSettings extends foundry.applications.sheets.S (_, index) => index !== Number.parseInt(button.dataset.index) ) }); - this.render(); + this.render({ internalRefresh: true }); } /** @override */ diff --git a/module/applications/ui/itemBrowser.mjs b/module/applications/ui/itemBrowser.mjs index 794c3fb6..b35573f7 100644 --- a/module/applications/ui/itemBrowser.mjs +++ b/module/applications/ui/itemBrowser.mjs @@ -230,6 +230,14 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) { result.flatMap(r => r), 'name' ); + + /* If any noticeable slowdown occurs, consider replacing with enriching description on clicking to expand descriptions */ + for (const item of this.items) { + item.system.enrichedDescription = + (await item.system.getEnrichedDescription?.()) ?? + (await foundry.applications.ux.TextEditor.implementation.enrichHTML(item.description)); + } + this.fieldFilter = this._createFieldFilter(); if (this.presets?.filter) { diff --git a/module/applications/ui/sceneNavigation.mjs b/module/applications/ui/sceneNavigation.mjs index ac16ac99..0a3e08a5 100644 --- a/module/applications/ui/sceneNavigation.mjs +++ b/module/applications/ui/sceneNavigation.mjs @@ -31,7 +31,7 @@ export default class DhSceneNavigation extends foundry.applications.ui.SceneNavi const environments = daggerheartInfo.sceneEnvironments.filter( x => x && x.testUserPermission(game.user, 'LIMITED') ); - const hasEnvironments = environments.length > 0; + const hasEnvironments = environments.length > 0 && x.isView; return { ...x, hasEnvironments, diff --git a/module/data/action/attackAction.mjs b/module/data/action/attackAction.mjs index ed97072f..7be7461d 100644 --- a/module/data/action/attackAction.mjs +++ b/module/data/action/attackAction.mjs @@ -36,6 +36,7 @@ export default class DHAttackAction extends DHDamageAction { async use(event, options) { const result = await super.use(event, options); + if (!result.message) return; if (result.message.system.action.roll?.type === 'attack') { const { updateCountdowns } = game.system.api.applications.ui.DhCountdowns; diff --git a/module/documents/tooltipManager.mjs b/module/documents/tooltipManager.mjs index dac5aea3..c4b52bb5 100644 --- a/module/documents/tooltipManager.mjs +++ b/module/documents/tooltipManager.mjs @@ -67,7 +67,7 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti if (item) { const isAction = item instanceof game.system.api.models.actions.actionsTypes.base; const isEffect = item instanceof ActiveEffect; - await this.enrichText(item, isAction || isEffect); + await this.enrichText(item); const type = isAction ? 'action' : isEffect ? 'effect' : item.type; html = await foundry.applications.handlebars.renderTemplate( @@ -202,10 +202,20 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti } } - async enrichText(item, flatStructure) { + async enrichText(item) { const { TextEditor } = foundry.applications.ux; + + if (item.system?.metadata?.hasDescription) { + const enrichedValue = + (await item.system?.getEnrichedDescription?.()) ?? + (await TextEditor.enrichHTML(item.system.description)); + foundry.utils.setProperty(item, 'system.enrichedDescription', enrichedValue); + } else if (item.description) { + const enrichedValue = await TextEditor.enrichHTML(item.description); + foundry.utils.setProperty(item, 'enrichedDescription', enrichedValue); + } + const enrichPaths = [ - { path: flatStructure ? '' : 'system', name: 'description' }, { path: 'system', name: 'features' }, { path: 'system', name: 'actions' }, { path: 'system', name: 'customActions' } diff --git a/templates/ui/itemBrowser/itemContainer.hbs b/templates/ui/itemBrowser/itemContainer.hbs index f6aefa6b..0040a692 100644 --- a/templates/ui/itemBrowser/itemContainer.hbs +++ b/templates/ui/itemBrowser/itemContainer.hbs @@ -10,7 +10,7 @@
- {{{system.description}}} + {{{system.enrichedDescription}}}
{{/each}} \ No newline at end of file