代码拉取完成,页面将自动刷新
Game.buildings = (function(){
var instance = {};
instance.dataVersion = 1;
instance.entries = {};
instance.updatePerSecondProduction = true;
instance.techTypeCount = 0;
instance.initialise = function() {
for (var id in Game.buildingData) {
var data = Game.buildingData[id];
this.techTypeCount++;
this.entries[id] = $.extend({}, data, {
id: id,
htmlId: 'resbld_' + id,
current: 0,
iconPath: Game.constants.iconPath,
iconName: data.icon,
iconExtension: Game.constants.iconExtension,
max: data.maxCount,
displayNeedsUpdate: true
});
}
console.debug("Loaded " + this.techTypeCount + " Building Types");
};
instance.update = function(delta) {
if (this.updatePerSecondProduction === true) {
this.updateProduction();
}
};
instance.save = function(data) {
data.buildings = { v: this.dataVersion, i: {}};
for(var key in this.entries) {
data.buildings.i[key] = this.entries[key].current;
}
};
instance.load = function(data) {
if(data.buildings) {
if(data.buildings.v && data.buildings.v === this.dataVersion) {
for(var id in data.buildings.i) {
if(this.entries[id]) {
this.constructBuildings(id, data.buildings.i[id]);
}
}
}
}
};
instance.constructBuildings = function(id, count) {
// Add the buildings and clamp to the maximum
var newValue = Math.floor(this.entries[id].current + count);
this.entries[id].current = Math.min(newValue, this.entries[id].max);
this.entries[id].displayNeedsUpdate = true;
this.updatePerSecondProduction = true;
};
instance.destroyBuildings = function(id, count) {
// Remove the buildings and ensure we can not go below 0
var newValue = Math.floor(this.entries[id].current - count);
this.entries[id].current = Math.max(newValue, 0);
this.entries[id].displayNeedsUpdate = true;
this.updatePerSecondProduction = true;
};
instance.unlock = function(id) {
this.entries[id].unlocked = true;
this.entries[id].displayNeedsUpdate = true;
};
instance.updateProduction = function() {
for(var id in this.entries) {
var data = this.entries[id];
if(data.current == 0) {
// Nothing to be done
continue;
}
var buildingData = this.entries[id];
if (!buildingData.resource) {
continue;
}
var baseValue = data.current * buildingData.perSecond;
Game.resources.setPerSecondProduction(buildingData.resource, baseValue);
}
this.updatePerSecondProduction = false;
};
instance.getBuildingData = function(id) {
return this.entries[id];
};
return instance;
}());
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。