diff --git a/main.js b/main.js
index 8dc5a8f0..9f8aaae8 100644
--- a/main.js
+++ b/main.js
@@ -122,7 +122,6 @@ let customization = 0;
let biomesData = applyDefaultBiomesSystem();
let nameBases = Names.getNameBases(); // cultures-related data
-const zoneTypes = ["Invasion", "Rebels", "Proselytism", "Crusade", "Disease", "Disaster"];
let color = d3.scaleSequential(d3.interpolateSpectral); // default color scheme
const lineGen = d3.line().curve(d3.curveBasis); // d3 line generator with default curve interpolation
@@ -1505,14 +1504,12 @@ function rankCells() {
TIME && console.timeEnd("rankCells");
}
-// regenerate some zones
+// generate zones
function addZones(number = 1) {
TIME && console.time("addZones");
- const data = [],
- cells = pack.cells,
- states = pack.states,
- burgs = pack.burgs;
+ const {cells, states, burgs} = pack;
const used = new Uint8Array(cells.i.length); // to store used cells
+ const zonesData = [];
for (let i = 0; i < rn(Math.random() * 1.8 * number); i++) addInvasion(); // invasion of enemy lands
for (let i = 0; i < rn(Math.random() * 1.6 * number); i++) addRebels(); // rebels along a state border
@@ -1526,6 +1523,8 @@ function addZones(number = 1) {
for (let i = 0; i < rn(Math.random() * 1.4 * number); i++) addFlood(); // flood on river banks
for (let i = 0; i < rn(Math.random() * 1.2 * number); i++) addTsunami(); // tsunami starting near coast
+ drawZones();
+
function addInvasion() {
const atWar = states.filter(s => s.diplomacy && s.diplomacy.some(d => d === "Enemy"));
if (!atWar.length) return;
@@ -1566,7 +1565,7 @@ function addZones(number = 1) {
Intervention: 1
});
const name = getAdjective(invader.name) + " " + invasion;
- data.push({name, type: "Invasion", cells: cellsArray, fill: "url(#hatch1)"});
+ zonesData.push({name, type: "Invasion", cells: cellsArray, fill: "url(#hatch1)"});
}
function addRebels() {
@@ -1595,7 +1594,7 @@ function addZones(number = 1) {
const rebels = rw({Rebels: 5, Insurgents: 2, Mutineers: 1, Rioters: 1, Separatists: 1, Secessionists: 1, Insurrection: 2, Rebellion: 1, Conspiracy: 2});
const name = getAdjective(states[neib].name) + " " + rebels;
- data.push({name, type: "Rebels", cells: cellsArray, fill: "url(#hatch3)"});
+ zonesData.push({name, type: "Rebels", cells: cellsArray, fill: "url(#hatch3)"});
}
function addProselytism() {
@@ -1625,7 +1624,7 @@ function addZones(number = 1) {
}
const name = getAdjective(organized.name.split(" ")[0]) + " Proselytism";
- data.push({name, type: "Proselytism", cells: cellsArray, fill: "url(#hatch6)"});
+ zonesData.push({name, type: "Proselytism", cells: cellsArray, fill: "url(#hatch6)"});
}
function addCrusade() {
@@ -1637,7 +1636,7 @@ function addZones(number = 1) {
cellsArray.forEach(i => (used[i] = 1));
const name = getAdjective(heresy.name.split(" ")[0]) + " Crusade";
- data.push({name, type: "Crusade", cells: cellsArray, fill: "url(#hatch6)"});
+ zonesData.push({name, type: "Crusade", cells: cellsArray, fill: "url(#hatch6)"});
}
function addDisease() {
@@ -1674,7 +1673,7 @@ function addZones(number = 1) {
const type = rw({Fever: 5, Pestilence: 2, Flu: 2, Pox: 2, Smallpox: 2, Plague: 4, Cholera: 2, Dropsy: 1, Leprosy: 2});
const name = rw({[color()]: 4, [animal()]: 2, [adjective()]: 1}) + " " + type;
- data.push({name, type: "Disease", cells: cellsArray, fill: "url(#hatch12)"});
+ zonesData.push({name, type: "Disease", cells: cellsArray, fill: "url(#hatch12)"});
}
function addDisaster() {
@@ -1706,7 +1705,7 @@ function addZones(number = 1) {
const type = rw({Famine: 5, Dearth: 1, Drought: 3, Earthquake: 3, Tornadoes: 1, Wildfires: 1});
const name = getAdjective(burg.name) + " " + type;
- data.push({name, type: "Disaster", cells: cellsArray, fill: "url(#hatch5)"});
+ zonesData.push({name, type: "Disaster", cells: cellsArray, fill: "url(#hatch5)"});
}
function addEruption() {
@@ -1737,7 +1736,7 @@ function addZones(number = 1) {
});
}
- data.push({name, type: "Disaster", cells: cellsArray, fill: "url(#hatch7)"});
+ zonesData.push({name, type: "Disaster", cells: cellsArray, fill: "url(#hatch7)"});
}
function addAvalanche() {
@@ -1762,7 +1761,7 @@ function addZones(number = 1) {
const proper = getAdjective(Names.getCultureShort(cells.culture[cell]));
const name = proper + " Avalanche";
- data.push({name, type: "Disaster", cells: cellsArray, fill: "url(#hatch5)"});
+ zonesData.push({name, type: "Disaster", cells: cellsArray, fill: "url(#hatch5)"});
}
function addFault() {
@@ -1787,7 +1786,7 @@ function addZones(number = 1) {
const proper = getAdjective(Names.getCultureShort(cells.culture[cell]));
const name = proper + " Fault";
- data.push({name, type: "Disaster", cells: cellsArray, fill: "url(#hatch2)"});
+ zonesData.push({name, type: "Disaster", cells: cellsArray, fill: "url(#hatch2)"});
}
function addFlood() {
@@ -1817,7 +1816,7 @@ function addZones(number = 1) {
}
const name = getAdjective(burgs[cells.burg[cell]].name) + " Flood";
- data.push({name, type: "Disaster", cells: cellsArray, fill: "url(#hatch13)"});
+ zonesData.push({name, type: "Disaster", cells: cellsArray, fill: "url(#hatch13)"});
}
function addTsunami() {
@@ -1845,13 +1844,13 @@ function addZones(number = 1) {
const proper = getAdjective(Names.getCultureShort(cells.culture[cell]));
const name = proper + " Tsunami";
- data.push({name, type: "Disaster", cells: cellsArray, fill: "url(#hatch13)"});
+ zonesData.push({name, type: "Disaster", cells: cellsArray, fill: "url(#hatch13)"});
}
- void (function drawZones() {
+ function drawZones() {
zones
.selectAll("g")
- .data(data)
+ .data(zonesData)
.enter()
.append("g")
.attr("id", (d, i) => "zone" + i)
@@ -1867,19 +1866,11 @@ function addZones(number = 1) {
.attr("id", function (d) {
return this.parentNode.id + "_" + d;
});
- })();
+ }
TIME && console.timeEnd("addZones");
}
-// Update zone types
-function updateZoneType(zoneId, newType) {
- const zone = document.getElementById(zoneId);
- if (zone) {
- zone.dataset.type = newType;
- }
-}
-
// show map stats on generation complete
function showStatistics() {
const template = templateInput.options[templateInput.selectedIndex].text;
diff --git a/modules/load.js b/modules/load.js
index a170e056..d358f15d 100644
--- a/modules/load.js
+++ b/modules/load.js
@@ -941,6 +941,10 @@ function parseLoadedData(data) {
// v1.73 moved the hatching patterns out of the user's SVG
document.getElementById("hatching")?.remove();
}
+
+ if (version < 1.731) {
+ // v1.731 added type to zones
+ }
})();
void (function checkDataIntegrity() {
diff --git a/modules/ui/zones-editor.js b/modules/ui/zones-editor.js
index 10cd6758..f897b299 100644
--- a/modules/ui/zones-editor.js
+++ b/modules/ui/zones-editor.js
@@ -18,9 +18,8 @@ function editZones() {
});
// add listeners
- document.getElementById("zonesFilterType").addEventListener("change", refreshZonesEditor);
- document.getElementById("zonesFilterButton").addEventListener("click", toggleFilterTable);
- document.getElementById("zonesEditorRefresh").addEventListener("click", refreshZonesEditor);
+ document.getElementById("zonesFilterType").addEventListener("change", filterZonesByType);
+ document.getElementById("zonesEditorRefresh").addEventListener("click", zonesEditorAddLines);
document.getElementById("zonesEditStyle").addEventListener("click", () => editStyle("zones"));
document.getElementById("zonesLegend").addEventListener("click", toggleLegend);
document.getElementById("zonesPercentage").addEventListener("click", togglePercentageMode);
@@ -28,8 +27,6 @@ function editZones() {
document.getElementById("zonesManuallyApply").addEventListener("click", applyZonesManualAssignent);
document.getElementById("zonesManuallyCancel").addEventListener("click", cancelZonesManualAssignent);
document.getElementById("zonesAdd").addEventListener("click", addZonesLayer);
- document.getElementById("zonesEditTypes").addEventListener("click", addZonesDialog);
- document.getElementById("zonesNewTypeButton").addEventListener("click", addZonesType);
document.getElementById("zonesExport").addEventListener("click", downloadZonesData);
document.getElementById("zonesRemove").addEventListener("click", toggleEraseMode);
@@ -51,68 +48,21 @@ function editZones() {
zone = el.parentNode.dataset.id;
if (el.classList.contains("religionName")) zones.select("#" + zone).attr("data-description", el.value);
});
-
- function refreshZonesEditor() {
- updateSVG();
- zonesEditorAddLines();
- }
-
- function updateSVG() {
- const value = document.getElementById("zonesFilterType").value;
- zones.selectAll("g").each(function () {
- if (value == "All" || this.dataset.type == value) {
- this.style.display = "block";
- } else {
- this.style.display = "none";
- }
- });
- }
-
- function getZoneTypesList(zoneId, currentType) {
- let res = `
';
-
- return res;
- }
-
-// add line for each zone
+ // add line for each zone
function zonesEditorAddLines() {
const unit = areaUnit.value === "square" ? " " + distanceUnitInput.value + "²" : " " + areaUnit.value;
let lines = "";
- // make sure all zone types are loaded from the SVG
zones.selectAll("g").each(function () {
- const zoneType = this.dataset.type;
- if (!zoneTypes.includes(zoneType)) { zoneTypes.push(zoneType); }
- });
-
- const selectedType = zonesFilterType.value || "All";
- zonesFilterType.options.length=0;
- zonesFilterType.options.add(new Option("All", "All", false, selectedType=="All"));
- zoneTypes.forEach(function(z, i) {
- zonesFilterType.options.add(new Option(z, z, false, selectedType==z));
- });
-
- let zoneCount=0;
- zones.selectAll("g").each(function () {
- zoneCount++;
- const zoneType = this.dataset.type;
- if (selectedType !== "All" && (zonesFilterButton.classList.contains("pressed") && zoneType !== selectedType)) return;
-
const c = this.dataset.cells ? this.dataset.cells.split(",").map(c => +c) : [];
const description = this.dataset.description;
+ const type = this.dataset.type;
const fill = this.getAttribute("fill");
const area = d3.sum(c.map(i => pack.cells.area[i])) * distanceScaleInput.value ** 2;
const rural = d3.sum(c.map(i => pack.cells.pop[i])) * populationRate;
const urban = d3.sum(c.map(i => pack.cells.burg[i]).map(b => pack.burgs[b].population)) * populationRate * urbanization;
const population = rural + urban;
- const zoneTypeList = getZoneTypesList(this.id, this.dataset.type);
const populationTip = `Total population: ${si(population)}; Rural population: ${si(rural)}; Urban population: ${si(urban)}. Click to change`;
const inactive = this.style.display === "none";
const focused = defs.select("#fog #focus" + this.id).size();
@@ -121,13 +71,13 @@ function editZones() {
data-cells=${c.length} data-area=${area} data-population=${population}>
+
${c.length}
${si(area) + unit}
${si(population)}
- ${zoneTypeList}
@@ -136,15 +86,6 @@ function editZones() {
});
body.innerHTML = lines;
- if (body.innerHTML === "") { body.innerHTML = `
Zero entries for this type. To see entries again, select "All" or disable the filter button
-
`; }
-
- for (let i=0; i
${z}${count}`;
- if (i > 5) {
- let id="removeZoneType" + i;
- lines += ``;
- }
- lines += '';
- });
- zoneTypeListBody.innerHTML = lines;
- zonesTypesFooterNumber.innerHTML = zoneTypes.length;
-
- for (let i=0; i