-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuilding.js
More file actions
103 lines (85 loc) · 2.98 KB
/
Copy pathBuilding.js
File metadata and controls
103 lines (85 loc) · 2.98 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//Class and subclasses for all types of buildings
//Top Level, Abstract class
var Building = {
buildingData: null,
loadBuildingData: function(){
if(Building.buildingData===null){
console.log("[Building] loading building data...");
Building.buildingData=MainGame.game.cache.getJSON('buildingData');
console.log("[Building] OK.");
}
},
createNew: function(data){
//console.log("[Building] createNew, the building's textureKey must be name.");
// load building data (first time only)
Building.loadBuildingData();
var b=null;
// Class vars: name, startingTurn, people, {props_in_buildingData.json[name]}
if(!data){
b=MainGame.game.make.sprite(0,0);
b.name=null;
}else{
/*global MainGame*/
b=MainGame.game.make.sprite(0,0,data.name);
// copy name,startingTurn,people
for(var key in data){
b[key]=data[key];
}
// copy props in buildingData.json[name]
var b_data=Building.buildingData[data.name];
for(var key2 in b_data){
b[key2]=b_data[key2];
}
// Set detail icon texture string
b.detailIconTexture = b.name + '_detail';
//console.log(b.name);
}
if (b.name === 'armyBase') {
b.squad = null;
b.squadDeployed = false;
}
b.integrity = 10;
b.anchor.set(0.5, 0.5);
// Class funcs
b.isEmpty=function(){return b.name===null};
b.addPerson=function(){return Building.addPerson(b)};
b.removePerson=function(){return Building.removePerson(b)};
b.removeConstructionEffect = function() { return Building.removeConstructionEffect(b); };
b.nextTurn=function(turn){return Building.nextTurn(b,turn)};
return b;
},
addPerson: function(b) {
if(b.people < b.maxPeople){
b.people += 1;
return true;
}
else{ return false; }
},
removePerson: function(b) {
if(b.people > 0){
b.people -= 1;
return true;
}
else{ return false; }
},
removeConstructionEffect: function(b) {
if (b.constructionIcon) { // Quick check to make sure we even have a construction effect
b.tint = 0xffffff;
b.loadTexture(b.name,0,false);
b.constructionIcon.destroy();
b.counterIcon.destroy();
}
},
nextTurn: function(b,turn){
if (b.startingTurn === turn) {
b.removeConstructionEffect();
}else if(b.startingTurn>turn){
b.counterIcon.loadTexture("counter_icon"+(b.startingTurn-MainGame.global.turn));
}
},
// Static Method - safely gets the data of a given building
getData: function(name) {
Building.loadBuildingData();
return Building.buildingData[name];
},
};