From f33dc8c4af58d30308eda84fd8ff5e4982e8c943 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Wed, 16 Jul 2025 13:06:52 +0200 Subject: [PATCH] Active effects are shown on the token --- daggerheart.mjs | 1 + module/canvas/placeables/_module.mjs | 1 + module/canvas/placeables/token.mjs | 36 ++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 module/canvas/placeables/token.mjs diff --git a/daggerheart.mjs b/daggerheart.mjs index 6fb6cc40..0d78e8fe 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -136,6 +136,7 @@ Hooks.once('init', () => { CONFIG.Canvas.rulerClass = placeables.DhRuler; CONFIG.Canvas.layers.templates.layerClass = placeables.DhTemplateLayer; + CONFIG.Token.objectClass = placeables.DhTokenPlaceable; CONFIG.Combat.documentClass = documents.DhpCombat; CONFIG.ui.combat = applications.ui.DhCombatTracker; CONFIG.ui.chat = applications.ui.DhChatLog; diff --git a/module/canvas/placeables/_module.mjs b/module/canvas/placeables/_module.mjs index 3610559c..78242839 100644 --- a/module/canvas/placeables/_module.mjs +++ b/module/canvas/placeables/_module.mjs @@ -1,4 +1,5 @@ export { default as DhMeasuredTemplate } from './measuredTemplate.mjs'; export { default as DhRuler } from './ruler.mjs'; export { default as DhTemplateLayer } from './templateLayer.mjs'; +export { default as DhTokenPlaceable } from './token.mjs'; export { default as DhTokenRuler } from './tokenRuler.mjs'; diff --git a/module/canvas/placeables/token.mjs b/module/canvas/placeables/token.mjs new file mode 100644 index 00000000..9b724dad --- /dev/null +++ b/module/canvas/placeables/token.mjs @@ -0,0 +1,36 @@ +export default class DhTokenPlaceable extends foundry.canvas.placeables.Token { + /** @inheritDoc */ + async _drawEffects() { + this.effects.renderable = false; + + // Clear Effects Container + this.effects.removeChildren().forEach(c => c.destroy()); + this.effects.bg = this.effects.addChild(new PIXI.Graphics()); + this.effects.bg.zIndex = -1; + this.effects.overlay = null; + + // Categorize effects + const activeEffects = Array.from(this.actor.effects); + const overlayEffect = activeEffects.findLast(e => e.img && e.getFlag('core', 'overlay')); + + // Draw effects + const promises = []; + for (const [i, effect] of activeEffects.entries()) { + if (!effect.img) continue; + const promise = + effect === overlayEffect + ? this._drawOverlay(effect.img, effect.tint) + : this._drawEffect(effect.img, effect.tint); + promises.push( + promise.then(e => { + if (e) e.zIndex = i; + }) + ); + } + await Promise.allSettled(promises); + + this.effects.sortChildren(); + this.effects.renderable = true; + this.renderFlags.set({ refreshEffects: true }); + } +}