Просмотр исходного кода

Go back to mutating objects instead of making fresh copies.

tags/v0.0.6
Fen Dweller 5 лет назад
Родитель
Сommit
3c24e7d341
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: E80B35A6F11C3656
1 измененных файлов: 9 добавлений и 13 удалений
  1. +9
    -13
      gorge.js

+ 9
- 13
gorge.js Просмотреть файл

@@ -73,11 +73,9 @@ function applyGlobalProdBonus(cost) {
for (let effect of effects["prod-all"]) {

if (ownedUpgrades[effect.parent]) {
cost = effect.apply(cost);
effect.apply(cost);
}
}

return cost;
}

function calculateProductivity() {
@@ -99,44 +97,42 @@ function applyProductivityMultipliers(type, cost) {
for (let effect of effects["prod"]) {

if (ownedUpgrades[effect.parent] && effect.target == type) {
cost = effect.apply(cost);
effect.apply(cost);
}
}

for (let effect of effects["helper"]) {

if (ownedUpgrades[effect.parent] && effect.helped == type) {
cost = effect.apply(cost, belongings[effect.helper].count);
effect.apply(cost, belongings[effect.helper].count);
}
}

return cost;
}

function productivityOf(type) {
let baseProd = makeCost(buildings[type].prod);

baseProd = applyProductivityMultipliers(type, baseProd);
applyProductivityMultipliers(type, baseProd);

baseProd = applyGlobalProdBonus(baseProd);
applyGlobalProdBonus(baseProd);

baseProd = scaleCost(baseProd, belongings[type].count);
scaleCost(baseProd, belongings[type].count);

return baseProd;
}

function makeCost(source) {
const empty = mapObject(resourceTypes, () => 0);
return deepFreeze({...empty, ...source});
return {...empty, ...source};
}

function addCost(cost1, cost2) {
return deepFreeze(Object.keys(resourceTypes).reduce((o, k) => ({ ...o, [k]: cost1[k] + cost2[k]}), {}));
return Object.keys(resourceTypes).reduce((o, k) => {o[k] += cost2[k]; return o;}, cost1);
}

function scaleCost(cost, scale) {
if (typeof(scale) != "number") console.log(scale)
return deepFreeze(Object.keys(resourceTypes).reduce((o, k) => ({ ...o, [k]: cost[k] * scale}), {}));
return Object.keys(resourceTypes).reduce((o, k) => {o[k] *= scale; return o;}, cost);
}

function costOfBuilding(type, count = 1) {


Загрузка…
Отмена
Сохранить