forked from plainblack/Lacuna-Web-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildingEnergyReserve.js
112 lines (97 loc) · 4.19 KB
/
buildingEnergyReserve.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
YAHOO.namespace("lacuna.buildings");
if (typeof YAHOO.lacuna.buildings.EnergyReserve == "undefined" || !YAHOO.lacuna.buildings.EnergyReserve) {
(function(){
var Lang = YAHOO.lang,
Util = YAHOO.util,
Dom = Util.Dom,
Event = Util.Event,
Lacuna = YAHOO.lacuna,
Game = Lacuna.Game,
Lib = Lacuna.Library;
var EnergyReserve = function(result){
EnergyReserve.superclass.constructor.call(this, result);
this.service = Game.Services.Buildings.EnergyReserve;
};
YAHOO.lang.extend(EnergyReserve, YAHOO.lacuna.buildings.Building, {
getChildTabs : function() {
return [this._getDumpTab()];
},
_getDumpTab : function() {
this.dumpTab = new YAHOO.widget.Tab({ label: "Dump", contentEl: this.DumpGetDisplay(this.result.dump)});
return this.dumpTab;
},
DumpGetDisplay : function() {
var ul = document.createElement('ul'),
li = document.createElement('li'),
nLi = li.cloneNode(false);
nLi.innerHTML = 'Convert energy into waste.';
ul.appendChild(nLi);
nLi = li.cloneNode(false);
nLi.innerHTML = '<span class="smallImg"><img src="'+Lib.AssetUrl+'ui/s/energy.png" class="smallEnergy" /></span>';
input = document.createElement("input");
input.id = 'dumpAmount';
input.type = "text";
input.value = 0;
input = nLi.appendChild(input);
Event.on(input, "change", this.DumpValueChange, this, true);
ul.appendChild(nLi);
var div = document.createElement("div");
Dom.addClass(div, 'dumpTab');
div.appendChild(ul);
var form = document.createElement('form');
btn = document.createElement("button");
btn.setAttribute("type", "button");
btn.innerHTML = "Dump";
btn = form.appendChild(btn);
Event.on(btn, "click", this.Dump, this, true);
div.appendChild(form);
var msg = document.createElement('div');
msg.id = "dumpMessage";
div.appendChild(msg);
return div;
},
Dump : function(e) {
var planet = Game.GetCurrentPlanet();
var building = this.building;
var type = "energy";
if(building) {
var amount = Dom.get("dumpAmount").value*1;
if(amount > planet.energy_stored) {
Dom.get("dumpMessage").innerHTML = "Can only convert " + type + " you have stored.";
Lib.fadeOutElm("dumpMessage");
}
else if( amount <= 0 ) {
Dom.get("dumpMessage").innerHTML = "You must specify an amount greater than zero.";
Lib.fadeOutElm("dumpMessage");
}
else {
Lacuna.Pulser.Show();
this.service.dump({
session_id:Game.GetSession(),
building_id:this.building.id,
amount:amount
}, {
success : function(o){
YAHOO.log(o, "info", "EnergyReserve.Dump.success");
Lacuna.Pulser.Hide();
this.rpcSuccess(o);
if(this.dumpTab){
var ce = this.dumpTab.get("contentEl");
Event.purgeElement(ce);
ce.innerHTML = "";
ce.appendChild(this.DumpGetDisplay(o.result.dump));
Dom.get("dumpMessage").innerHTML = "Successfully converted " + amount + " " + type + " to waste.";
Lib.fadeOutElm("dumpMessage");
}
},
scope:this
});
}
}
}
});
YAHOO.lacuna.buildings.EnergyReserve = EnergyReserve;
})();
YAHOO.register("energyreserve", YAHOO.lacuna.buildings.EnergyReserve, {version: "1", build: "0"});
}
// vim: noet:ts=4:sw=4