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 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..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} */ @@ -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];