Skip to content

Commit e93574b

Browse files
author
Daniel
committed
-Add ability to enable diagonal per gridNode
1 parent e060a37 commit e93574b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

astar.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ var astar = {
8888
currentNode.closed = true;
8989

9090
// Find all neighbors for the current node. Optionally find diagonal neighbors as well (false by default).
91-
var neighbors = astar.neighbors(grid, currentNode, diagonal);
91+
var diagonalThisNode = false;
92+
if (diagonal == true) {
93+
diagonalThisNode = (currentNode.options.diagonal != null) ? currentNode.options.diagonal : true;
94+
}
95+
var neighbors = astar.neighbors(grid, currentNode, diagonalThisNode);
9296

9397
for(var i=0, il = neighbors.length; i < il; i++) {
9498
var neighbor = neighbors[i];
@@ -215,7 +219,7 @@ function Graph(grid) {
215219
nodes[x] = [];
216220

217221
for (var y = 0, row = grid[x]; y < row.length; y++) {
218-
nodes[x][y] = new GraphNode(x, y, row[y]);
222+
nodes[x][y] = new GraphNode(x, y, row[y].cost, row[y].options);
219223
}
220224
}
221225

@@ -238,7 +242,7 @@ Graph.prototype.toString = function() {
238242
return graphString;
239243
};
240244

241-
function GraphNode(x, y, type) {
245+
function GraphNode(x, y, type, options) {
242246
this.data = { };
243247
this.x = x;
244248
this.y = y;
@@ -247,6 +251,7 @@ function GraphNode(x, y, type) {
247251
y: y
248252
};
249253
this.type = type;
254+
this.options = options || {};
250255
}
251256

252257
GraphNode.prototype.toString = function() {

0 commit comments

Comments
 (0)