From aee37b8457efcb30e696803c5bfcdad958b6cd91 Mon Sep 17 00:00:00 2001 From: Haxxer Date: Tue, 17 Sep 2024 08:37:07 +0100 Subject: [PATCH] Fixes and adjustments --- module.json | 2 +- .../sequencer-crosshair/CrosshairsDocument.js | 17 +++++++------- .../CrosshairsPlaceable.js | 23 ++++--------------- src/modules/sequencer.js | 2 +- src/sections/crosshair.js | 4 ++-- src/sections/effect.js | 6 ++++- 6 files changed, 21 insertions(+), 33 deletions(-) diff --git a/module.json b/module.json index dfe73e9f..b5b8453b 100644 --- a/module.json +++ b/module.json @@ -5,7 +5,7 @@ "version": "10.0.0", "library": "false", "compatibility": { - "minimum": "11", + "minimum": "12", "verified": "12", "maximum": "12" }, diff --git a/src/modules/sequencer-crosshair/CrosshairsDocument.js b/src/modules/sequencer-crosshair/CrosshairsDocument.js index fcf27501..64dee0ba 100644 --- a/src/modules/sequencer-crosshair/CrosshairsDocument.js +++ b/src/modules/sequencer-crosshair/CrosshairsDocument.js @@ -1,4 +1,5 @@ import CrosshairsPlaceable from "./CrosshairsPlaceable.js"; +import { get_object_canvas_data } from "../../lib/canvas-lib.js"; /** * @@ -17,7 +18,7 @@ export default class CrosshairsDocument extends MeasuredTemplateDocument { crosshair = {}; #layer = null; - endPosition = null; + cachedPosition = null; static get placeableClass() { return CrosshairsPlaceable; @@ -66,15 +67,13 @@ export default class CrosshairsDocument extends MeasuredTemplateDocument { }; getOrientation() { - return { - x: this.x, - y: this.y, - width: this.token.width * this.parent.grid.size, - height: this.token.height * this.parent.grid.size, - elevation: 0, // TODO - rotation: this.rotation, - end: this.endPosition + this.cachedPosition ??= { + source: get_object_canvas_data(this.object, { uuid: false }), + target: this.t === CONST.MEASURED_TEMPLATE_TYPES.CONE || this.t === CONST.MEASURED_TEMPLATE_TYPES.RAY + ? get_object_canvas_data(this.object, { measure: true, uuid: false }) + : null }; + return this.cachedPosition; } get documentName() { diff --git a/src/modules/sequencer-crosshair/CrosshairsPlaceable.js b/src/modules/sequencer-crosshair/CrosshairsPlaceable.js index 14a6c44c..d0cccc65 100644 --- a/src/modules/sequencer-crosshair/CrosshairsPlaceable.js +++ b/src/modules/sequencer-crosshair/CrosshairsPlaceable.js @@ -144,13 +144,14 @@ export default class CrosshairsPlaceable extends MeasuredTemplate { } _onMove(evt) { - evt.preventDefault(); + + evt.preventDefault() const now = Date.now(); const leftDown = (evt.buttons & 1) > 0; this.isDrag = !!(leftDown && canvas.mouseInteractionManager.isDragging); - canvas.mouseInteractionManager.cancel(evt); + canvas._onDragCanvasPan(evt); // Apply a 20ms throttle if (now - this.moveTime <= 20) return; @@ -362,35 +363,19 @@ export default class CrosshairsPlaceable extends MeasuredTemplate { canvas.stage.off("mouseup", this.#handlers.confirm); canvas.app.view.oncontextmenu = null; canvas.app.view.onwheel = null; - canvas.mouseInteractionManager.reset({ interactionData: true, state: false }); } _onConfirm(evt) { - evt.preventDefault(); - canvas.mouseInteractionManager.cancel(evt); - canvas.mouseInteractionManager.reset({ - interactionData: true, - state: false, - }); if (this.isDrag) { this.isDrag = false; return; } - - this.document.endPosition = this.document.t === CONST.MEASURED_TEMPLATE_TYPES.CONE || this.document.t === CONST.MEASURED_TEMPLATE_TYPES.RAY - ? get_object_position(this, { measure: true, bypass: true }) - : null; - + this.document.getOrientation(); this.#promise.resolve(this.document); this.destroy(); } _onCancel(evt) { - canvas.mouseInteractionManager.cancel(evt); - canvas.mouseInteractionManager.reset({ - interactionData: true, - state: false, - }); if (this.isDrag) { this.isDrag = false; return; diff --git a/src/modules/sequencer.js b/src/modules/sequencer.js index 01fd7ce3..7f5c4008 100644 --- a/src/modules/sequencer.js +++ b/src/modules/sequencer.js @@ -80,7 +80,7 @@ export default class Sequence { continue; } if (!section._isLastSection) { - await new Promise((resolve) => setTimeout(resolve, 1)); + await new Promise((resolve) => setTimeout(resolve, 3)); } } diff --git a/src/sections/crosshair.js b/src/sections/crosshair.js index ed0049d7..fe222bb2 100644 --- a/src/sections/crosshair.js +++ b/src/sections/crosshair.js @@ -322,8 +322,8 @@ export default class CrosshairSection extends Section { } this.sequence.nameOffsetMap[this._name] = { seed: `${this._name}-${foundry.utils.randomID()}`, - source: position, - target: position?.end ?? null + source: position.source, + target: position.target } } diff --git a/src/sections/effect.js b/src/sections/effect.js index 2ae0100b..440a1fcc 100644 --- a/src/sections/effect.js +++ b/src/sections/effect.js @@ -2272,6 +2272,10 @@ export default class EffectSection extends Section { */ _getSourceObject() { if (!this._source || typeof this._source !== "object") return this._source; + if(this._source instanceof CrosshairsPlaceable || this._source instanceof CrosshairsDocument){ + const doc = this._source?.document ?? this._source; + return doc.getOrientation().source; + } if (this._source?.cachedLocation || !this._attachTo) { return canvaslib.get_object_canvas_data(this._source, { uuid: false }); } @@ -2289,7 +2293,7 @@ export default class EffectSection extends Section { if (typeof this._target.target !== "object") return this._target.target; if(this._target?.target instanceof CrosshairsPlaceable || this._target?.target instanceof CrosshairsDocument){ const doc = this._target?.target?.document ?? this._target?.target; - return doc.getOrientation().end; + return doc.getOrientation().target; } if ( this._target?.target?.cachedLocation ||