Add sfx:grid-snap on cursor cell-cross for shelf + spawn

Matches the wall / slab / curve-wall tool pattern: emit
sfx:grid-snap only when the snapped position changes (cursor crosses
a grid cell), not every frame of mouse movement within the same cell.
Tracked via a `previousSnapRef` per tool, reset when the tool
re-activates.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Wassim SAMAD
2026-05-14 15:01:56 -04:00
co-authored by Claude Opus 4.7
parent 76794ceb7d
commit d17e083c77
2 changed files with 21 additions and 0 deletions
+10
View File
@@ -50,13 +50,23 @@ const PREVIEW_BRACKET_DEPTH = PREVIEW_DEPTH * 0.7
const ShelfTool = () => {
const activeLevelId = useViewer((state) => state.selection.levelId)
const cursorRef = useRef<Group>(null)
const previousSnapRef = useRef<[number, number] | null>(null)
useEffect(() => {
if (!activeLevelId) return
previousSnapRef.current = null
const onGridMove = (event: GridEvent) => {
const [sx, sz] = snapPointToGrid([event.localPosition[0], event.localPosition[2]], GRID_STEP)
cursorRef.current?.position.set(sx, event.localPosition[1], sz)
// Fire grid-snap SFX only when the snapped position crosses a cell,
// matching the wall / slab / curve tools.
const prev = previousSnapRef.current
if (!prev || prev[0] !== sx || prev[1] !== sz) {
triggerSFX('sfx:grid-snap')
previousSnapRef.current = [sx, sz]
}
}
const onGridClick = (event: GridEvent) => {