mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-19 10:31:24 +01:00
reinstate economics logic
This commit is contained in:
parent
cea9b1a48a
commit
cb486fa0e8
17 changed files with 2179 additions and 42 deletions
|
|
@ -94,6 +94,12 @@ function editBurg(id) {
|
|||
if (b.shanty) byId("burgShanty").classList.remove("inactive");
|
||||
else byId("burgShanty").classList.add("inactive");
|
||||
|
||||
// economics block
|
||||
byId("burgProduction").innerHTML = getProduction(b.produced);
|
||||
const deals = pack.trade.deals;
|
||||
byId("burgExport").innerHTML = getExport(deals.filter((deal) => deal.exporter === b.i));
|
||||
byId("burgImport").innerHTML = "";
|
||||
|
||||
//toggle lock
|
||||
updateBurgLockIcon();
|
||||
|
||||
|
|
@ -119,6 +125,38 @@ 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>`;
|
||||
}
|
||||
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('')}`;
|
||||
}
|
||||
|
||||
function dragBurgLabel() {
|
||||
const tr = parseTransform(this.getAttribute("transform"));
|
||||
const dx = +tr[0] - d3.event.x,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue