Fix zones not recovering after heightmap edit in Risk mode (#1327)
Some checks are pending
Deploy static content to Pages / deploy (push) Waiting to run
Code quality / quality (push) Waiting to run

* 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>
This commit is contained in:
Copilot 2026-02-18 23:33:18 +01:00 committed by GitHub
parent da9e915cdc
commit 13ec798ffb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 28 deletions

View file

@ -330,15 +330,11 @@ function editHeightmap(options) {
c.y = p[1]; c.y = p[1];
} }
// recalculate zones to grid const zoneGridCellsMap = new Map();
zones.selectAll("g").each(function () { for (const zone of pack.zones) {
const zone = d3.select(this); if (!zone.cells || !zone.cells.length) continue;
const dataCells = zone.attr("data-cells"); zoneGridCellsMap.set(zone.i, zone.cells.map(i => pack.cells.g[i]));
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();
});
Features.markupGrid(); Features.markupGrid();
if (erosionAllowed) addLakesInDeepDepressions(); if (erosionAllowed) addLakesInDeepDepressions();
@ -448,24 +444,18 @@ function editHeightmap(options) {
Lakes.defineNames(); Lakes.defineNames();
} }
// restore zones from grid const gridToPackMap = new Map();
zones.selectAll("g").each(function () { for (const i of pack.cells.i) {
const zone = d3.select(this); const g = pack.cells.g[i];
const g = zone.attr("data-cells"); if (!gridToPackMap.has(g)) gridToPackMap.set(g, []);
const gCells = g ? g.split(",").map(i => +i) : []; gridToPackMap.get(g).push(i);
const cells = pack.cells.i.filter(i => gCells.includes(pack.cells.g[i])); }
zone.attr("data-cells", cells); for (const zone of pack.zones) {
zone.selectAll("*").remove(); const gridCells = zoneGridCellsMap.get(zone.i);
const base = zone.attr("id") + "_"; // id generic part if (!gridCells || !gridCells.length) continue;
zone zone.cells = gridCells.flatMap(g => gridToPackMap.get(g) || []);
.selectAll("*") }
.data(cells)
.enter()
.append("polygon")
.attr("points", d => getPackPolygon(d))
.attr("id", d => base + d);
});
// recalculate ice // recalculate ice
Ice.generate(); Ice.generate();

View file

@ -13,7 +13,7 @@
* Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2 * 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"); if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function");
{ {

View file

@ -8511,7 +8511,7 @@
<script defer src="modules/ui/editors.js?v=1.112.1"></script> <script defer src="modules/ui/editors.js?v=1.112.1"></script>
<script defer src="modules/ui/tools.js?v=1.111.0"></script> <script defer src="modules/ui/tools.js?v=1.111.0"></script>
<script defer src="modules/ui/world-configurator.js?v=1.105.4"></script> <script defer src="modules/ui/world-configurator.js?v=1.105.4"></script>
<script defer src="modules/ui/heightmap-editor.js?v=1.105.2"></script> <script defer src="modules/ui/heightmap-editor.js?v=1.112.2"></script>
<script defer src="modules/ui/provinces-editor.js?v=1.108.1"></script> <script defer src="modules/ui/provinces-editor.js?v=1.108.1"></script>
<script defer src="modules/ui/biomes-editor.js?v=1.112.0"></script> <script defer src="modules/ui/biomes-editor.js?v=1.112.0"></script>
<script defer src="modules/ui/namesbase-editor.js?v=1.105.11"></script> <script defer src="modules/ui/namesbase-editor.js?v=1.105.11"></script>