Fix measurement errors when disabling token snapping while the Terrain Ruler module isn't enabled

This commit is contained in:
Manuel Vögele
2021-04-01 00:07:26 +02:00
parent 942bfa04e8
commit 94fe223529
2 changed files with 12 additions and 1 deletions
+6
View File
@@ -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 ## 1.4.4
### Bugfixes ### Bugfixes
- Fix snapping for tokens that are smaller than 1x1 - Fix snapping for tokens that are smaller than 1x1
+6 -1
View File
@@ -108,9 +108,14 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) {
if (snap) if (snap)
destination = getSnapPointForToken(destination.x, destination.y, this.draggedToken) 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]); 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 // 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) 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; const r = this.ruler;
this.destination = destination; this.destination = destination;
@@ -133,10 +138,10 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) {
centeredSegments.push({ray: centeredRay, label}) centeredSegments.push({ray: centeredRay, label})
} }
const shape = getTokenShape(this.draggedToken) const shape = getTokenShape(this.draggedToken)
// Compute measured distance // Compute measured distance
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS
let distances let distances
if (terrainRulerAvailable) if (terrainRulerAvailable)
distances = game.terrainRuler.measureDistances(centeredSegments, {costFunction: (x, y) => getCostFromSpeedProvider(this.draggedToken, getAreaFromPositionAndShape({x, y}, shape), {x, y})}); distances = game.terrainRuler.measureDistances(centeredSegments, {costFunction: (x, y) => getCostFromSpeedProvider(this.draggedToken, getAreaFromPositionAndShape({x, y}, shape), {x, y})});