smooth selection with zone and structureLayer

This commit is contained in:
wass08
2026-01-26 08:34:23 +09:00
parent 1861173428
commit 63d3c1524f
@@ -20,7 +20,7 @@ const isNodeInCurrentLevel = (node: AnyNode): boolean => {
return nodeLevelId === currentLevelId; return nodeLevelId === currentLevelId;
}; };
type SelectableNodeType = "wall" | "item" | "building"; type SelectableNodeType = "wall" | "item" | "building" | "zone";
interface SelectionStrategy { interface SelectionStrategy {
types: SelectableNodeType[]; types: SelectableNodeType[];
@@ -44,29 +44,44 @@ const SELECTION_STRATEGIES: Record<string, SelectionStrategy> = {
}, },
structure: { structure: {
types: ["wall", "item"], types: ["wall", "item", "zone"],
handleSelect: (node, isShift) => { handleSelect: (node, isShift) => {
const { selection, setSelection } = useViewer.getState(); const { selection, setSelection } = useViewer.getState();
if (node.type === 'zone') {
setSelection({ zoneId: node.id });
} else {
const nextIds = isShift const nextIds = isShift
? selection.selectedIds.includes(node.id) ? selection.selectedIds.includes(node.id)
? selection.selectedIds.filter((id) => id !== node.id) ? selection.selectedIds.filter((id) => id !== node.id)
: [...selection.selectedIds, node.id] : [...selection.selectedIds, node.id]
: [node.id]; : [node.id];
setSelection({ selectedIds: nextIds }); setSelection({ selectedIds: nextIds });
}
}, },
handleDeselect: () => { handleDeselect: () => {
useViewer.getState().setSelection({ selectedIds: [] }); const structureLayer = useEditor.getState().structureLayer;
if (structureLayer === "zones") {
useViewer.getState().setSelection({ zoneId: null });
} else {
useViewer.getState().setSelection({ selectedIds: [] });
}
}, },
isValid: (node) => { isValid: (node) => {
if (!isNodeInCurrentLevel(node)) return false; if (!isNodeInCurrentLevel(node)) return false;
if (node.type === "wall") return true; const structureLayer = useEditor.getState().structureLayer;
if (node.type === "item") { if (structureLayer === "zones") {
return ( if (node.type === "zone") return true;
(node as ItemNode).asset.category === "door" || return false;
(node as ItemNode).asset.category === "window" } else {
); if (node.type === "wall") return true;
if (node.type === "item") {
return (
(node as ItemNode).asset.category === "door" ||
(node as ItemNode).asset.category === "window"
);
}
return false;
} }
return false;
}, },
}, },