-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (50 loc) · 1.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class NodeDetour {
constructor() {
var addon = require('bindings')('addon');
this.pathfinder = new addon.Pathfinder();
}
loadBin(path) {
let full_path = require('path').resolve(path);
let result = this.pathfinder.LoadBin(full_path);
switch(result) {
case 1: return { error: false };
case 2: return { error: true, message: "Could not open file" };
case 3: return { error: true, message: "Could not read header" };
case 4: return { error: true, message: "Header magic value incorrect" };
case 5: return { error: true, message: "Header version incorrect" };
case 6: return { error: true, message: "Could not allocate mesh object" };
case 7: return { error: true, message: "Could not initialize mesh" };
case 8: return { error: true, message: "Could not open tile header" };
case 9: return { error: true, message: "Could not read tile header data" };
}
}
findPath(p1, p2) {
var result = this.pathfinder.FindPath(p1[0], p1[1], p1[2], p2[0], p2[1], p2[2]);
if(result == 0) {
throw "An error occurred finding a path. Make sure you have loaded a valid binary navmesh.";
return;
}
return result;
}
findPath2d(p1, p2) {
var array = this.pathfinder.FindPath(p1[0], p1[1], p1[2], p2[0], p2[1], p2[2]);
if(array == 0) {
throw "An error occurred finding a path. Make sure you have loaded a valid binary navmesh.";
return;
}
var result = [];
for(var i = 0; i < array.length; i+= 3) {
result.push([array[i], array[i+1], array[i+2]]);
}
return result;
}
findRandomPoint() {
var result = this.pathfinder.FindRandomPoint();
if(result == 0) {
throw "An error occurred finding a random point. Make sure you have loaded a valid binary navmesh.";
return;
}
return result;
}
}
module.exports = NodeDetour;