Add box brush command helpers and implementations

This commit is contained in:
2026-03-31 02:03:30 +02:00
parent afd2e1e011
commit 50bec99748
4 changed files with 278 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
import { cloneEditorSelection, type EditorSelection } from "../core/selection";
import type { BoxBrush } from "../document/brushes";
import type { SceneDocument } from "../document/scene-document";
export function getBoxBrushOrThrow(document: SceneDocument, brushId: string): BoxBrush {
const brush = document.brushes[brushId];
if (brush === undefined) {
throw new Error(`Box brush ${brushId} does not exist.`);
}
if (brush.kind !== "box") {
throw new Error(`Brush ${brushId} is not a supported box brush.`);
}
return brush;
}
export function setSingleBrushSelection(brushId: string): EditorSelection {
return {
kind: "brushes",
ids: [brushId]
};
}
export function cloneSelectionForCommand(selection: EditorSelection): EditorSelection {
return cloneEditorSelection(selection);
}
export function replaceBrush(document: SceneDocument, brush: BoxBrush): SceneDocument {
return {
...document,
brushes: {
...document.brushes,
[brush.id]: brush
}
};
}
export function removeBrush(document: SceneDocument, brushId: string): SceneDocument {
const { [brushId]: _removedBrush, ...remainingBrushes } = document.brushes;
return {
...document,
brushes: remainingBrushes
};
}