diff --git a/index.css b/index.css index 623c4189..4f9c5df5 100644 --- a/index.css +++ b/index.css @@ -692,7 +692,7 @@ fieldset { } #styleElements .whiteButton { - padding: 0 9px; + padding: 0 .8em; border: 0; background-color: #ffffff !important; } @@ -1249,6 +1249,7 @@ div.states>.cultureName { div.states>.culturePopulation { width: 4em; + cursor: pointer; } div.states > .cultureBase, diff --git a/index.html b/index.html index fddb158d..4aeec706 100644 --- a/index.html +++ b/index.html @@ -2671,7 +2671,7 @@
Total population: ${total} ⇒ ${total} (100%)
`; + + const update = function() { + const totalNew = ruralPop.valueAsNumber + urbanPop.valueAsNumber; + if (isNaN(totalNew)) return; + totalPop.innerHTML = totalNew; + totalPopPerc.innerHTML = rn(totalNew / total * 100); + } + + ruralPop.oninput = () => update(); + urbanPop.oninput = () => update(); + + $("#alert").dialog({ + resizable: false, title: "Change state population", width: "23em", buttons: { + Apply: function() {applyPopulationChange(); $(this).dialog("close");}, + Cancel: function() {$(this).dialog("close");} + }, position: {my: "center", at: "center", of: "svg"} + }); + + function applyPopulationChange() { + const ruralChange = rn(ruralPop.value / rural, 4); + if (isFinite(ruralChange) && ruralChange !== 1) { + const cells = pack.cells.i.filter(i => pack.cells.state[i] === state); + cells.forEach(i => pack.cells.pop[i] *= ruralChange); + } + if (!isFinite(ruralChange) && +ruralPop.value > 0) { + const points = ruralPop.value / populationRate.value; + const cells = pack.cells.i.filter(i => pack.cells.state[i] === state); + const pop = rn(points / cells.length); + cells.forEach(i => pack.cells.pop[i] = pop); + } + + const urbanChange = rn(urbanPop.value / urban, 4); + if (isFinite(urbanChange) && urbanChange !== 1) { + const burgs = pack.burgs.filter(b => !b.removed && b.state === state); + burgs.forEach(b => b.population *= urbanChange); + } + if (!isFinite(urbanChange) && +urbanPop.value > 0) { + const points = urbanPop.value / populationRate.value / urbanization.value; + const burgs = pack.burgs.filter(b => !b.removed && b.state === state); + const population = rn(points / burgs.length); + burgs.forEach(b => b.population = population); + } + + refreshStatesEditor(); + } + + } + function stateCapitalZoomIn(state) { const capital = pack.states[state].capital; const l = burgLabels.select("[data-id='" + capital + "']");