2 Star 8 Fork 2

锅巴汉化 / SpaceCompany1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
building.js 3.06 KB
一键复制 编辑 原始数据 按行查看 历史
zhaolinxu 提交于 2017-10-12 09:57 . Revert "回退"
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;
}());
HTML
1
https://gitee.com/likexia/SpaceCompany1.git
git@gitee.com:likexia/SpaceCompany1.git
likexia
SpaceCompany1
SpaceCompany1
master

搜索帮助