From 13ec798ffb2f63702baeb5872509eac0780ce93d Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Feb 2026 23:33:18 +0100 Subject: [PATCH] Fix zones not recovering after heightmap edit in Risk mode (#1327) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Initial plan * Fix zones restoration in risk heightmap edit mode Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> * Remove comments from zones restoration code Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> * Optimize zones restoration with O(n) map lookup instead of O(n²) Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> * Use local Map for zone backup instead of mutating zone objects Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> * Update version to 1.112.2 and heightmap-editor.js cache hash Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> --- public/modules/ui/heightmap-editor.js | 42 ++++++++++----------------- public/versioning.js | 2 +- src/index.html | 2 +- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/public/modules/ui/heightmap-editor.js b/public/modules/ui/heightmap-editor.js index 6e76c4bb..e204055a 100644 --- a/public/modules/ui/heightmap-editor.js +++ b/public/modules/ui/heightmap-editor.js @@ -330,15 +330,11 @@ function editHeightmap(options) { c.y = p[1]; } - // recalculate zones to grid - zones.selectAll("g").each(function () { - const zone = d3.select(this); - const dataCells = zone.attr("data-cells"); - const cells = dataCells ? dataCells.split(",").map(i => +i) : []; - const g = cells.map(i => pack.cells.g[i]); - zone.attr("data-cells", g); - zone.selectAll("*").remove(); - }); + const zoneGridCellsMap = new Map(); + for (const zone of pack.zones) { + if (!zone.cells || !zone.cells.length) continue; + zoneGridCellsMap.set(zone.i, zone.cells.map(i => pack.cells.g[i])); + } Features.markupGrid(); if (erosionAllowed) addLakesInDeepDepressions(); @@ -448,24 +444,18 @@ function editHeightmap(options) { Lakes.defineNames(); } - // restore zones from grid - zones.selectAll("g").each(function () { - const zone = d3.select(this); - const g = zone.attr("data-cells"); - const gCells = g ? g.split(",").map(i => +i) : []; - const cells = pack.cells.i.filter(i => gCells.includes(pack.cells.g[i])); + const gridToPackMap = new Map(); + for (const i of pack.cells.i) { + const g = pack.cells.g[i]; + if (!gridToPackMap.has(g)) gridToPackMap.set(g, []); + gridToPackMap.get(g).push(i); + } - zone.attr("data-cells", cells); - zone.selectAll("*").remove(); - const base = zone.attr("id") + "_"; // id generic part - zone - .selectAll("*") - .data(cells) - .enter() - .append("polygon") - .attr("points", d => getPackPolygon(d)) - .attr("id", d => base + d); - }); + for (const zone of pack.zones) { + const gridCells = zoneGridCellsMap.get(zone.i); + if (!gridCells || !gridCells.length) continue; + zone.cells = gridCells.flatMap(g => gridToPackMap.get(g) || []); + } // recalculate ice Ice.generate(); diff --git a/public/versioning.js b/public/versioning.js index fd2a67a2..056b30e2 100644 --- a/public/versioning.js +++ b/public/versioning.js @@ -13,7 +13,7 @@ * Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2 */ -const VERSION = "1.112.1"; +const VERSION = "1.112.2"; if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function"); { diff --git a/src/index.html b/src/index.html index 668803de..ca605c87 100644 --- a/src/index.html +++ b/src/index.html @@ -8511,7 +8511,7 @@ - +