mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 12:01:23 +01:00
Merge economics with current
This commit is contained in:
parent
d3ea2df1a2
commit
7270c8c833
13 changed files with 2119 additions and 2 deletions
|
|
@ -94,6 +94,12 @@ function editBurg(id) {
|
|||
if (b.shanty) document.getElementById("burgShanty").classList.remove("inactive");
|
||||
else document.getElementById("burgShanty").classList.add("inactive");
|
||||
|
||||
// economics block
|
||||
document.getElementById('burgProduction').innerHTML = getProduction(b.produced);
|
||||
const deals = pack.trade.deals;
|
||||
document.getElementById('burgExport').innerHTML = getExport(deals.filter((deal) => deal.exporter === b.i));
|
||||
document.getElementById('burgImport').innerHTML = '';
|
||||
|
||||
//toggle lock
|
||||
updateBurgLockIcon();
|
||||
|
||||
|
|
@ -126,6 +132,41 @@ function editBurg(id) {
|
|||
}
|
||||
}
|
||||
|
||||
function getProduction(pool) {
|
||||
let html = "";
|
||||
|
||||
for (const resourceId in pool) {
|
||||
const {name, unit, icon} = Resources.get(+resourceId);
|
||||
const production = pool[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;
|
||||
}
|
||||
|
||||
function getExport(dealsArray) {
|
||||
if (!dealsArray.length) return 'no';
|
||||
|
||||
const totalIncome = rn(d3.sum(dealsArray.map((deal) => deal.burgIncome)));
|
||||
const exported = dealsArray.map((deal) => {
|
||||
const {resourceId, quantity, burgIncome} = deal;
|
||||
const {name, unit, icon} = Resources.get(resourceId);
|
||||
const unitName = quantity > 1 ? unit + 's' : unit;
|
||||
|
||||
return `<span data-tip="${name}: ${quantity} ${unitName}. Income: ${rn(burgIncome)}">
|
||||
<svg class="resIcon"><use href="#${icon}"></svg>
|
||||
<span style="margin: 0 0.2em 0 -0.2em">${quantity}</span>
|
||||
</span>`;
|
||||
});
|
||||
|
||||
return `${totalIncome}: ${exported.join('')}`;
|
||||
}
|
||||
|
||||
// in °C, array from -1 °C; source: https://en.wikipedia.org/wiki/List_of_cities_by_average_temperature
|
||||
function getTemperatureLikeness(temperature) {
|
||||
if (temperature < -5) return "Yakutsk";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue