mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-03-24 08:07:23 +01:00
Fix zones restoration in risk heightmap edit mode
Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
This commit is contained in:
parent
350aff8bf5
commit
fed86420e8
1 changed files with 14 additions and 27 deletions
|
|
@ -330,15 +330,12 @@ function editHeightmap(options) {
|
||||||
c.y = p[1];
|
c.y = p[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// recalculate zones to grid
|
// recalculate zones to grid - store grid cell IDs in pack.zones
|
||||||
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");
|
// Convert pack cell IDs to grid cell IDs
|
||||||
const cells = dataCells ? dataCells.split(",").map(i => +i) : [];
|
zone.gridCells = zone.cells.map(i => pack.cells.g[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 +445,14 @@ function editHeightmap(options) {
|
||||||
Lakes.defineNames();
|
Lakes.defineNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore zones from grid
|
// restore zones from grid - convert grid cell IDs back to pack cell IDs
|
||||||
zones.selectAll("g").each(function () {
|
for (const zone of pack.zones) {
|
||||||
const zone = d3.select(this);
|
if (!zone.gridCells || !zone.gridCells.length) continue;
|
||||||
const g = zone.attr("data-cells");
|
// Find pack cells that correspond to the stored grid cells
|
||||||
const gCells = g ? g.split(",").map(i => +i) : [];
|
zone.cells = pack.cells.i.filter(i => zone.gridCells.includes(pack.cells.g[i]));
|
||||||
const cells = pack.cells.i.filter(i => gCells.includes(pack.cells.g[i]));
|
// Clean up temporary storage
|
||||||
|
delete zone.gridCells;
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
// recalculate ice
|
// recalculate ice
|
||||||
Ice.generate();
|
Ice.generate();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue