resource units

This commit is contained in:
Azgaar 2021-08-08 13:44:50 +03:00
parent 16c316a74f
commit a3043f932f
5 changed files with 51 additions and 13 deletions

View file

@ -110,5 +110,24 @@ window.Production = (function () {
}
};
return {collectResources};
const defineExport = () => {
const {cells, burgs} = pack;
for (const burg of burgs) {
if (!burg.i || burg.removed) continue;
const {population, production: resourcePool} = burg;
const localUsage = Math.ceil(population);
const surplus = {};
for (const resourceId in resourcePool) {
const production = resourcePool[resourceId];
const extraProduction = production - localUsage;
if (extraProduction > 0) surplus[resourceId] = extraProduction;
}
burg.export = surplus;
}
};
return {collectResources, defineExport};
})();

View file

@ -98,17 +98,8 @@ function editBurg(id) {
else document.getElementById('burgShanty').classList.add('inactive');
// economics block
let productionHTML = '';
for (const resourceId in b.production) {
const {name, unit, icon} = Resources.get(+resourceId);
const production = b.production[resourceId];
const unitName = production > 1 ? unit + 's' : unit;
productionHTML += `<span data-tip="${name}: ${production} ${unitName}">
<svg class="resIcon"><use href="#${icon}"></svg>
<span style="margin: 0 0.2em 0 -0.2em">${production}</span>
</span>`;
}
document.getElementById('burgProduction').innerHTML = productionHTML;
document.getElementById('burgProduction').innerHTML = getProduction(b.production);
document.getElementById('burgExport').innerHTML = getProduction(b.export);
//toggle lock
updateBurgLockIcon();
@ -128,6 +119,23 @@ function editBurg(id) {
document.getElementById('burgEmblem').setAttribute('href', '#' + coaID);
}
function getProduction(resources) {
let html = '';
for (const resourceId in resources) {
const {name, unit, icon} = Resources.get(+resourceId);
const production = resources[resourceId];
const unitName = production > 1 ? unit + 's' : unit;
html += `<span data-tip="${name}: ${production} ${unitName}">
<svg class="resIcon"><use href="#${icon}"></svg>
<span style="margin: 0 0.2em 0 -0.2em">${production}</span>
</span>`;
}
return html;
}
// [-1; 31] °C, source: https://en.wikipedia.org/wiki/List_of_cities_by_average_temperature
function getTemperatureLikeness(temperature) {
if (temperature < -15) return 'nowhere in the real-world';