Skip to content

Commit 13ec798

Browse files
CopilotAzgaar
andauthored
Fix zones not recovering after heightmap edit in Risk mode (#1327)
* 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>
1 parent da9e915 commit 13ec798

3 files changed

Lines changed: 19 additions & 29 deletions

File tree

public/modules/ui/heightmap-editor.js

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,11 @@ function editHeightmap(options) {
330330
c.y = p[1];
331331
}
332332

333-
// recalculate zones to grid
334-
zones.selectAll("g").each(function () {
335-
const zone = d3.select(this);
336-
const dataCells = zone.attr("data-cells");
337-
const cells = dataCells ? dataCells.split(",").map(i => +i) : [];
338-
const g = cells.map(i => pack.cells.g[i]);
339-
zone.attr("data-cells", g);
340-
zone.selectAll("*").remove();
341-
});
333+
const zoneGridCellsMap = new Map();
334+
for (const zone of pack.zones) {
335+
if (!zone.cells || !zone.cells.length) continue;
336+
zoneGridCellsMap.set(zone.i, zone.cells.map(i => pack.cells.g[i]));
337+
}
342338

343339
Features.markupGrid();
344340
if (erosionAllowed) addLakesInDeepDepressions();
@@ -448,24 +444,18 @@ function editHeightmap(options) {
448444
Lakes.defineNames();
449445
}
450446

451-
// restore zones from grid
452-
zones.selectAll("g").each(function () {
453-
const zone = d3.select(this);
454-
const g = zone.attr("data-cells");
455-
const gCells = g ? g.split(",").map(i => +i) : [];
456-
const cells = pack.cells.i.filter(i => gCells.includes(pack.cells.g[i]));
457-
458-
zone.attr("data-cells", cells);
459-
zone.selectAll("*").remove();
460-
const base = zone.attr("id") + "_"; // id generic part
461-
zone
462-
.selectAll("*")
463-
.data(cells)
464-
.enter()
465-
.append("polygon")
466-
.attr("points", d => getPackPolygon(d))
467-
.attr("id", d => base + d);
468-
});
447+
const gridToPackMap = new Map();
448+
for (const i of pack.cells.i) {
449+
const g = pack.cells.g[i];
450+
if (!gridToPackMap.has(g)) gridToPackMap.set(g, []);
451+
gridToPackMap.get(g).push(i);
452+
}
453+
454+
for (const zone of pack.zones) {
455+
const gridCells = zoneGridCellsMap.get(zone.i);
456+
if (!gridCells || !gridCells.length) continue;
457+
zone.cells = gridCells.flatMap(g => gridToPackMap.get(g) || []);
458+
}
469459

470460
// recalculate ice
471461
Ice.generate();

public/versioning.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2
1414
*/
1515

16-
const VERSION = "1.112.1";
16+
const VERSION = "1.112.2";
1717
if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function");
1818

1919
{

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8511,7 +8511,7 @@
85118511
<script defer src="modules/ui/editors.js?v=1.112.1"></script>
85128512
<script defer src="modules/ui/tools.js?v=1.111.0"></script>
85138513
<script defer src="modules/ui/world-configurator.js?v=1.105.4"></script>
8514-
<script defer src="modules/ui/heightmap-editor.js?v=1.105.2"></script>
8514+
<script defer src="modules/ui/heightmap-editor.js?v=1.112.2"></script>
85158515
<script defer src="modules/ui/provinces-editor.js?v=1.108.1"></script>
85168516
<script defer src="modules/ui/biomes-editor.js?v=1.112.0"></script>
85178517
<script defer src="modules/ui/namesbase-editor.js?v=1.105.11"></script>

0 commit comments

Comments
 (0)