yolkbot 0.1.0-alpha.56 → 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "yolkbot",
3
3
  "description": "create a shell shockers (self) bot in under 10 lines.",
4
- "version": "0.1.0-alpha.56",
4
+ "version": "0.1.0-alpha.58",
5
5
  "keywords": [
6
6
  "shell shockers",
7
7
  "shellshock.io",
@@ -16,57 +16,55 @@
16
16
  }, 4);
17
17
  }*/
18
18
 
19
- import fs from 'node:fs';
20
-
21
- let timesCalledAt = 0;
22
-
23
19
  class NodeList {
24
20
  constructor(raw) {
25
21
  const now = Date.now();
26
22
  this.list = [];
27
-
28
- const addedPositions = [];
23
+ const addedPositions = new Set();
29
24
 
30
25
  for (const meshName of Object.keys(raw.data)) {
31
26
  for (const nodeData of raw.data[meshName]) {
32
- addedPositions.push(nodeData);
27
+ addedPositions.add(`${nodeData.x},${nodeData.y},${nodeData.z}`);
33
28
  this.add(new MapNode(meshName, nodeData));
34
29
  }
35
30
  }
36
31
 
37
- // data doesn't include air, but we need to include them anyway
38
- // addedPositions stores all the blocks with nodes - create a node for every block not in there.
39
- // width/height/depth are given by raw.width/height/depth
40
32
  for (let x = 0; x < raw.width; x++) {
41
33
  for (let y = 0; y < raw.height; y++) {
42
34
  for (let z = 0; z < raw.depth; z++) {
43
- if (!addedPositions.find(node => node.x == x && node.y == y && node.z == z)) {
44
- this.add(new MapNode('SPECIAL.fuckitweball.none', { x: x, y: y, z: z }));
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 }));
45
38
  }
46
39
  }
47
40
  }
48
41
  }
49
42
 
43
+ const nodeMap = new Map();
50
44
  for (const node of this.list) {
51
- // add all nodes around it
52
- for (const other of this.list) {
53
- const dx = Math.abs(node.x - other.x);
54
- const dy = Math.abs(node.y - other.y);
55
- const dz = Math.abs(node.z - other.z);
56
- if (dx > 1 || dy > 1 || dz > 1) {
57
- continue;
58
- }
59
- if (other == this) {
60
- continue;
61
- }
62
- if (node.canLink(other, this)) {
63
- node.addLink(other);
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);
64
63
  }
65
64
  }
66
65
  }
67
66
 
68
67
  console.log(`NodeList created in ${Date.now() - now}ms`);
69
-
70
68
  }
71
69
 
72
70
  add(node) {
@@ -78,10 +76,16 @@ class NodeList {
78
76
  }
79
77
 
80
78
  at(x, y, z) {
81
- timesCalledAt++;
82
- fs.writeFileSync('/Users/user/.yolkbot/cocaine.txt', timesCalledAt);
79
+ if (!this.nodeMap) {
80
+ this.nodeMap = new Map();
81
+ for (const node of this.list) {
82
+ const key = `${node.x},${node.y},${node.z}`;
83
+ this.nodeMap.set(key, node);
84
+ }
85
+ }
86
+
83
87
  const key = `${x},${y},${z}`;
84
- return this.list.find(node => node.positionStr() == key);
88
+ return this.nodeMap.get(key);
85
89
  }
86
90
 
87
91
  clean() {