Refactor path point addition to correctly manage and reattach spline corridor junctions
This commit is contained in:
@@ -9,8 +9,13 @@ import {
|
|||||||
getScenePathPointIndex,
|
getScenePathPointIndex,
|
||||||
type ScenePathPoint
|
type ScenePathPoint
|
||||||
} from "../document/paths";
|
} from "../document/paths";
|
||||||
|
import type { SplineCorridorJunctionRegistry } from "../document/spline-corridor-junctions";
|
||||||
|
|
||||||
import type { EditorCommand } from "./command";
|
import type { EditorCommand } from "./command";
|
||||||
|
import {
|
||||||
|
cloneSplineCorridorJunctionRegistry,
|
||||||
|
setScenePathAndReattachJunctions
|
||||||
|
} from "./path-junction-maintenance";
|
||||||
|
|
||||||
interface AddPathPointCommandOptions {
|
interface AddPathPointCommandOptions {
|
||||||
pathId: string;
|
pathId: string;
|
||||||
@@ -35,6 +40,7 @@ export function createAddPathPointCommand(
|
|||||||
): EditorCommand {
|
): EditorCommand {
|
||||||
let addedPoint: ScenePathPoint | null =
|
let addedPoint: ScenePathPoint | null =
|
||||||
options.point === undefined ? null : cloneScenePathPoint(options.point);
|
options.point === undefined ? null : cloneScenePathPoint(options.point);
|
||||||
|
let previousJunctions: SplineCorridorJunctionRegistry | null = null;
|
||||||
let previousSelection: EditorSelection | null = null;
|
let previousSelection: EditorSelection | null = null;
|
||||||
let previousToolMode: ToolMode | null = null;
|
let previousToolMode: ToolMode | null = null;
|
||||||
|
|
||||||
@@ -64,6 +70,12 @@ export function createAddPathPointCommand(
|
|||||||
previousToolMode = context.getToolMode();
|
previousToolMode = context.getToolMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (previousJunctions === null) {
|
||||||
|
previousJunctions = cloneSplineCorridorJunctionRegistry(
|
||||||
|
currentDocument.splineCorridorJunctions
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const insertionIndex =
|
const insertionIndex =
|
||||||
options.insertAfterPointId === undefined
|
options.insertAfterPointId === undefined
|
||||||
? path.points.length
|
? path.points.length
|
||||||
@@ -75,11 +87,10 @@ export function createAddPathPointCommand(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.setDocument({
|
context.setDocument(
|
||||||
...currentDocument,
|
setScenePathAndReattachJunctions(
|
||||||
paths: {
|
currentDocument,
|
||||||
...currentDocument.paths,
|
cloneScenePath({
|
||||||
[path.id]: cloneScenePath({
|
|
||||||
...path,
|
...path,
|
||||||
points: [
|
points: [
|
||||||
...path.points.slice(0, insertionIndex),
|
...path.points.slice(0, insertionIndex),
|
||||||
@@ -87,8 +98,8 @@ export function createAddPathPointCommand(
|
|||||||
...path.points.slice(insertionIndex)
|
...path.points.slice(insertionIndex)
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
}
|
)
|
||||||
});
|
);
|
||||||
context.setSelection(
|
context.setSelection(
|
||||||
setSelectedPathPointSelection(options.pathId, addedPoint.id)
|
setSelectedPathPointSelection(options.pathId, addedPoint.id)
|
||||||
);
|
);
|
||||||
@@ -114,7 +125,11 @@ export function createAddPathPointCommand(
|
|||||||
...path,
|
...path,
|
||||||
points: path.points.filter((point) => point.id !== addedPoint?.id)
|
points: path.points.filter((point) => point.id !== addedPoint?.id)
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
|
splineCorridorJunctions:
|
||||||
|
previousJunctions === null
|
||||||
|
? currentDocument.splineCorridorJunctions
|
||||||
|
: cloneSplineCorridorJunctionRegistry(previousJunctions)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (previousSelection !== null) {
|
if (previousSelection !== null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user