-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_stats.js
119 lines (105 loc) · 2.42 KB
/
game_stats.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
function GameStats()
{
this.gamestats = new Object();
this.gamestatmorphers = new Object();
};
GameStats.prototype.setStatsData = function(data)
{
delete this.gamestats;
this.gamestats = data;
};
GameStats.prototype.setGameStat = function(stat, value)
{
this.gamestats[stat] = value;
};
GameStats.prototype.setGameStatMorpher = function(stat, morpher)
{
this.gamestatmorphers[stat] = morpher;
};
GameStats.prototype.setGameStatValueAndMorpher = function(stat, value, morpher)
{
this.setGameStat(stat, value);
this.setGameStatMorpher(stat, morpher);
};
GameStats.prototype.removeGameStat = function(stat)
{
if (this.gamestats.hasOwnProperty(stat))
{
delete this.gamestats[stat];
}
};
GameStats.prototype.removeGameStatMorpher = function(stat)
{
if (this.gamestatmorphers.hasOwnProperty(stat))
{
delete this.gamestatmorphers[stat];
}
};
GameStats.prototype.removeGameStatAndMorpher = function(stat)
{
this.removeGameStat(stat);
this.removeGameStatMorpher(stat);
};
GameStats.prototype.getRawStat = function(stat)
{
if (this.gamestats.hasOwnProperty(stat))
{
return this.gamestats[stat];
}
};
GameStats.prototype.getStat = function(stat)
{
var val = this.getRawStat(stat);
return this.getStatFromRaw(stat, val);
};
GameStats.prototype.getStatFromRaw = function(stat, val)
{
if (this.gamestatmorphers.hasOwnProperty(stat))
{
return this.gamestatmorphers[stat](val);
}
else
{
return val;
}
};
GameStats.prototype.applyStatToHTMLElement = function(stat, element)
{
var j = 0;
if (this.gamestats.hasOwnProperty(stat))
{
var elems = element.querySelectorAll("#" + stat + ".stat");
var val = this.gamestats[stat];
for (i = 0; i < elems.length; i++)
{
elems[i].textContent = this.getStatFromRaw(stat, val);
j++;
}
elems = element.querySelectorAll("#" + stat + ".rawstat");
for (i = 0; i < elems.length; i++)
{
elems[i].textContent = val;
j++;
}
}
return j;
};
GameStats.prototype.setGameStatWithHTMLUpdate = function(stat, value, element)
{
this.setGameStat(stat, value);
this.applyStatToHTMLElement(stat, element);
};
GameStats.prototype.setGameStatAndMorpherWithHTMLUpdate = function(stat, value, morpher, element)
{
this.setGameStatValueAndMorpher(stat, value, morpher);
this.applyStatToHTMLElement(stat, element);
};
GameStats.prototype.applyStatsToHTMLElement = function(element)
{
var j = 0;
for (var stat in this.gamestats)
{
j += this.applyStatToHTMLElement(stat, element);
}
return j;
};