From 61d4d52589b372d5cffa18e46326ecf33c923eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Montero=20Lamas?= Date: Sun, 6 Feb 2022 21:09:30 +0100 Subject: [PATCH] Zone filter (#728) * Adding zone type dropdown to index.html * added zone type filter to zones-editor.js * zoneTypes dialog add and delete types, dialog * filtering types * correct filter button and prompt The filter button now works on click with an added zonesEditorAddLines(); on function toggleFilterTable(). If the table is empty, a message appears on a line giving advice. * Amount of types and fixes Fixed some spacing in zoneTypes dialog, and made a count for the amount of zones per type. * Minor changes for zone types * dialog for types on a button New button for the zone Types dialog. * typo in index.html * update on click add type Co-authored-by: Evolvedexperiment Co-authored-by: Azgaar --- main.js | 9 +++++ modules/ui/zones-editor.js | 77 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/main.js b/main.js index 434fdba5..4138ed74 100644 --- a/main.js +++ b/main.js @@ -158,6 +158,7 @@ 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 @@ -2056,6 +2057,14 @@ function addZones(number = 1) { 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 heightmap = byId("templateInput").value; diff --git a/modules/ui/zones-editor.js b/modules/ui/zones-editor.js index 759447dd..bc58c17f 100644 --- a/modules/ui/zones-editor.js +++ b/modules/ui/zones-editor.js @@ -30,6 +30,8 @@ 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); @@ -52,6 +54,14 @@ function editZones() { if (el.classList.contains("zoneName")) zone.attr("data-description", el.value); else if (el.classList.contains("zoneType")) zone.attr("data-type", el.value); }); + + function refreshZonesEditor() { + updateSVG(); + zonesEditorAddLines(); + } + + function updateSVG() { + const value = document.getElementById("zonesFilterType").value; // update type filter with a list of used types function updateFilters() { @@ -82,6 +92,7 @@ function editZones() { 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 = zoneEl.style.display === "none"; const focused = defs.select("#fog #focus" + zoneEl.id).size(); @@ -97,6 +108,7 @@ function editZones() {
${si(area) + unit}
${si(population)}
+ ${zoneTypeList} @@ -363,6 +375,11 @@ function editZones() { zonesEditorAddLines(); } } + + function toggleFilterTable() { + this.classList.toggle("pressed"); + zonesEditorAddLines(); + } function addZonesLayer() { const id = getNextId("zone"); @@ -470,6 +487,66 @@ function editZones() { } } + function zonesTypesAddLines() { + const zoneTypeListBody = document.getElementById("zonesTypesBodySection"); + + let lines = ""; + zoneTypes.forEach(function(z, i) { + let count=0; // Amount of zones per type + zones.selectAll("g").each(function() { if (this.dataset.type === z) count++; }); + + lines += `
${z}${count}`; + if (i > 5) { + let id="removeZoneType" + i; + lines += ``; + } + lines += '
'; + }); + zoneTypeListBody.innerHTML = lines; + zonesTypesFooterNumber.innerHTML = zoneTypes.length; + + for (let i=0; i