-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlevels.js
61 lines (52 loc) · 1.21 KB
/
levels.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
56
57
58
59
60
61
function LevelsService(){
this.levels = {};
/**
* [addState description]
* @param {[type]} state [description]
* @param {[type]} level [description]
*/
this.addState = function(state, level){
if( !this.levels[level] )
this.levels[level] = [];
this.levels[level].push(state);
return true;
};
/**
* [getStates description]
* @param {[type]} level [description]
* @return {[type]} [description]
*/
this.getStates = function(level){
return this.levels[level];
}
/**
* [getLevelSize description]
* @param {[type]} level [description]
* @return {[type]} [description]
*/
this.getLevelSize = function(level){
if( !this.levels[level] )
return 0;
else
return this.levels[level].length;
};
/**
* [getMaxLevel description]
* @return {[type]} [description]
*/
this.getMaxLevel = function(){
var max = 0;
for (var key in this.levels)
if (this.levels.hasOwnProperty(key) && parseInt(key) > max)
max = parseInt(key);
return max;
};
/**
* [clear description]
* @return {[type]} [description]
*/
this.clear = function(){
this.levels = {};
};
}
module.exports = LevelsService;