From b60550fdd4a7271d9f51a688d9ba83e22ce80ed2 Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Fri, 16 Feb 2024 09:34:32 -0800 Subject: [PATCH 1/3] Fix for pathfinding slipping through cracks If no objects present, isOpenDoor was returning true when it should be false. --- scripts/pathfinding/BorderTriangle.js | 8 +++++--- scripts/pathfinding/pathfinding.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/pathfinding/BorderTriangle.js b/scripts/pathfinding/BorderTriangle.js index 36d872e..8ca16d0 100644 --- a/scripts/pathfinding/BorderTriangle.js +++ b/scripts/pathfinding/BorderTriangle.js @@ -119,12 +119,14 @@ export class BorderEdge { /** * Determine if this is an open door with nothing else blocking. - * @returns {boolean} + * @type {boolean} */ - isOpenDoor() { + get isOpenDoor() { + if ( !this.objects.size ) return false; + const { moveToken, tokenBlockType } = this.constructor; return this.objects.every(obj => (obj instanceof Wall) ? obj.isOpen - : (obj instanceof Token ) ? !this._tokenEdgeBlocks(obj) + : (obj instanceof Token ) ? !WallTracerEdge.tokenEdgeBlocks(obj, moveToken, tokenBlockType) : true); } diff --git a/scripts/pathfinding/pathfinding.js b/scripts/pathfinding/pathfinding.js index ab9b313..79c647e 100644 --- a/scripts/pathfinding/pathfinding.js +++ b/scripts/pathfinding/pathfinding.js @@ -343,6 +343,20 @@ export class Pathfinder { return pts.reverse(); } + /** + * Identify triangles for a path in order. + * @returns {BorderTriangle[]} + */ + static getPathTriangles(pathMap) { + let curr = pathMap.goal; + const tri = []; + while ( curr && tri.length < 1000 ) { + tri.push(curr) + curr = pathMap.get(curr.key); + } + return tri.reverse(); + } + drawPath(pathPoints, opts) { const nPts = pathPoints.length; let prior = pathPoints[0]; From 74703c723bada4f0fe6a41eeb63c50a0281945d2 Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Fri, 16 Feb 2024 09:37:36 -0800 Subject: [PATCH 2/3] Use the minimum of width and height of token --- scripts/pathfinding/pathfinding.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/pathfinding/pathfinding.js b/scripts/pathfinding/pathfinding.js index 79c647e..c823668 100644 --- a/scripts/pathfinding/pathfinding.js +++ b/scripts/pathfinding/pathfinding.js @@ -192,7 +192,7 @@ export class Pathfinder { _spacer = 0; get spacer() { - return this._spacer || (this.token.w * 0.5) || (canvas.dimensions.size * 0.5); + return this._spacer || (Math.min(this.token.w, this.token.h) * 0.5) || (canvas.dimensions.size * 0.5); } /** @enum {BreadthFirstPathSearch} */ @@ -351,7 +351,7 @@ export class Pathfinder { let curr = pathMap.goal; const tri = []; while ( curr && tri.length < 1000 ) { - tri.push(curr) + tri.push(curr); curr = pathMap.get(curr.key); } return tri.reverse(); From d7c17fdfb007e4e7498b0b28b6e57b0cb8e2670e Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Fri, 16 Feb 2024 09:37:40 -0800 Subject: [PATCH 3/3] Update changelog --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index ffd9d03..aa1a296 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,6 @@ +# 0.8.6 +Fix for pathfinding slipping through small cracks between walls. Unless the wall is a door, the path should be limited to half the token min(width, height). + # 0.8.5 ## New Features