diff --git a/index.html b/index.html
index 506f4465..1ad23967 100644
--- a/index.html
+++ b/index.html
@@ -264,6 +264,7 @@
+
@@ -2272,8 +2273,8 @@
State
Form
Capital
- Culture
- Burgs
+ Culture
+ Burgs
Area
Population
Type
diff --git a/main.js b/main.js
index a2ccf33b..7f3a72ce 100644
--- a/main.js
+++ b/main.js
@@ -11,8 +11,9 @@ const version = "1.5"; // generator version
document.title += " v" + version;
// Switches to disable/enable logging features
-const INFO = 1;
-const TIME = 1;
+const PRODUCTION = window.location.host;
+const INFO = !PRODUCTION;
+const TIME = !PRODUCTION;
const WARN = 1;
const ERROR = 1;
diff --git a/modules/save-and-load.js b/modules/save-and-load.js
index e2b81159..3e98966d 100644
--- a/modules/save-and-load.js
+++ b/modules/save-and-load.js
@@ -779,36 +779,43 @@ function parseLoadedData(data) {
}
}()
- void function restoreLayersState() {
- if (texture.style("display") !== "none" && texture.select("image").size()) turnButtonOn("toggleTexture"); else turnButtonOff("toggleTexture");
- if (terrs.selectAll("*").size()) turnButtonOn("toggleHeight"); else turnButtonOff("toggleHeight");
- if (biomes.selectAll("*").size()) turnButtonOn("toggleBiomes"); else turnButtonOff("toggleBiomes");
- if (cells.selectAll("*").size()) turnButtonOn("toggleCells"); else turnButtonOff("toggleCells");
- if (gridOverlay.selectAll("*").size()) turnButtonOn("toggleGrid"); else turnButtonOff("toggleGrid");
- if (coordinates.selectAll("*").size()) turnButtonOn("toggleCoordinates"); else turnButtonOff("toggleCoordinates");
- if (compass.style("display") !== "none" && compass.select("use").size()) turnButtonOn("toggleCompass"); else turnButtonOff("toggleCompass");
- if (rivers.style("display") !== "none") turnButtonOn("toggleRivers"); else turnButtonOff("toggleRivers");
- if (terrain.style("display") !== "none" && terrain.selectAll("*").size()) turnButtonOn("toggleRelief"); else turnButtonOff("toggleRelief");
- if (relig.selectAll("*").size()) turnButtonOn("toggleReligions"); else turnButtonOff("toggleReligions");
- if (cults.selectAll("*").size()) turnButtonOn("toggleCultures"); else turnButtonOff("toggleCultures");
- if (statesBody.selectAll("*").size()) turnButtonOn("toggleStates"); else turnButtonOff("toggleStates");
- if (provs.selectAll("*").size()) turnButtonOn("toggleProvinces"); else turnButtonOff("toggleProvinces");
- if (zones.selectAll("*").size() && zones.style("display") !== "none") turnButtonOn("toggleZones"); else turnButtonOff("toggleZones");
- if (borders.style("display") !== "none") turnButtonOn("toggleBorders"); else turnButtonOff("toggleBorders");
- if (routes.style("display") !== "none" && routes.selectAll("path").size()) turnButtonOn("toggleRoutes"); else turnButtonOff("toggleRoutes");
- if (temperature.selectAll("*").size()) turnButtonOn("toggleTemp"); else turnButtonOff("toggleTemp");
- if (prec.selectAll("circle").size()) turnButtonOn("togglePrec"); else turnButtonOff("togglePrec");
- if (labels.style("display") !== "none") turnButtonOn("toggleLabels"); else turnButtonOff("toggleLabels");
- if (icons.style("display") !== "none") turnButtonOn("toggleIcons"); else turnButtonOff("toggleIcons");
- if (armies.selectAll("*").size() && armies.style("display") !== "none") turnButtonOn("toggleMilitary"); else turnButtonOff("toggleMilitary");
- if (markers.selectAll("*").size() && markers.style("display") !== "none") turnButtonOn("toggleMarkers"); else turnButtonOff("toggleMarkers");
- if (ruler.style("display") !== "none") turnButtonOn("toggleRulers"); else turnButtonOff("toggleRulers");
- if (scaleBar.style("display") !== "none") turnButtonOn("toggleScaleBar"); else turnButtonOff("toggleScaleBar");
+ const notHidden = selection => selection.style("display") !== "none";
+ const hasChildren = selection => selection.node().hasChildNodes();
+ const hasChild = (selection, selector) => selection.node().querySelector(selector);
+ const turnOn = el => document.getElementById(el).classList.remove("buttonoff");
- // special case for population bars
- const populationIsOn = population.selectAll("line").size();
- if (populationIsOn) drawPopulation();
- if (populationIsOn) turnButtonOn("togglePopulation"); else turnButtonOff("togglePopulation");
+ void function restoreLayersState() {
+ // turn all layers off
+ document.getElementById("mapLayers").querySelectorAll("li").forEach(el => el.classList.add("buttonoff"));
+
+ // turn on active layers
+ if (notHidden(texture) && hasChild(texture, "image")) turnOn("toggleTexture");
+ if (hasChildren(terrs)) turnOn("toggleHeight");
+ if (hasChildren(biomes)) turnOn("toggleBiomes");
+ if (hasChildren(cells)) turnOn("toggleCells");
+ if (hasChildren(gridOverlay)) turnOn("toggleGrid");
+ if (hasChildren(coordinates)) turnOn("toggleCoordinates");
+ if (notHidden(compass) && hasChild(compass, "use")) turnOn("toggleCompass");
+ if (notHidden(rivers)) turnOn("toggleRivers");
+ if (notHidden(terrain) && hasChildren(terrain)) turnOn("toggleRelief");
+ if (hasChildren(relig)) turnOn("toggleReligions");
+ if (hasChildren(cults)) turnOn("toggleCultures");
+ if (hasChildren(statesBody)) turnOn("toggleStates");
+ if (hasChildren(provs)) turnOn("toggleProvinces");
+ if (hasChildren(zones) && notHidden(zones)) turnOn("toggleZones");
+ if (notHidden(borders) && hasChild(compass, "use")) turnOn("toggleBorders");
+ if (notHidden(routes) && hasChild(routes, "path")) turnOn("toggleRoutes");
+ if (hasChildren(temperature)) turnOn("toggleTemp");
+ if (hasChild(population, "line")) turnOn("togglePopulation");
+ if (hasChildren(ice)) turnOn("toggleIce");
+ if (hasChild(prec, "circle")) turnOn("togglePrec");
+ if (hasChild(emblems, "use")) turnOn("toggleEmblems");
+ if (notHidden(labels)) turnOn("toggleLabels");
+ if (notHidden(icons)) turnOn("toggleIcons");
+ if (hasChildren(armies) && notHidden(armies)) turnOn("toggleMilitary");
+ if (hasChildren(markers) && notHidden(markers)) turnOn("toggleMarkers");
+ if (notHidden(ruler)) turnOn("toggleRulers");
+ if (notHidden(scaleBar)) turnOn("toggleScaleBar");
getCurrentPreset();
}()
diff --git a/modules/ui/layers.js b/modules/ui/layers.js
index ea88cf25..d7cff0c6 100644
--- a/modules/ui/layers.js
+++ b/modules/ui/layers.js
@@ -1,30 +1,6 @@
// UI module stub to control map layers
"use strict";
-// on map regeneration restore layers if they was turned on
-function restoreLayers() {
- if (layerIsOn("toggleHeight")) drawHeightmap();
- if (layerIsOn("toggleCells")) drawCells();
- if (layerIsOn("toggleGrid")) drawGrid();
- if (layerIsOn("toggleCoordinates")) drawCoordinates();
- if (layerIsOn("toggleCompass")) compass.style("display", "block");
- if (layerIsOn("toggleTemp")) drawTemp();
- if (layerIsOn("togglePrec")) drawPrec();
- if (layerIsOn("togglePopulation")) drawPopulation();
- if (layerIsOn("toggleBiomes")) drawBiomes();
- if (layerIsOn("toggleRelief")) ReliefIcons();
- if (layerIsOn("toggleCultures")) drawCultures();
- if (layerIsOn("toggleProvinces")) drawProvinces();
- if (layerIsOn("toggleReligions")) drawReligions();
- if (layerIsOn("toggleIce")) drawIce();
- if (layerIsOn("toggleEmblems")) drawEmblems();
-
- // states are getting rendered each time, if it's not required than layers should be hidden
- if (!layerIsOn("toggleBorders")) $('#borders').fadeOut();
- if (!layerIsOn("toggleStates")) regions.style("display", "none").selectAll("path").remove();
-}
-
-restoreLayers(); // run on-load
let presets = {}; // global object
restoreCustomPresets(); // run on-load
@@ -39,6 +15,7 @@ function getDefaultPresets() {
"physical": ["toggleCoordinates", "toggleHeight", "toggleIce", "toggleRivers", "toggleScaleBar"],
"poi": ["toggleBorders", "toggleHeight", "toggleIce", "toggleIcons", "toggleMarkers", "toggleRivers", "toggleRoutes", "toggleScaleBar"],
"military": ["toggleBorders", "toggleIcons", "toggleLabels", "toggleMilitary", "toggleRivers", "toggleRoutes", "toggleScaleBar", "toggleStates"],
+ "emblems": ["toggleBorders", "toggleIcons", "toggleIce", "toggleEmblems", "toggleRivers", "toggleRoutes", "toggleScaleBar", "toggleStates"],
"landmass": ["toggleScaleBar"]
}
}
@@ -56,9 +33,10 @@ function restoreCustomPresets() {
presets = storedPresets;
}
+// run on map generation
function applyPreset() {
- const selected = localStorage.getItem("preset");
- if (selected) changePreset(selected);
+ const preset = localStorage.getItem("preset") || document.getElementById("layersPreset").value;
+ changePreset(preset);
}
// toggle layers on preset change
@@ -118,6 +96,29 @@ function getCurrentPreset() {
savePresetButton.style.display = "inline-block";
}
+// run on map regeneration
+function restoreLayers() {
+ if (layerIsOn("toggleHeight")) drawHeightmap();
+ if (layerIsOn("toggleCells")) drawCells();
+ if (layerIsOn("toggleGrid")) drawGrid();
+ if (layerIsOn("toggleCoordinates")) drawCoordinates();
+ if (layerIsOn("toggleCompass")) compass.style("display", "block");
+ if (layerIsOn("toggleTemp")) drawTemp();
+ if (layerIsOn("togglePrec")) drawPrec();
+ if (layerIsOn("togglePopulation")) drawPopulation();
+ if (layerIsOn("toggleBiomes")) drawBiomes();
+ if (layerIsOn("toggleRelief")) ReliefIcons();
+ if (layerIsOn("toggleCultures")) drawCultures();
+ if (layerIsOn("toggleProvinces")) drawProvinces();
+ if (layerIsOn("toggleReligions")) drawReligions();
+ if (layerIsOn("toggleIce")) drawIce();
+ if (layerIsOn("toggleEmblems")) drawEmblems();
+
+ // states are getting rendered each time, if it's not required than layers should be hidden
+ if (!layerIsOn("toggleBorders")) $('#borders').fadeOut();
+ if (!layerIsOn("toggleStates")) regions.style("display", "none").selectAll("path").remove();
+}
+
function toggleHeight(event) {
if (!terrs.selectAll("*").size()) {
turnButtonOn("toggleHeight");
@@ -458,7 +459,7 @@ function drawCells() {
cells.append("path").attr("d", path);
}
-function toggleIce() {
+function toggleIce(event) {
if (!layerIsOn("toggleIce")) {
turnButtonOn("toggleIce");
$('#ice').fadeIn();
diff --git a/modules/ui/options.js b/modules/ui/options.js
index ebcd7879..9efbfaa8 100644
--- a/modules/ui/options.js
+++ b/modules/ui/options.js
@@ -245,7 +245,7 @@ function showSeedHistoryDialog() {
});
}
-// generate map with historycal seed
+// generate map with historical seed
function restoreSeed(id) {
if (mapHistory[id].seed == seed) {
tip("The current map is already generated with this seed", null, "error");
diff --git a/modules/ui/world-configurator.js b/modules/ui/world-configurator.js
index ffcef39f..11eef897 100644
--- a/modules/ui/world-configurator.js
+++ b/modules/ui/world-configurator.js
@@ -2,10 +2,10 @@ function editWorld() {
if (customization) return;
$("#worldConfigurator").dialog({title: "Configure World", resizable: false, width: "42em",
buttons: {
- "Whole World": () => applyPreset(100, 50),
- "Northern": () => applyPreset(33, 25),
- "Tropical": () => applyPreset(33, 50),
- "Southern": () => applyPreset(33, 75),
+ "Whole World": () => applyWorldPreset(100, 50),
+ "Northern": () => applyWorldPreset(33, 25),
+ "Tropical": () => applyWorldPreset(33, 50),
+ "Southern": () => applyWorldPreset(33, 75),
"Restore Winds": restoreDefaultWinds
}, open: function() {
const buttons = $(this).dialog("widget").find(".ui-dialog-buttonset > button");
@@ -125,7 +125,7 @@ function editWorld() {
if (update) updateWorld();
}
- function applyPreset(size, lat) {
+ function applyWorldPreset(size, lat) {
document.getElementById("mapSizeInput").value = document.getElementById("mapSizeOutput").value = size;
document.getElementById("latitudeInput").value = document.getElementById("latitudeOutput").value = lat;
lock("mapSize");