mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
goods export system
This commit is contained in:
parent
2312d99760
commit
1f6f693be7
7 changed files with 118 additions and 35 deletions
|
|
@ -98,8 +98,10 @@ function editBurg(id) {
|
|||
else document.getElementById('burgShanty').classList.add('inactive');
|
||||
|
||||
// economics block
|
||||
document.getElementById('burgProduction').innerHTML = getProduction(b.production);
|
||||
document.getElementById('burgExport').innerHTML = getProduction(b.export);
|
||||
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();
|
||||
|
|
@ -119,12 +121,12 @@ function editBurg(id) {
|
|||
document.getElementById('burgEmblem').setAttribute('href', '#' + coaID);
|
||||
}
|
||||
|
||||
function getProduction(resources) {
|
||||
function getProduction(pool) {
|
||||
let html = '';
|
||||
|
||||
for (const resourceId in resources) {
|
||||
for (const resourceId in pool) {
|
||||
const {name, unit, icon} = Resources.get(+resourceId);
|
||||
const production = resources[resourceId];
|
||||
const production = pool[resourceId];
|
||||
const unitName = production > 1 ? unit + 's' : unit;
|
||||
|
||||
html += `<span data-tip="${name}: ${production} ${unitName}">
|
||||
|
|
@ -136,6 +138,24 @@ function editBurg(id) {
|
|||
return html;
|
||||
}
|
||||
|
||||
function getExport(dealsArray) {
|
||||
if (!dealsArray.length) return 'no';
|
||||
|
||||
const totalIncome = 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: ${burgIncome}">
|
||||
<svg class="resIcon"><use href="#${icon}"></svg>
|
||||
<span style="margin: 0 0.2em 0 -0.2em">${quantity}</span>
|
||||
</span>`;
|
||||
});
|
||||
|
||||
return `${totalIncome}: ${exported.join('')}`;
|
||||
}
|
||||
|
||||
// [-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';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue