Properly store terrain ruler's state in the movement history
This commit is contained in:
@@ -4,6 +4,9 @@
|
|||||||
### New features
|
### New features
|
||||||
- Drag Ruler can now measure difficult terrain on gridless maps (if the Terrain Ruler module is installed and enabled)
|
- Drag Ruler can now measure difficult terrain on gridless maps (if the Terrain Ruler module is installed and enabled)
|
||||||
|
|
||||||
|
### Bugfixes
|
||||||
|
- Fixed a bug that sometimes measured diagonals incorrectly with the 5/10/5 grid rule
|
||||||
|
|
||||||
### Translation
|
### Translation
|
||||||
- Corrected typos in the german translation (thanks to CarnVanBeck!)
|
- Corrected typos in the german translation (thanks to CarnVanBeck!)
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,12 @@ export function highlightMeasurementTerrainRuler(ray, startDistance, tokenShape=
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function measureDistances(segments, token, shape, gridSpaces=true, options={}) {
|
export function measureDistances(segments, token, shape, options={}) {
|
||||||
const opts = duplicate(options)
|
const opts = duplicate(options)
|
||||||
opts.gridSpaces = gridSpaces;
|
if (!opts.gridSpaces)
|
||||||
|
opts.gridSpaces = true;
|
||||||
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && (!game.modules.get("TerrainLayer")?.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) {
|
if (terrainRulerAvailable) {
|
||||||
const firstNewSegmentIndex = segments.findIndex(segment => !segment.ray.dragRulerVisitedSpaces);
|
const firstNewSegmentIndex = segments.findIndex(segment => !segment.ray.dragRulerVisitedSpaces);
|
||||||
const previousSegments = segments.slice(0, firstNewSegmentIndex);
|
const previousSegments = segments.slice(0, firstNewSegmentIndex);
|
||||||
@@ -27,7 +29,7 @@ export function measureDistances(segments, token, shape, gridSpaces=true, option
|
|||||||
previousSegments.forEach(segment => segment.ray.terrainRulerVisitedSpaces = duplicate(segment.ray.dragRulerVisitedSpaces));
|
previousSegments.forEach(segment => segment.ray.terrainRulerVisitedSpaces = duplicate(segment.ray.dragRulerVisitedSpaces));
|
||||||
opts.costFunction = (x, y) => getCostFromSpeedProvider(token, getAreaFromPositionAndShape({x, y}, shape), {x, y});
|
opts.costFunction = (x, y) => getCostFromSpeedProvider(token, getAreaFromPositionAndShape({x, y}, shape), {x, y});
|
||||||
if (previousSegments.length > 0)
|
if (previousSegments.length > 0)
|
||||||
opts.terrainRulerInitialState = previousSegments[previousSegments.length - 1];
|
opts.terrainRulerInitialState = previousSegments[previousSegments.length - 1].ray.dragRulerFinalState;
|
||||||
return distances.concat(terrainRuler.measureDistances(newSegments, opts));
|
return distances.concat(terrainRuler.measureDistances(newSegments, opts));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -83,4 +85,3 @@ export function checkDependencies() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,6 +156,8 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) {
|
|||||||
centeredRay.isPrevious = ray.isPrevious;
|
centeredRay.isPrevious = ray.isPrevious;
|
||||||
ray.dragRulerVisitedSpaces = origin.dragRulerVisitedSpaces;
|
ray.dragRulerVisitedSpaces = origin.dragRulerVisitedSpaces;
|
||||||
centeredRay.dragRulerVisitedSpaces = ray.dragRulerVisitedSpaces;
|
centeredRay.dragRulerVisitedSpaces = ray.dragRulerVisitedSpaces;
|
||||||
|
ray.dragRulerFinalState = origin.dragRulerFinalState;
|
||||||
|
centeredRay.dragRulerFinalState = ray.dragRulerFinalState;
|
||||||
if (ray.distance < 10) {
|
if (ray.distance < 10) {
|
||||||
if (label) label.visible = false;
|
if (label) label.visible = false;
|
||||||
continue;
|
continue;
|
||||||
@@ -168,7 +170,7 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) {
|
|||||||
const shape = getTokenShape(this.draggedToken)
|
const shape = getTokenShape(this.draggedToken)
|
||||||
|
|
||||||
// Compute measured distance
|
// Compute measured distance
|
||||||
const distances = measureDistances(centeredSegments, this.draggedToken, shape, gridSpaces);
|
const distances = measureDistances(centeredSegments, this.draggedToken, shape, {gridSpaces});
|
||||||
|
|
||||||
let totalDistance = 0;
|
let totalDistance = 0;
|
||||||
for (let [i, d] of distances.entries()) {
|
for (let [i, d] of distances.entries()) {
|
||||||
|
|||||||
@@ -56,9 +56,9 @@ function calculateUpdate(combat, token, rays) {
|
|||||||
// Ignore rays that have the same start and end coordinates
|
// Ignore rays that have the same start and end coordinates
|
||||||
if (ray.A.x !== ray.B.x || ray.A.y !== ray.B.y) {
|
if (ray.A.x !== ray.B.x || ray.A.y !== ray.B.y) {
|
||||||
if (terrainRulerAvailable) {
|
if (terrainRulerAvailable) {
|
||||||
measureDistances([{ray}], token, getTokenShape(token), true, {terrainRulerInitialState: dragRulerFlags.rulerState});
|
measureDistances([{ray}], token, getTokenShape(token), {terrainRulerInitialState: waypoints[waypoints.length - 1]?.dragRulerFinalState});
|
||||||
ray.A.dragRulerVisitedSpaces = ray.terrainRulerVisitedSpaces;
|
ray.A.dragRulerVisitedSpaces = ray.terrainRulerVisitedSpaces;
|
||||||
dragRulerFlags.rulerState = ray.terrainRulerFinalState;
|
ray.A.dragRulerFinalState = ray.terrainRulerFinalState;
|
||||||
}
|
}
|
||||||
waypoints.push(ray.A);
|
waypoints.push(ray.A);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user