Skip to content

Commit

Permalink
Fixes and adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Sep 17, 2024
1 parent e890a1b commit aee37b8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 33 deletions.
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "10.0.0",
"library": "false",
"compatibility": {
"minimum": "11",
"minimum": "12",
"verified": "12",
"maximum": "12"
},
Expand Down
17 changes: 8 additions & 9 deletions src/modules/sequencer-crosshair/CrosshairsDocument.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CrosshairsPlaceable from "./CrosshairsPlaceable.js";
import { get_object_canvas_data } from "../../lib/canvas-lib.js";

/**
*
Expand All @@ -17,7 +18,7 @@ export default class CrosshairsDocument extends MeasuredTemplateDocument {

crosshair = {};
#layer = null;
endPosition = null;
cachedPosition = null;

static get placeableClass() {
return CrosshairsPlaceable;
Expand Down Expand Up @@ -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() {
Expand Down
23 changes: 4 additions & 19 deletions src/modules/sequencer-crosshair/CrosshairsPlaceable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/sequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/sections/crosshair.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/sections/effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand All @@ -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 ||
Expand Down

0 comments on commit aee37b8

Please sign in to comment.