From 3f58b9f36218766cd04398eaf9e2a44edc81ced2 Mon Sep 17 00:00:00 2001 From: dranorter Date: Sun, 17 Oct 2021 04:48:56 -0400 Subject: [PATCH 1/3] Watabou cities integration change, new Urban Density setting (#672) * Watabou cities integration change, new Urban Density setting New setting does not yet save/load - I don't want to change the .map file format. * new markers - monsters * markers - fix bridges placement * markers - fix number * markers - sacred places * markers - refactor functions * markers - course generator for inns * markers - course generator enhancement * markers - bandits and pirates * reset PRNG - make points generation deterministic * use imperial measures for US only * split save and export to different files * remove unused js libs * markers - statues * markers - magic portals * markers - magic portals fix * markers - palm grove fix * markers - round coords on zoom * markers data rework - master data object * markers rework - optional pin shapes * markers rework - editor start, dragging * markers rework - editor functions * markers rework - editor UI * editable theme color * added self-hosted analytics * collect statistics for a short period * umami - we do'nt need html class events * umami - don't collect if noTrack is set * markers - add on click * saveTiles clean up listeners on close * markers - generate from config file * config generate markers dialog * config generate markers dialog fixes * markers overview * markers - export as geoJSON * markers overview - export data to csv * markers - auto-update on load * markers overview - focus on marker * burg editor - MFCG preview * markers - generate tool + lock tooltip * Watabou cities integration change, new Urban Density setting New setting does not yet save/load - I don't want to change the .map file format. * Trying to put the formula in the right place Again, sorry for the mess * whoops * Getting the equation right * Change default Co-authored-by: Azgaar --- index.html | 6 ++++++ main.js | 1 + modules/ui/burg-editor.js | 3 +-- modules/ui/units-editor.js | 8 ++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index ec30a12b..f0fa618a 100644 --- a/index.html +++ b/index.html @@ -3214,6 +3214,12 @@ + +
+
Urban density:
+ + +
diff --git a/main.js b/main.js index a32b3aa0..539dea04 100644 --- a/main.js +++ b/main.js @@ -155,6 +155,7 @@ let options = { let mapCoordinates = {}; // map coordinates on globe let populationRate = +document.getElementById("populationRateInput").value; let urbanization = +document.getElementById("urbanizationInput").value; +let urbanDensity = +document.getElementById("urbanDensityInput").value; applyStoredOptions(); diff --git a/modules/ui/burg-editor.js b/modules/ui/burg-editor.js index c61b6ed9..2de633d5 100644 --- a/modules/ui/burg-editor.js +++ b/modules/ui/burg-editor.js @@ -408,7 +408,6 @@ function editBurg(id) { document.getElementById("mfcgPreview").setAttribute("src", mfcgURL); document.getElementById("mfcgLink").setAttribute("href", mfcgURL); } - function getBurgSeed(burg) { return burg.MFCG || Number(`${seed}${String(burg.i).padStart(4, 0)}`); } @@ -417,7 +416,7 @@ function editBurg(id) { const {cells} = pack; const {name, population, cell} = burg; const burgSeed = getBurgSeed(burg); - const size = minmax(rn(population), 6, 100); + const size = Math.max(Math.min(Math.ceil(2.13*Math.pow(population * populationRate/urbanDensity,0.385)), 100), 6); const people = rn(population * populationRate * urbanization); const hub = +cells.road[cell] > 50; diff --git a/modules/ui/units-editor.js b/modules/ui/units-editor.js index 54571191..be8f94c4 100644 --- a/modules/ui/units-editor.js +++ b/modules/ui/units-editor.js @@ -31,6 +31,8 @@ function editUnits() { document.getElementById("populationRateInput").addEventListener("change", changePopulationRate); document.getElementById("urbanizationOutput").addEventListener("input", changeUrbanizationRate); document.getElementById("urbanizationInput").addEventListener("change", changeUrbanizationRate); + document.getElementById("urbanDensityOutput").addEventListener("input", changeUrbanDensity); + document.getElementById("urbanDensityInput").addEventListener("change", changeUrbanDensity); document.getElementById("addLinearRuler").addEventListener("click", addRuler); document.getElementById("addOpisometer").addEventListener("click", toggleOpisometerMode); @@ -93,6 +95,10 @@ function editUnits() { urbanization = +this.value; } + function changeUrbanDensity() { + urbanDensity = +this.value; + } + function restoreDefaultUnits() { // distanceScale document.getElementById("distanceScaleOutput").value = 3; @@ -135,8 +141,10 @@ function editUnits() { // population populationRate = populationRateOutput.value = populationRateInput.value = 1000; urbanization = urbanizationOutput.value = urbanizationInput.value = 1; + urbanDensity = urbanDensityOutput.value = urbanDensityInput.value = 10; localStorage.removeItem("populationRate"); localStorage.removeItem("urbanization"); + localStorage.removeItem("urbanDensity") } function addRuler() { From cc82d258faf1bf8e5be3e6b1e7fa4b3cc4c5119b Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sun, 17 Oct 2021 12:01:38 +0300 Subject: [PATCH 2/3] urbanDensity - save/load --- index.html | 6 +++--- modules/load.js | 1 + modules/save.js | 3 ++- modules/ui/burg-editor.js | 3 ++- modules/ui/units-editor.js | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index f0fa618a..28c0dea1 100644 --- a/index.html +++ b/index.html @@ -3215,10 +3215,10 @@
-
+
Urban density:
- - + +
diff --git a/modules/load.js b/modules/load.js index a44b4d36..fc58fa55 100644 --- a/modules/load.js +++ b/modules/load.js @@ -231,6 +231,7 @@ function parseLoadedData(data) { if (settings[21]) hideLabels.checked = +settings[21]; if (settings[22]) stylePreset.value = settings[22]; if (settings[23]) rescaleLabels.checked = +settings[23]; + if (settings[24]) urbanDensity = urbanDensity.value = urbanDensityOutput.value = +settings[24]; })(); void (function parseConfiguration() { diff --git a/modules/save.js b/modules/save.js index 6ebda083..04f3e665 100644 --- a/modules/save.js +++ b/modules/save.js @@ -33,7 +33,8 @@ function getMapData() { mapName.value, +hideLabels.checked, stylePreset.value, - +rescaleLabels.checked + +rescaleLabels.checked, + urbanDensity ].join("|"); const coords = JSON.stringify(mapCoordinates); const biomes = [biomesData.color, biomesData.habitability, biomesData.name].join("|"); diff --git a/modules/ui/burg-editor.js b/modules/ui/burg-editor.js index 2de633d5..1fcdf434 100644 --- a/modules/ui/burg-editor.js +++ b/modules/ui/burg-editor.js @@ -416,7 +416,8 @@ function editBurg(id) { const {cells} = pack; const {name, population, cell} = burg; const burgSeed = getBurgSeed(burg); - const size = Math.max(Math.min(Math.ceil(2.13*Math.pow(population * populationRate/urbanDensity,0.385)), 100), 6); + const sizeRaw = 2.13 * Math.pow((population * populationRate) / urbanDensity, 0.385); + const size = minmax(Math.ceil(sizeRaw), 6, 100); const people = rn(population * populationRate * urbanization); const hub = +cells.road[cell] > 50; diff --git a/modules/ui/units-editor.js b/modules/ui/units-editor.js index be8f94c4..aa3e4e63 100644 --- a/modules/ui/units-editor.js +++ b/modules/ui/units-editor.js @@ -144,7 +144,7 @@ function editUnits() { urbanDensity = urbanDensityOutput.value = urbanDensityInput.value = 10; localStorage.removeItem("populationRate"); localStorage.removeItem("urbanization"); - localStorage.removeItem("urbanDensity") + localStorage.removeItem("urbanDensity"); } function addRuler() { From 5c90d6a6a42359a5ecbe62d99d7fe545d9a4bc5c Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sun, 17 Oct 2021 12:05:06 +0300 Subject: [PATCH 3/3] urbanDensity - chage limits --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 28c0dea1..54591a88 100644 --- a/index.html +++ b/index.html @@ -3217,8 +3217,8 @@
Urban density:
- - + +