From ac00aac85b02f69f360e582e829fc52a0bcf3d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Fri, 30 Sep 2022 22:28:04 +0200 Subject: [PATCH] Gracefully handle situations where no path exists --- src/ruler.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ruler.js b/src/ruler.js index b0715e1..f5d7362 100644 --- a/src/ruler.js +++ b/src/ruler.js @@ -121,7 +121,7 @@ export function extendRuler() { return routinglib .calculatePath(from, to, {token: this.draggedEntity}) - .then(result => this.addPathToWaypoints(result.path)) + .then(result => this.addPathToWaypoints(result?.path)) .then(() => this.performPostPathfindingActions(options)); } @@ -129,6 +129,14 @@ export function extendRuler() { } addPathToWaypoints(path) { + if (!path) { + // TODO Show an indicator informing that there is no path + + // Don't show a path if the pathfinding yields no result to show the user that the destination is unreachable + this.destination = this.waypoints[this.waypoints.length - 1]; + return; + } + path = path.map(point => getSnapPointForTokenObj(getPixelsFromGridPositionObj(point), this.draggedEntity), );