From 57e51ee8411d390f181526ac71ef9c01352acf20 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Sun, 1 Feb 2026 00:25:40 +0100 Subject: [PATCH] Added in comments about Beastform failing --- .../sheets-configs/token-config-mixin.mjs | 2 +- module/documents/token.mjs | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/module/applications/sheets-configs/token-config-mixin.mjs b/module/applications/sheets-configs/token-config-mixin.mjs index a23aa7f4..5242d797 100644 --- a/module/applications/sheets-configs/token-config-mixin.mjs +++ b/module/applications/sheets-configs/token-config-mixin.mjs @@ -69,7 +69,7 @@ export default function DHTokenConfigMixin(Base) { const deletions = { actorId: _del, actorLink: _del }; const mergeOptions = { inplace: false, performDeletions: true }; - this._preview.updateSource(mergeObject(changes, deletions, mergeOptions)); + this._preview.updateSource(foundry.utils.mergeObject(changes, deletions, mergeOptions)); if (this._preview?.object?.destroyed === false) { this._preview.object.initializeSources(); diff --git a/module/documents/token.mjs b/module/documents/token.mjs index b9507c2f..b70d7834 100644 --- a/module/documents/token.mjs +++ b/module/documents/token.mjs @@ -542,4 +542,62 @@ export default class DHToken extends CONFIG.Token.documentClass { game.system.registeredTriggers.unregisterItemTriggers(this.actor.items); } } + + /* V14 TEMP until foundry fixes: https://discord.com/channels/170995199584108546/1421197211194228907/1467296028700049566 */ + _onRelatedUpdate(update = {}, operation = {}) { + this.#refreshOverrides(operation); + this._prepareBars(); + + // Update tracked Combat resource + const combatant = this.combatant; + if (combatant) { + const isActorUpdate = [this, null, undefined].includes(operation.parent); + const resource = game.combat.settings.resource; + const updates = Array.isArray(update) ? update : [update]; + if (isActorUpdate && resource && updates.some(u => foundry.utils.hasProperty(u.system ?? {}, resource))) { + combatant.updateResource(); + } + ui.combat.render(); + } + + // Trigger redraws on the token + if (this.parent.isView) { + if (this.object?.hasActiveHUD) canvas.tokens.hud.render(); + this.object?.renderFlags.set({ redrawEffects: true }); + for (const key of ['bar1', 'bar2']) { + const name = `${this.object?.objectId}.animate${key.capitalize()}`; + const easing = foundry.canvas.animation.CanvasAnimation.easeInOutCosine; + this.object?.animate({ [key]: this[key] }, { name, easing }); + } + for (const app of foundry.applications.sheets.TokenConfig.instances()) { + app._preview?.updateSource({ delta: this.toObject().delta }, { diff: false, recursive: false }); + app._preview?.object?.renderFlags.set({ refreshBars: true, redrawEffects: true }); + } + } + } + + /* V14 TEMP until foundry fixes: https://discord.com/channels/170995199584108546/1421197211194228907/1467296028700049566 */ + #refreshOverrides(operation) { + if (!this.actor) return; + + const { deepClone, mergeObject, equals, isEmpty } = foundry.utils; + const oldOverrides = deepClone(this._overrides) ?? {}; + const newOverrides = deepClone(this.actor?.tokenOverrides ?? {}, { prune: true }); + if (!equals(oldOverrides, newOverrides)) { + this._overrides = newOverrides; + this.reset(); + + // Send emulated update data to the PlaceableObject + if (!canvas.ready || canvas.scene !== this.scene) return; + const { width, height, depth, ...changes } = mergeObject( + mergeObject(oldOverrides, this, { insertKeys: false, insertValues: false }), + this._overrides + ); + this.object?._onUpdate(changes, {}, game.user.id); + + // Hand off size changes to a secondary handler requiring downstream implementation. + const sizeChanges = deepClone({ width, height, depth }, { prune: true }); + if (!isEmpty(sizeChanges)) this._onOverrideSize(sizeChanges, operation); + } + } }