From 94fe223529169c4e6ec0649eab2f3bd3934db2d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Thu, 1 Apr 2021 00:07:26 +0200 Subject: [PATCH] Fix measurement errors when disabling token snapping while the Terrain Ruler module isn't enabled --- CHANGELOG.md | 6 ++++++ src/foundry_imports.js | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 722e611..3f4ac94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## In development +### Bugfixes +- Fixed a bug that could cause a meausred distance to be wrong when disabling token snapping using the shift key +- Fixed a bug where the highlighted path could have gaps when disabbling token snapping using the shift key + + ## 1.4.4 ### Bugfixes - Fix snapping for tokens that are smaller than 1x1 diff --git a/src/foundry_imports.js b/src/foundry_imports.js index a3c5f32..2d5d660 100644 --- a/src/foundry_imports.js +++ b/src/foundry_imports.js @@ -108,9 +108,14 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) { if (snap) destination = getSnapPointForToken(destination.x, destination.y, this.draggedToken) + const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS; + const waypoints = this.waypoints.concat([destination]); // Move the waypoints to the center of the grid if a size is used that measures from edge to edge const centeredWaypoints = applyTokenSizeOffset(waypoints, this.draggedToken) + // Foundries native ruler requires the waypoints to sit in the dead center of the square to work properly + if (!terrainRulerAvailable) + centeredWaypoints.forEach(w => [w.x, w.y] = canvas.grid.getCenter(w.x, w.y)); const r = this.ruler; this.destination = destination; @@ -133,10 +138,10 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) { centeredSegments.push({ray: centeredRay, label}) } + const shape = getTokenShape(this.draggedToken) // Compute measured distance - const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS let distances if (terrainRulerAvailable) distances = game.terrainRuler.measureDistances(centeredSegments, {costFunction: (x, y) => getCostFromSpeedProvider(this.draggedToken, getAreaFromPositionAndShape({x, y}, shape), {x, y})});