From 1b8b2328c64cfdfffd846f98df315a81adec3451 Mon Sep 17 00:00:00 2001 From: Cole Schultz Date: Fri, 29 Apr 2022 03:41:05 -0500 Subject: [PATCH 1/4] Add the pathfinding radius setting (#194) --- js/pathfinding.js | 3 ++- js/settings.js | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/js/pathfinding.js b/js/pathfinding.js index dc006e7..8bedacb 100644 --- a/js/pathfinding.js +++ b/js/pathfinding.js @@ -240,7 +240,8 @@ export function findPath(from, to, token, previousWaypoints) { let tokenSize = Math.max(token.data.width, token.data.height) * canvas.dimensions.size; let pathfinder = gridlessPathfinders.get(tokenSize); if (!pathfinder) { - pathfinder = GridlessPathfinding.initialize(canvas.walls.placeables, tokenSize, token.data.elevation, Boolean(game.modules.get("wall-height")?.active)); + let radiusMultiplier = game.settings.get(settingsKey, "pathfindingRadius"); + pathfinder = GridlessPathfinding.initialize(canvas.walls.placeables, tokenSize * radiusMultiplier, token.data.elevation, Boolean(game.modules.get("wall-height")?.active)); gridlessPathfinders.set(tokenSize, pathfinder); } paintGridlessPathfindingDebug(pathfinder); diff --git a/js/settings.js b/js/settings.js index 5eaa99f..f4293f2 100644 --- a/js/settings.js +++ b/js/settings.js @@ -1,5 +1,6 @@ import {availableSpeedProviders, currentSpeedProvider, getDefaultSpeedProvider, updateSpeedProvider} from "./api.js"; import {SpeedProvider} from "./speed_provider.js" +import {wipePathfindingCache} from "./pathfinding.js" import { early_isGM } from "./util.js"; export const settingsKey = "drag-ruler"; @@ -100,10 +101,18 @@ export function registerSettings() { game.settings.register(settingsKey, "autoPathfinding", { name: "drag-ruler.settings.autoPathfinding.name", hint: "drag-ruler.settings.autoPathfinding.hint", - scpoe: "client", + scope: "client", config: early_isGM() || game.settings.get(settingsKey, "allowPathfinding"), type: Boolean, - defualt: false, + default: false, + }); + + game.settings.register(settingsKey, "pathfindingRadius", { + scope: "world", + config: false, + type: Number, + default: 0.9, + onChange: wipePathfindingCache, }); game.settings.register(settingsKey, "lastTerrainRulerHintTime", { From 1577435a337749541ccaae1714a500c30bcfed47 Mon Sep 17 00:00:00 2001 From: Jonathan Calvert <38069151+JDCalvert@users.noreply.github.com> Date: Fri, 6 May 2022 19:16:52 +0100 Subject: [PATCH 2/4] Fix issue caused by client setting moving from Levels to Wall Height (#195) --- js/pathfinding.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js/pathfinding.js b/js/pathfinding.js index 8bedacb..cad2851 100644 --- a/js/pathfinding.js +++ b/js/pathfinding.js @@ -272,12 +272,12 @@ function buildTokenData(token) { // Almost all the information we need is for calculating the snap point const tokenData = buildSnapPointTokenData(token); - // If levels is enabled, which walls matter depends on the token's elevation. - // Depending on the settings in levels, the height we care about is either their - // Foot height (elevation) or eye height (losHeight). - if (isModuleActive("levels")) { - const blockSightMovement = game.settings.get(_levelsModuleName, "blockSightMovement"); - tokenData.elevation = blockSightMovement ? token.data.elevation : token.losHeight; + // If Wall Height is enabled, which walls matter depends on the token's elevation. + // Depending on the settings in Wall Height, the height we care about is either their + // foot height (elevation) or eye height (losHeight). + if (isModuleActive("wall-height")) { + const blockSightMovement = game.settings.get("wall-height", "blockSightMovement"); + tokenData.elevation = blockSightMovement ? token.losHeight : token.data.elevation; } return tokenData; From d325f8aceea13764f8a25b1132b1f795038eee9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Fri, 6 May 2022 20:22:42 +0200 Subject: [PATCH 3/4] Don't attempt to start background caching on gridless scenes, as it's currently unsupported (fixes #196) --- js/pathfinding.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/js/pathfinding.js b/js/pathfinding.js index cad2851..befb7ed 100644 --- a/js/pathfinding.js +++ b/js/pathfinding.js @@ -416,6 +416,9 @@ export function initializePathfinding() { } export function startBackgroundCaching(token) { + // Background caching isn't yet supported for gridless scenes + if (canvas.grid.type === CONST.GRID_TYPES.GRIDLESS) + return; if (game.user.isGM || game.settings.get(settingsKey, "allowPathfinding")) { cache.startBackgroundCaching(token); } From 5904efbdd51166373c2fc780e84b896686fd06e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Sat, 7 May 2022 08:12:30 +0200 Subject: [PATCH 4/4] Remove redundant first waypoint from path generated by pathfinder This fixes a bug where gridless snapping would snap slightly below the target range --- js/foundry_imports.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/foundry_imports.js b/js/foundry_imports.js index 79a90b2..2e96cab 100644 --- a/js/foundry_imports.js +++ b/js/foundry_imports.js @@ -175,7 +175,9 @@ export function measure(destination, options={}) { const from = getGridPositionFromPixelsObj(this.waypoints[this.waypoints.length - 1]); const to = getGridPositionFromPixelsObj(destination); let path = findPath(from, to, this.draggedEntity, this.waypoints); - if (path) { + if (path) + path.shift(); + if (path && path.length > 0) { path = path.map(point => getSnapPointForTokenObj(getPixelsFromGridPositionObj(point), this.draggedEntity)); // If the token is snapped to the grid, the first point of the path is already handled by the ruler