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 diff --git a/js/pathfinding.js b/js/pathfinding.js index b9ca834..46bf512 100644 --- a/js/pathfinding.js +++ b/js/pathfinding.js @@ -252,7 +252,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); @@ -307,12 +308,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; @@ -465,6 +466,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); } 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", {