From 645e454f62bd198cd6a5520ca88a12ae2ea94553 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sat, 4 Apr 2026 19:30:47 +0200 Subject: [PATCH] Enhance whitebox snap functionality and update status messages --- src/app/App.tsx | 60 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/src/app/App.tsx b/src/app/App.tsx index 4e152091..9de2a8b2 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -1953,10 +1953,21 @@ export function App({ store, initialStatusMessage }: AppProps) { }, center: null }, - "Previewing a box brush. Click in the viewport to create it." + `Previewing a whitebox box. Click in the viewport to create it${whiteboxSnapEnabled ? ` on the ${whiteboxSnapStep}m grid` : ""}.` ); }; + const handleWhiteboxSnapToggle = () => { + const nextEnabled = !whiteboxSnapEnabled; + setWhiteboxSnapEnabled(nextEnabled); + setStatusMessage(nextEnabled ? `Grid snap enabled at ${whiteboxSnapStep}m.` : "Grid snap disabled for whitebox transforms."); + }; + + const handleWhiteboxSnapStepBlur = () => { + const normalizedStep = resolveOptionalPositiveNumber(whiteboxSnapStepDraft, DEFAULT_GRID_SIZE); + setWhiteboxSnapStepDraft(String(normalizedStep)); + }; + const applySelection = ( selection: EditorSelection, source: "outliner" | "viewport" | "inspector" | "runner", @@ -1999,24 +2010,50 @@ export function App({ store, initialStatusMessage }: AppProps) { const applyPositionChange = () => { if (selectedBrush === null) { - setStatusMessage("Select a box brush before moving it."); + setStatusMessage("Select a whitebox box before moving it."); return; } try { - const snappedCenter = snapVec3ToGrid(readVec3Draft(positionDraft, "Box brush position"), DEFAULT_GRID_SIZE); + const nextCenter = maybeSnapVec3(readVec3Draft(positionDraft, "Whitebox box position"), whiteboxSnapEnabled, whiteboxSnapStep); - if (areVec3Equal(snappedCenter, selectedBrush.center)) { + if (areVec3Equal(nextCenter, selectedBrush.center)) { return; } store.executeCommand( createMoveBoxBrushCommand({ brushId: selectedBrush.id, - center: snappedCenter + center: nextCenter, + snapToGrid: false }) ); - setStatusMessage("Moved selected box brush."); + setStatusMessage("Moved selected whitebox box."); + } catch (error) { + setStatusMessage(getErrorMessage(error)); + } + }; + + const applyRotationChange = () => { + if (selectedBrush === null) { + setStatusMessage("Select a whitebox box before rotating it."); + return; + } + + try { + const nextRotationDegrees = readVec3Draft(rotationDraft, "Whitebox box rotation"); + + if (areVec3Equal(nextRotationDegrees, selectedBrush.rotationDegrees)) { + return; + } + + store.executeCommand( + createRotateBoxBrushCommand({ + brushId: selectedBrush.id, + rotationDegrees: nextRotationDegrees + }) + ); + setStatusMessage("Rotated selected whitebox box."); } catch (error) { setStatusMessage(getErrorMessage(error)); } @@ -2024,24 +2061,25 @@ export function App({ store, initialStatusMessage }: AppProps) { const applySizeChange = () => { if (selectedBrush === null) { - setStatusMessage("Select a box brush before resizing it."); + setStatusMessage("Select a whitebox box before scaling it."); return; } try { - const snappedSize = snapPositiveSizeToGrid(readVec3Draft(sizeDraft, "Box brush size"), DEFAULT_GRID_SIZE); + const nextSize = maybeSnapPositiveSize(readVec3Draft(sizeDraft, "Whitebox box size"), whiteboxSnapEnabled, whiteboxSnapStep); - if (areVec3Equal(snappedSize, selectedBrush.size)) { + if (areVec3Equal(nextSize, selectedBrush.size)) { return; } store.executeCommand( createResizeBoxBrushCommand({ brushId: selectedBrush.id, - size: snappedSize + size: nextSize, + snapToGrid: false }) ); - setStatusMessage("Resized selected box brush."); + setStatusMessage("Scaled selected whitebox box."); } catch (error) { setStatusMessage(getErrorMessage(error)); }