Show distance labels for points placed by pathfinding

This commit is contained in:
Manuel Vögele
2022-01-28 23:55:58 +01:00
parent a404353d38
commit ce9bea14fc
+5 -1
View File
@@ -166,13 +166,17 @@ export function measure(destination, options={}) {
} }
// Remove waypoints generated by pathfinding // Remove waypoints generated by pathfinding
this.waypoints.filter(waypoint => waypoint.isPathfinding).forEach(_ => this.labels.removeChild(this.labels.children.pop()));
this.waypoints = this.waypoints.filter(waypoint => !waypoint.isPathfinding); this.waypoints = this.waypoints.filter(waypoint => !waypoint.isPathfinding);
if (isToken && options.pathfinding) { if (isToken && options.pathfinding) {
let path = findPath(getGridPositionFromPixelsObj(this.waypoints[this.waypoints.length - 1]), getGridPositionFromPixelsObj(destination)); let path = findPath(getGridPositionFromPixelsObj(this.waypoints[this.waypoints.length - 1]), getGridPositionFromPixelsObj(destination));
if (path) { if (path) {
path = path.map(point => getCenterFromGridPositionObj(point)); path = path.map(point => getCenterFromGridPositionObj(point));
path.forEach(point => point.isPathfinding = true); for (const point of path) {
point.isPathfinding = true;
this.labels.addChild(new PreciseText("", CONFIG.canvasTextStyle));
}
this.waypoints = this.waypoints.concat(path); this.waypoints = this.waypoints.concat(path);
} }
else { else {