yolkbot 0.1.0-alpha.57 → 0.1.0-alpha.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/browser.js +3 -3
- package/package.json +1 -1
- package/src/pathing/mapnode.js +24 -22
package/package.json
CHANGED
package/src/pathing/mapnode.js
CHANGED
|
@@ -20,49 +20,51 @@ class NodeList {
|
|
|
20
20
|
constructor(raw) {
|
|
21
21
|
const now = Date.now();
|
|
22
22
|
this.list = [];
|
|
23
|
-
|
|
24
|
-
const addedPositions = [];
|
|
23
|
+
const addedPositions = new Set();
|
|
25
24
|
|
|
26
25
|
for (const meshName of Object.keys(raw.data)) {
|
|
27
26
|
for (const nodeData of raw.data[meshName]) {
|
|
28
|
-
addedPositions.
|
|
27
|
+
addedPositions.add(`${nodeData.x},${nodeData.y},${nodeData.z}`);
|
|
29
28
|
this.add(new MapNode(meshName, nodeData));
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
// data doesn't include air, but we need to include them anyway
|
|
34
|
-
// addedPositions stores all the blocks with nodes - create a node for every block not in there.
|
|
35
|
-
// width/height/depth are given by raw.width/height/depth
|
|
36
32
|
for (let x = 0; x < raw.width; x++) {
|
|
37
33
|
for (let y = 0; y < raw.height; y++) {
|
|
38
34
|
for (let z = 0; z < raw.depth; z++) {
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
const posKey = `${x},${y},${z}`;
|
|
36
|
+
if (!addedPositions.has(posKey)) {
|
|
37
|
+
this.add(new MapNode('SPECIAL.__yolkbot_air__.none', { x: x, y: y, z: z }));
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
42
|
|
|
43
|
+
const nodeMap = new Map();
|
|
46
44
|
for (const node of this.list) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
45
|
+
nodeMap.set(node.positionStr(), node);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (const node of this.list) {
|
|
49
|
+
const neighbors = [
|
|
50
|
+
{ x: node.x + 1, y: node.y, z: node.z },
|
|
51
|
+
{ x: node.x - 1, y: node.y, z: node.z },
|
|
52
|
+
{ x: node.x, y: node.y + 1, z: node.z },
|
|
53
|
+
{ x: node.x, y: node.y - 1, z: node.z },
|
|
54
|
+
{ x: node.x, y: node.y, z: node.z + 1 },
|
|
55
|
+
{ x: node.x, y: node.y, z: node.z - 1 }
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
for (const neighborPos of neighbors) {
|
|
59
|
+
const neighborKey = `${neighborPos.x},${neighborPos.y},${neighborPos.z}`;
|
|
60
|
+
const neighborNode = nodeMap.get(neighborKey);
|
|
61
|
+
if (neighborNode && node.canLink(neighborNode, this)) {
|
|
62
|
+
node.addLink(neighborNode);
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
console.log(`NodeList created in ${Date.now() - now}ms`);
|
|
65
|
-
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
add(node) {
|