Add snapToGrid and label options to resize box brush command
This commit is contained in:
@@ -11,11 +11,14 @@ import type { EditorCommand } from "./command";
|
|||||||
interface ResizeBoxBrushCommandOptions {
|
interface ResizeBoxBrushCommandOptions {
|
||||||
brushId: string;
|
brushId: string;
|
||||||
size: Vec3;
|
size: Vec3;
|
||||||
|
snapToGrid?: boolean;
|
||||||
gridSize?: number;
|
gridSize?: number;
|
||||||
|
label?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createResizeBoxBrushCommand(options: ResizeBoxBrushCommandOptions): EditorCommand {
|
export function createResizeBoxBrushCommand(options: ResizeBoxBrushCommandOptions): EditorCommand {
|
||||||
const snappedSize = snapPositiveSizeToGrid(options.size, options.gridSize ?? DEFAULT_GRID_SIZE);
|
const resolvedSize =
|
||||||
|
options.snapToGrid === false ? options.size : snapPositiveSizeToGrid(options.size, options.gridSize ?? DEFAULT_GRID_SIZE);
|
||||||
|
|
||||||
let previousSize: Vec3 | null = null;
|
let previousSize: Vec3 | null = null;
|
||||||
let previousSelection: EditorSelection | null = null;
|
let previousSelection: EditorSelection | null = null;
|
||||||
@@ -23,7 +26,7 @@ export function createResizeBoxBrushCommand(options: ResizeBoxBrushCommandOption
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
id: createOpaqueId("command"),
|
id: createOpaqueId("command"),
|
||||||
label: "Resize box brush",
|
label: options.label ?? "Resize box brush",
|
||||||
execute(context) {
|
execute(context) {
|
||||||
const currentDocument = context.getDocument();
|
const currentDocument = context.getDocument();
|
||||||
const brush = getBoxBrushOrThrow(currentDocument, options.brushId);
|
const brush = getBoxBrushOrThrow(currentDocument, options.brushId);
|
||||||
@@ -46,7 +49,7 @@ export function createResizeBoxBrushCommand(options: ResizeBoxBrushCommandOption
|
|||||||
replaceBrush(currentDocument, {
|
replaceBrush(currentDocument, {
|
||||||
...brush,
|
...brush,
|
||||||
size: {
|
size: {
|
||||||
...snappedSize
|
...resolvedSize
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user