forked from plainblack/Lacuna-Web-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildingThemePark.js
106 lines (89 loc) · 3.62 KB
/
buildingThemePark.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
YAHOO.namespace("lacuna.buildings");
if (typeof YAHOO.lacuna.buildings.ThemePark == "undefined" || !YAHOO.lacuna.buildings.ThemePark) {
(function(){
var Lang = YAHOO.lang,
Util = YAHOO.util,
Dom = Util.Dom,
Event = Util.Event,
Lacuna = YAHOO.lacuna,
Game = Lacuna.Game,
Lib = Lacuna.Library;
var ThemePark = function(result){
ThemePark.superclass.constructor.call(this, result);
this.service = Game.Services.Buildings.ThemePark;
};
Lang.extend(ThemePark, Lacuna.buildings.Building, {
getChildTabs : function() {
return [this._getTab()];
},
_getTab : function() {
this.tab = new YAHOO.widget.Tab({ label: "Operations", content: [
'<div id="ThemeParkWorking" style="display:none;">',
' Time left on current operations: <span id="ThemeParkTime"></span>',
'</div>',
'<div id="ThemeParkMessage" style="margin-top:5px;"></div>',
'<div id="ThemeParkDisplay" style="display:none;margin:5px 0;">',
' <button type="button" id="Operate">Open Theme Park</button>',
'</div>'
].join('')});
Event.on("Operate", "click", this.operate, this, true);
this.subscribe("onLoad", function() {
this.updateDisplay(this.result); //first load this will be accurate
}, this, true);
return this.tab;
},
operate : function() {
Lacuna.Pulser.Show();
this.service.operate({
session_id:Game.GetSession(),
building_id:this.building.id
}, {
success : function(o){
Lacuna.Pulser.Hide();
this.rpcSuccess(o);
this.updateDisplay(o.result);
},
scope:this
});
},
updateDisplay : function(result) {
var isWorking = result.building.work && result.building.work.seconds_remaining > 0;
if(isWorking) {
Dom.setStyle("ThemeParkWorking","display","");
this.resetQueue();
this.addQueue(result.building.work.seconds_remaining, this.parkQueue, "ThemeParkTime");
}
else {
Dom.setStyle("ThemeParkWorking","display","none");
}
if(result.themepark.can_operate) {
Dom.setStyle("ThemeParkDisplay","display","");
if(isWorking) {
Dom.get("Operate").innerHTML = "Extend Theme Park Operations";
}
else {
Dom.get("Operate").innerHTML = "Open Theme Park";
}
}
else {
Dom.setStyle("ThemeParkDisplay","display","none");
Dom.get("ThemeParkMessage").innerHTML = result.themepark.reason[1];
}
},
parkQueue : function(remaining, el){
if(remaining <= 0) {
var span = Dom.get(el),
p = span.parentNode;
p.removeChild(span);
p.innerHTML = "Park is closed.";
}
else {
Dom.get(el).innerHTML = Lib.formatTime(Math.round(remaining));
}
}
});
YAHOO.lacuna.buildings.ThemePark = ThemePark;
})();
YAHOO.register("ThemePark", YAHOO.lacuna.buildings.ThemePark, {version: "1", build: "0"});
}
// vim: noet:ts=4:sw=4