From fa95a05d0f5255db0507ed4260e3192c6ae3d914 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 13 May 2026 20:01:02 +0200 Subject: [PATCH] Implement utilities for cloning and reattaching spline corridor junctions to paths --- src/commands/path-junction-maintenance.ts | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/commands/path-junction-maintenance.ts 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) + }) + }; +}