mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 12:01:23 +01:00
resource units
This commit is contained in:
parent
e963ccbfca
commit
713833f4b8
4 changed files with 24 additions and 13 deletions
|
|
@ -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};
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -96,17 +96,8 @@ function editBurg(id) {
|
|||
document.getElementById("burgImport").innerHTML = '';
|
||||
|
||||
// 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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue