Fix errors

This commit is contained in:
Manuel Vögele
2022-01-29 23:33:59 +01:00
parent e2c7fd992b
commit 8f134a49ba
+6 -7
View File
@@ -42,16 +42,15 @@ function getNode(pos, initialize=true) {
pos = {layer: 0, ...pos}; // Copy pos and set pos.layer to the default value if it's unset pos = {layer: 0, ...pos}; // Copy pos and set pos.layer to the default value if it's unset
if (!cachedNodes) if (!cachedNodes)
cachedNodes = new Array(2); cachedNodes = new Array(2);
if (!cachedNodes[pos.layer]) { if (!cachedNodes[pos.layer])
cachedNodes[pos.layer] = new Array(Math.ceil(canvas.dimensions.height / canvas.grid.h)); cachedNodes[pos.layer] = new Array(Math.ceil(canvas.dimensions.height / canvas.grid.h));
} if (!cachedNodes[pos.layer][pos.y])
if (!cachedLayer[pos.layer][pos.y]) cachedNodes[pos.layer][pos.y] = new Array(Math.ceil(canvas.dimensions.width / canvas.grid.w));
cachedLayer[pos.layer][pos.y] = new Array(Math.ceil(canvas.dimensions.width / canvas.grid.w)); if (!cachedNodes[pos.layer][pos.y][pos.x]) {
if (!cachedLayer[pos.layer][pos.y][pos.x]) { cachedNodes[pos.layer][pos.y][pos.x] = pos;
cachedLayer[pos.layer][pos.y][pos.x] = pos;
} }
const node = cachedLayer[pos.layer][pos.y][pos.x]; const node = cachedNodes[pos.layer][pos.y][pos.x];
if (initialize && !node.edges) { if (initialize && !node.edges) {
node.edges = []; node.edges = [];
for (const neighborPos of neighbors(pos)) { for (const neighborPos of neighbors(pos)) {