diff --git a/src/foundry_imports.js b/src/foundry_imports.js index 568fd52..db913ea 100644 --- a/src/foundry_imports.js +++ b/src/foundry_imports.js @@ -49,7 +49,7 @@ export async function moveEntities(draggedEntity, selectedEntities) { // Once all animations are complete we can clear the ruler if (this.draggedEntity?.id === draggedEntity.id) { - this._state = Ruler.STATES.MEASURING; + this._state = Ruler.STATES.MEASURING; this._endMeasurement(); } } @@ -137,8 +137,8 @@ export function onMouseMove(event) { // Extract event data const destination = { - x: event.interactionData.destination.x + this.rulerOffset.x, - y: event.interactionData.destination.y + this.rulerOffset.y, + x: event.interactionData.destination.x, + y: event.interactionData.destination.y, }; // Hide any existing Token HUD diff --git a/src/main.js b/src/main.js index e921ad8..bbb985c 100644 --- a/src/main.js +++ b/src/main.js @@ -137,11 +137,6 @@ function onEntityLeftDragStart(wrapped, event) { const ruler = canvas.controls.ruler; ruler.draggedEntity = this; const entityCenter = getEntityCenter(this); - const isV11 = game.release.generation === 11; - ruler.rulerOffset = { - x: isV11 ? entityCenter.x - event.interactionData.origin.x : 0, - y: isV11 ? entityCenter.y - event.interactionData.origin.y : 0, - }; if (game.settings.get(settingsKey, "autoStartMeasurement")) { let options = {}; setSnapParameterOnOptions(ruler, options); @@ -218,7 +213,7 @@ function applyGridlessSnapping(event) { const rasterWidth = 35 / canvas.stage.scale.x; const tokenX = event.interactionData.destination.x; const tokenY = event.interactionData.destination.y; - const destination = {x: tokenX + ruler.rulerOffset.x, y: tokenY + ruler.rulerOffset.y}; + const destination = {x: tokenX, y: tokenY}; const ranges = getRangesFromSpeedProvider(ruler.draggedEntity); const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active; @@ -242,8 +237,8 @@ function applyGridlessSnapping(event) { const deltaY = destination.y - rasterLocation.y; const rasterDistance = Math.hypot(deltaX, deltaY); if (rasterDistance < rasterWidth) { - event.interactionData.destination.x = rasterLocation.x - ruler.rulerOffset.x; - event.interactionData.destination.y = rasterLocation.y - ruler.rulerOffset.y; + event.interactionData.destination.x = rasterLocation.x; + event.interactionData.destination.y = rasterLocation.y; } } } else { @@ -257,7 +252,7 @@ function applyGridlessSnapping(event) { }); origin = segments.pop().ray.A; waypointDistance = canvas.grid.measureDistances(segments).reduce((a, b) => a + b); - origin = {x: origin.x - ruler.rulerOffset.x, y: origin.y - ruler.rulerOffset.y}; + origin = {x: origin.x, y: origin.y}; } const deltaX = tokenX - origin.x; diff --git a/src/ruler.js b/src/ruler.js index 02dd94c..851bd01 100644 --- a/src/ruler.js +++ b/src/ruler.js @@ -42,7 +42,10 @@ export function extendRuler() { } _getMeasurementData() { - const json = typeof super._getMeasurementData === 'function' ? super._getMeasurementData() : super.toJSON(); + const json = + typeof super._getMeasurementData === "function" + ? super._getMeasurementData() + : super.toJSON(); if (this.draggedEntity) { const isToken = this.draggedEntity instanceof Token; json.draggedEntityIsToken = isToken; @@ -62,7 +65,7 @@ export function extendRuler() { } update(data) { - if ( !data || (data.state === Ruler.STATES.INACTIVE) ) return this.clear(); + if (!data || data.state === Ruler.STATES.INACTIVE) return this.clear(); // Don't show a GMs drag ruler to non GM players if ( data.draggedEntity && @@ -111,7 +114,7 @@ export function extendRuler() { // Compute the measurement destination, segments, and distance const d = this._getMeasurementDestination(destination); - if ( this.destination && (d.x === this.destination.x) && (d.y === this.destination.y)) { + if (this.destination && d.x === this.destination.x && d.y === this.destination.y) { this.performPostPathfindingActions(options); return; } @@ -262,7 +265,7 @@ export function extendRuler() { unsnappedSegments.push({ray: unsnappedRay, label}); } this.dragRulerUnsnappedSegments = unsnappedSegments; - if ( this.labels.children.length > segments.length ) { + if (this.labels.children.length > segments.length) { this.labels.removeChildren(segments.length).forEach(c => c.destroy()); } return segments; @@ -289,9 +292,7 @@ export function extendRuler() { this.totalDistance += d; s.last = i === this.segments.length - 1; s.distance = d; - // V11 and lower use totalDistance as a second arg - // V12 ignores the 2nd argument and uses this.totalDistance - s.text = this._getSegmentLabel(s, this.totalDistance); + s.text = this._getSegmentLabel(s); } for (const [i, segment] of this.segments.entries()) { @@ -390,14 +391,10 @@ export function extendRuler() { if (this.waypoints.filter(w => !w.isPrevious).length > 1) { event.preventDefault(); const mousePosition = getPointer().getLocalPosition(canvas.tokens); - const rulerOffset = this.rulerOffset; // Options are not passed to _removeWaypoint in vanilla Foundry. // Send them in case other modules have overriden that behavior and accept an options parameter (Toggle Snap to Grid) - this._removeWaypoint( - {x: mousePosition.x + rulerOffset.x, y: mousePosition.y + rulerOffset.y}, - options, - ); + this._removeWaypoint({x: mousePosition.x, y: mousePosition.y}, options); this.performPostPathfindingActions(options); } else { this.dragRulerAbortDrag(event); @@ -493,8 +490,8 @@ export function extendRuler() { ruler.dragRulerAddWaypoint(entityCenter, {snap: false}); const mousePosition = getPointer().getLocalPosition(canvas.tokens); const destination = { - x: mousePosition.x + ruler.rulerOffset.x, - y: mousePosition.y + ruler.rulerOffset.y, + x: mousePosition.x, + y: mousePosition.y, }; if (measureImmediately) ruler.measure(destination, options); } diff --git a/src/util.js b/src/util.js index f623fbb..afb6fa8 100644 --- a/src/util.js +++ b/src/util.js @@ -157,8 +157,7 @@ export function getAreaFromPositionAndShape(position, shape) { let y = position.y + space.y; if (isCanvasHex()) { let shiftedRow; - // v12 ?? v11 - if (canvas.grid?.even ?? canvas.grid.grid.options.even) shiftedRow = 1; + if (canvas.grid?.even) shiftedRow = 1; else shiftedRow = 0; if (canvas.grid.grid.columnar) { if (space.x % 2 !== 0 && position.x % 2 !== shiftedRow) { @@ -302,8 +301,7 @@ export function getPointer() { export function getMeasurePosition() { const mousePosition = getPointer().getLocalPosition(canvas.tokens); - const rulerOffset = canvas.controls.ruler.rulerOffset; - const measurePosition = {x: mousePosition.x + rulerOffset.x, y: mousePosition.y + rulerOffset.y}; + const measurePosition = {x: mousePosition.x, y: mousePosition.y}; return measurePosition; } @@ -327,7 +325,5 @@ export function isPathfindingEnabled() { } function isCanvasHex() { - // isHexagonal is introduced in V12 (undefined in V11) - // isHex is deprecated since V12 - return canvas.grid.isHexagonal ?? canvas.grid.isHex + return canvas.grid.isHexagonal; }