-
Notifications
You must be signed in to change notification settings - Fork 1
/
Util.js
executable file
·45 lines (35 loc) · 845 Bytes
/
Util.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
exports.equalsEpsilon = function(val1, val2, epsilon)
{
if(epsilon == undefined)
epsilon = 0.001;
return ((val1 + epsilon) > val2 && (val1 - epsilon) < val2);
}
exports.stringifyTerritory = function(t)
{
return JSON.stringify(t,
function(key, value)
{
if (key == "taggedToPlayer" || key == "player" || key == "simulation")
return;
return value;
}, "\t"
);
}
// ref: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
};
exports.guid = function() {
return s4() + s4() + s4();
}
var pastGuid = [];
exports.uniqueGuid = function()
{
var guid;
do { guid = exports.guid(); }
while(pastGuid.indexOf(guid) > -1);
pastGuid.push(guid);
return guid;
}