LWWidget.Beta5.Planets = LWWidget.Game.Page.inherits({ setData: function (data) { var _d = data.getChildren('Empire')[0].getChildren('Planets')[0]; this.planets = parseInt(_d.getAttribute('count'), 10); this.pList = new Array(); if (this.planets) { // Planets under attack this.underAttack = parseInt(_d.getAttribute('siege'), 10); // Happiness / Corruption this.avgHappiness = parseInt(_d.getAttribute('avgHap'), 10); this.avgCorruption = parseInt(_d.getAttribute('avgCor'), 10); // Population this.totPopulation = parseInt(_d.getAttribute('totPop'), 10); this.avgPopulation = parseInt(_d.getAttribute('avgPop'), 10); // Factories this.totFactories = parseInt(_d.getAttribute('totFac'), 10); this.avgFactories = parseInt(_d.getAttribute('avgFac'), 10); // Factories this.totTurrets = parseInt(_d.getAttribute('totTur'), 10); this.avgTurrets = parseInt(_d.getAttribute('avgTur'), 10); // Planet list var _l = _d.getChildren('List')[0].getChildren('Planet'); for (var i in _l) { this.pList.push(_l[i].getText()); } } }, show: function () { this.mode = 0; }, draw: function (_e) { _e.innerHTML = (this.mode == 0 || !this.planets) ? this.getStats() : this.getList(); }, setMode: function (m) { this.mode = m; if (this.game) { this.game.draw(); } }, getStats: function () { if (this.planets == 0) { return '
No planets.
'; } var _s = '' + Base.Util.formatNumber(this.planets) + ' planet'
+ (this.planets > 1 ? 's' : '') + '
';
if (this.underAttack) {
_s += '' + Base.Util.formatNumber(this.underAttack) + ' planet'
+ (this.underAttack > 1 ? 's' : '') + ' under attack!';
} else {
_s += 'No planets under attack';
}
_s += '
Average happiness: ' + this.avgHappiness + '%
Average corruption: '
+ this.avgCorruption + '%
Population: ' + Base.Util.formatNumber(this.totPopulation) + '';
if (this.planets > 1) {
_s += ' (' + Base.Util.formatNumber(this.avgPopulation) + ' on average)';
}
_s += '
Factories: ' + Base.Util.formatNumber(this.totFactories) + '';
if (this.planets > 1) {
_s += ' (' + Base.Util.formatNumber(this.avgFactories) + ' on average)';
}
_s += '
Turrets: ' + Base.Util.formatNumber(this.totTurrets) + '';
if (this.planets > 1) {
_s += ' (' + Base.Util.formatNumber(this.avgTurrets) + ' on average)';
}
_s += '
View list
<<- Back
'
+ this.pList.join('
') + '