Cancel running pathfinding jobs before scheduling a new one

This commit is contained in:
Manuel Vögele
2022-09-30 22:47:51 +02:00
parent ac00aac85b
commit 25fc6258e7
+12 -5
View File
@@ -110,19 +110,26 @@ export function extendRuler() {
if (d.x === this.destination.x && d.y === this.destination.y) return;
this.destination = d;
// TODO Cancel running pathfinding operations
// TODO Check if we can reuse the old path
this.dragRulerRemovePathfindingWaypoints();
if (this.pathfindingJob) {
routinglib.cancelPathfinding(this.pathfindingJob);
this.pathfindingJob = undefined;
}
if (isToken && isPathfindingEnabled.call(this)) {
// TODO Show a busy indicator
const from = getGridPositionFromPixelsObj(this.waypoints[this.waypoints.length - 1]);
const to = getGridPositionFromPixelsObj(destination);
return routinglib
.calculatePath(from, to, {token: this.draggedEntity})
.then(result => this.addPathToWaypoints(result?.path))
.then(() => this.performPostPathfindingActions(options));
const pathfindingJob = routinglib.calculatePath(from, to, {token: this.draggedEntity});
this.pathfindingJob = pathfindingJob;
return this.pathfindingJob.then(result => {
if (pathfindingJob === this.pathfindingJob) {
this.addPathToWaypoints(result?.path);
return this.performPostPathfindingActions(options);
}
});
}
return this.performPostPathfindingActions(options);