If Terran Ruler is enabled, store the length of the traveled path so changes to difficult terrain aren't reflected in the tokens movement history
This commit is contained in:
+18
-5
@@ -14,10 +14,23 @@ export function highlightMeasurementTerrainRuler(ray, startDistance, tokenShape=
|
||||
}
|
||||
}
|
||||
|
||||
export function measureDistances(segments, token, shape, gridSpaces=true) {
|
||||
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;
|
||||
if (terrainRulerAvailable)
|
||||
return terrainRuler.measureDistances(segments, {costFunction: (x, y) => getCostFromSpeedProvider(token, getAreaFromPositionAndShape({x, y}, shape), {x, y})});
|
||||
else
|
||||
return canvas.grid.measureDistances(segments, { gridSpaces });
|
||||
if (terrainRulerAvailable) {
|
||||
const firstNewSegmentIndex = segments.findIndex(segment => !segment.ray.dragRulerVisitedSpaces);
|
||||
const previousSegments = segments.slice(0, firstNewSegmentIndex);
|
||||
const newSegments = segments.slice(firstNewSegmentIndex);
|
||||
const distances = previousSegments.map(segment => segment.ray.dragRulerVisitedSpaces[segment.ray.dragRulerVisitedSpaces.length - 1].distance);
|
||||
previousSegments.forEach(segment => segment.ray.terrainRulerVisitedSpaces = duplicate(segment.ray.dragRulerVisitedSpaces));
|
||||
opts.costFunction = (x, y) => getCostFromSpeedProvider(token, getAreaFromPositionAndShape({x, y}, shape), {x, y});
|
||||
if (previousSegments.length > 0)
|
||||
opts.terrainRulerInitialState = previousSegments[previousSegments.length - 1];
|
||||
return distances.concat(terrainRuler.measureDistances(newSegments, opts));
|
||||
}
|
||||
else {
|
||||
return canvas.grid.measureDistances(segments, options);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user