-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
79 lines (64 loc) · 1.96 KB
/
Copy pathutils.js
File metadata and controls
79 lines (64 loc) · 1.96 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
This class has a bunch of utility functions
TODO:
-clean up globalDistance
*/
var role_proto = require('prototype.role');
var utils={
globalDistance:function(pos1,pos2){
// takes in two room pos arguments and returns their global distance
var room1replaced = pos1.roomName.replace(/[ENSW]/g, function(s) { return ","+s+",";});
var room1= room1replaced.split(",");
var room2replaced = pos2.roomName.replace(/[ENSW]/g, function(s) { return ","+s+",";});
var room2= room2replaced.split(",");
var x1,y1,xDirection1,yDirection1,x1RoomNum,y1RoomNum;
var x2,y2,xDirection2,yDirection2,x2RoomNum,y2RoomNum;
if (room1[1]=="E"){
xDirection1=1;
}else{
xDirection1=-1;
}
if (room1[3]=="N"){
yDirection1=1;
}else{
yDirection1=-1;
}
if (room2[1]=="E"){
xDirection2=1;
}else{
xDirection2=-1;
}
if (room2[3]=="N"){
yDirection2=1;
}else{
yDirection2=-1;
}
x1RoomNum= room1[2];y1RoomNum= room1[4];
x2RoomNum= room2[2];y2RoomNum= room2[4];
x1 = 50*x1RoomNum*xDirection1 +pos1.x;
y1 = 50*y1RoomNum*yDirection1 +pos1.y;
x2 = 50*x2RoomNum*xDirection2 +pos2.x;
y2 = 50*y2RoomNum*yDirection2 +pos2.y;
return Math.sqrt(Math.pow(x1-x2,2) +Math.pow(y1-y2,2));
},
roleExists: function(role){
try
{
require("role." + role);
return true;
}
catch(e)
{
console.log("role exist error"+e);
return false;
}
},
getRole: function(role){
if(!this.roleExists(role))
return false;
var roleObject = require("role." + role);
roleObject = Object.assign( role_proto,roleObject);
return roleObject;
}
};
module.exports= utils;