From 3b237a223f737970ef3713561ca0c2cd947eb357 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Wed, 17 Dec 2025 18:37:32 +0100 Subject: [PATCH] . --- .../sidebar/tabs/actorDirectory.mjs | 26 +++++++++++++++++++ module/data/actor/base.mjs | 8 ------ module/documents/token.mjs | 11 ++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/module/applications/sidebar/tabs/actorDirectory.mjs b/module/applications/sidebar/tabs/actorDirectory.mjs index 4a528e74..d40443a0 100644 --- a/module/applications/sidebar/tabs/actorDirectory.mjs +++ b/module/applications/sidebar/tabs/actorDirectory.mjs @@ -17,4 +17,30 @@ export default class DhActorDirectory extends foundry.applications.sidebar.tabs. : null; }; } + + /** @inheritDoc */ + _onDragStart(event) { + let actor; + const { entryId } = event.currentTarget.dataset; + if (entryId) { + actor = this.collection.get(entryId); + if (!actor?.visible) return false; + } + super._onDragStart(event); + + // Create the drag preview. + if (actor && canvas.ready) { + const img = event.currentTarget.querySelector('img'); + const pt = actor.prototypeToken; + const usesSize = actor.system.metadata.usesSize; + const tokenSizes = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).tokenSizes; + const width = usesSize ? tokenSizes[actor.system.size] : pt.width; + const height = usesSize ? tokenSizes[actor.system.size] : pt.height; + + const w = width * canvas.dimensions.size * Math.abs(pt.texture.scaleX) * canvas.stage.scale.x; + const h = height * canvas.dimensions.size * Math.abs(pt.texture.scaleY) * canvas.stage.scale.y; + const preview = foundry.applications.ux.DragDrop.implementation.createDragImage(img, w, h); + event.dataTransfer.setDragImage(preview, w / 2, h / 2); + } + } } diff --git a/module/data/actor/base.mjs b/module/data/actor/base.mjs index 8c933a6e..61a14a13 100644 --- a/module/data/actor/base.mjs +++ b/module/data/actor/base.mjs @@ -146,14 +146,6 @@ export default class BaseDataActor extends foundry.abstract.TypeDataModel { options.scrollingTextData = textData; } - if (!this.parent.isToken && changes.system?.size) { - const tokenSizes = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).tokenSizes; - this.parent.prototypeToken.update({ - width: tokenSizes[changes.system.size], - height: tokenSizes[changes.system.size] - }); - } - if (changes.system?.resources) { const defeatedSettings = game.settings.get( CONFIG.DH.id, diff --git a/module/documents/token.mjs b/module/documents/token.mjs index a08bb365..b9a8afc6 100644 --- a/module/documents/token.mjs +++ b/module/documents/token.mjs @@ -101,6 +101,17 @@ export default class DHToken extends TokenDocument { super.deleteCombatants(tokens, combat ?? {}); } + /**@inheritdoc */ + getSize(data = {}) { + if (this.actor?.system.metadata.usesSize) { + const tokenSizes = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).tokenSizes; + const size = tokenSizes[this.actor.system.size]; + return super.getSize({ ...data, width: size, height: size }); + } + + return super.getSize(data); + } + /**@inheritdoc */ _onRelatedUpdate(update = {}, operation = {}) { super._onRelatedUpdate(update, operation);