diff --git a/src/commands/path-junction-maintenance.ts b/src/commands/path-junction-maintenance.ts new file mode 100644 index 00000000..ae9215bc --- /dev/null +++ b/src/commands/path-junction-maintenance.ts @@ -0,0 +1,40 @@ +import { cloneScenePath, type ScenePath } from "../document/paths"; +import type { SceneDocument } from "../document/scene-document"; +import { + cloneSplineCorridorJunction, + type SplineCorridorJunctionRegistry +} from "../document/spline-corridor-junctions"; +import { reattachSplineCorridorJunctionsToPaths } from "../spline-corridor/spline-corridor-junctions"; + +export function cloneSplineCorridorJunctionRegistry( + junctions: SplineCorridorJunctionRegistry +): SplineCorridorJunctionRegistry { + return Object.fromEntries( + Object.entries(junctions).map(([junctionId, junction]) => [ + junctionId, + cloneSplineCorridorJunction(junction) + ]) + ); +} + +export function setScenePathAndReattachJunctions( + document: SceneDocument, + path: ScenePath +): SceneDocument { + const nextPath = cloneScenePath(path); + const nextPaths = { + ...document.paths, + [nextPath.id]: nextPath + }; + + return { + ...document, + paths: nextPaths, + splineCorridorJunctions: reattachSplineCorridorJunctionsToPaths({ + paths: Object.values(nextPaths), + junctions: document.splineCorridorJunctions, + changedPathIds: [nextPath.id], + terrains: Object.values(document.terrains) + }) + }; +}