From 85e167af453ab0456a727da348cdaca2e042e0b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Tue, 11 May 2021 18:21:39 +0200 Subject: [PATCH] Allow difficult terrain measurements on girdless maps --- CHANGELOG.md | 5 +++++ src/compatibility.js | 2 +- src/foundry_imports.js | 12 +++++++----- src/movement_tracking.js | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3827ecd..6777dec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ ## In development +**BREAKING** This update is incompatible with previous Terrain Ruler versions. If you're using Terrain Ruler, make sure you update Terrain Ruler to at least version 1.3.0. + +### New features +- Drag Ruler can now measure difficult terrain on gridless maps (if the Terrain Ruler module is installed and enabled) + ### Translation - Corrected typos in the german translation (thanks to CarnVanBeck!) diff --git a/src/compatibility.js b/src/compatibility.js index 0ac073d..6e80fb6 100644 --- a/src/compatibility.js +++ b/src/compatibility.js @@ -18,7 +18,7 @@ export function highlightMeasurementTerrainRuler(ray, startDistance, tokenShape= export function measureDistances(segments, token, shape, gridSpaces=true, options={}) { const opts = duplicate(options) opts.gridSpaces = gridSpaces; - const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS; + const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && (!game.modules.get("TerrainLayer")?.active || canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS); if (terrainRulerAvailable) { const firstNewSegmentIndex = segments.findIndex(segment => !segment.ray.dragRulerVisitedSpaces); const previousSegments = segments.slice(0, firstNewSegmentIndex); diff --git a/src/foundry_imports.js b/src/foundry_imports.js index 4cd416b..c3c39f5 100644 --- a/src/foundry_imports.js +++ b/src/foundry_imports.js @@ -130,7 +130,7 @@ 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 terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && (!game.modules.get("TerrainLayer")?.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 @@ -209,10 +209,12 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) { } // Highlight grid positions - if (terrainRulerAvailable) - highlightMeasurementTerrainRuler.call(this, cs.ray, cs.startDistance, shape, opacityMultiplier) - else - highlightMeasurementNative.call(this, cs.ray, cs.startDistance, shape, opacityMultiplier); + if (canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS) { + if (terrainRulerAvailable) + highlightMeasurementTerrainRuler.call(this, cs.ray, cs.startDistance, shape, opacityMultiplier) + else + highlightMeasurementNative.call(this, cs.ray, cs.startDistance, shape, opacityMultiplier); + } } // Draw endpoints diff --git a/src/movement_tracking.js b/src/movement_tracking.js index 2575bcb..03e078d 100644 --- a/src/movement_tracking.js +++ b/src/movement_tracking.js @@ -49,7 +49,7 @@ function calculateUpdate(combat, token, rays) { } // Add the passed waypoints to the combatant - const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS; + const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && (!game.modules.get("TerrainLayer")?.active || canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS); const dragRulerFlags = combatant.flags.dragRuler; const waypoints = dragRulerFlags.passedWaypoints; for (const ray of rays) {