forked from zhaolinxu/SpaceCompany
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rocket.js
60 lines (51 loc) · 1.8 KB
/
rocket.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
Game.interstellar.rocket = (function(){
var instance = {};
instance.entries = {};
instance.categoryEntries = {};
instance.entries = {};
instance.initialise = function(){
for (var id in Game.rocketData) {
var data = Game.rocketData[id];
this.navCount++;
this.entries[id] = $.extend({}, data, {
id: id,
htmlId: 'roc_' + id,
count: 0,
displayNeedsUpdate: true
});
}
}
instance.updateCost = function(entryName){
var data = this.entries[entryName];
for(var part in data.cost){
var target = 0;
for(var i = 0; i < Object.keys(Game.interstellarUI.rocketPartObservers[entryName]).length; i++){
if(part == Game.interstellarUI.rocketPartObservers[entryName][i].part){
Game.interstellarUI.rocketPartObservers[entryName][i].value = data.cost[part.toString()];
}
}
}
}
instance.buildRocket = function(entryName){
var partPass = 0;
for(var part in this.entries[entryName].cost){
if(Game.interstellar.rocketParts.entries[part].count >= this.entries[entryName].cost[part]){
partPass += 1;
}
}
if(partPass === Object.keys(Game.interstellar.rocket.entries[entryName].cost).length){
for(var part in this.entries[entryName].cost){
}
this.entries[entryName].built = true;
this.entries[entryName].displayNeedsUpdate = true;
}
}
instance.unlock = function(id) {
this.entries[id].unlocked = true;
this.entries[id].displayNeedsUpdate = true;
};
instance.getRocketData = function(id) {
return this.entries[id];
};
return instance;
}());