mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-04-04 14:37:24 +02:00
fix: improve deep cloning for graph and resampling to handle non-cloneable properties
This commit is contained in:
parent
f2fc42799b
commit
b80dc94e1b
3 changed files with 54 additions and 5 deletions
|
|
@ -260,7 +260,14 @@ function getName(id) {
|
|||
}
|
||||
|
||||
function getGraph(currentGraph) {
|
||||
const newGraph = shouldRegenerateGrid(currentGraph, seed) ? generateGrid() : structuredClone(currentGraph);
|
||||
if (shouldRegenerateGrid(currentGraph, seed)) return generateGrid();
|
||||
|
||||
// Deep clone avoiding non-cloneable properties (like D3 quadtrees with functions)
|
||||
const newGraph = JSON.parse(JSON.stringify(currentGraph));
|
||||
// Recreate voronoi cells since JSON doesn't preserve typed arrays or circular refs
|
||||
const {cells, vertices} = calculateVoronoi(newGraph.points, newGraph.boundary);
|
||||
newGraph.cells = cells;
|
||||
newGraph.vertices = vertices;
|
||||
delete newGraph.cells.h;
|
||||
return newGraph;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue