nice state switch
This commit is contained in:
@@ -28,9 +28,9 @@ export function ActionMenu({ className }: { className?: string }) {
|
|||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{/* Structure Tools Row - Animated */}
|
{/* Item Catalog Row - Only show when in build mode with item tool */}
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{tool === "item" && catalogCategory && (
|
{mode === "build" && tool === "item" && catalogCategory && (
|
||||||
<motion.div
|
<motion.div
|
||||||
className={cn(
|
className={cn(
|
||||||
"overflow-hidden border-zinc-800 max-h-96 border-b px-2 py-2",
|
"overflow-hidden border-zinc-800 max-h-96 border-b px-2 py-2",
|
||||||
|
|||||||
@@ -26,12 +26,18 @@ export const tools: ToolConfig[] = [
|
|||||||
export function StructureTools() {
|
export function StructureTools() {
|
||||||
const activeTool = useEditor((state) => state.tool)
|
const activeTool = useEditor((state) => state.tool)
|
||||||
const catalogCategory = useEditor((state) => state.catalogCategory)
|
const catalogCategory = useEditor((state) => state.catalogCategory)
|
||||||
|
const structureLayer = useEditor((state) => state.structureLayer)
|
||||||
const setTool = useEditor((state) => state.setTool)
|
const setTool = useEditor((state) => state.setTool)
|
||||||
const setCatalogCategory = useEditor((state) => state.setCatalogCategory)
|
const setCatalogCategory = useEditor((state) => state.setCatalogCategory)
|
||||||
|
|
||||||
|
// Filter tools based on structureLayer
|
||||||
|
const visibleTools = structureLayer === 'zones'
|
||||||
|
? tools.filter((t) => t.id === 'zone')
|
||||||
|
: tools.filter((t) => t.id !== 'zone')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-1.5">
|
||||||
{tools.map((tool, index) => {
|
{visibleTools.map((tool, index) => {
|
||||||
// For item tools with catalog category, check both tool and category match
|
// For item tools with catalog category, check both tool and category match
|
||||||
const isActive =
|
const isActive =
|
||||||
activeTool === tool.id &&
|
activeTool === tool.id &&
|
||||||
|
|||||||
@@ -401,11 +401,14 @@ function ContentSection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function StructurePhaseView() {
|
function StructurePhaseView() {
|
||||||
|
const phase = useEditor((state) => state.phase);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-full">
|
<div className="flex flex-col h-full">
|
||||||
<BuildingSelector />
|
<BuildingSelector />
|
||||||
<LevelsSection />
|
<LevelsSection />
|
||||||
<LayerToggle />
|
{/* Only show layer toggle in structure phase, furnish is always elements */}
|
||||||
|
{phase === "structure" && <LayerToggle />}
|
||||||
<div className="flex-1 overflow-auto">
|
<div className="flex-1 overflow-auto">
|
||||||
<ContentSection />
|
<ContentSection />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ const useEditor = create<EditorState>()((set, get) => ({
|
|||||||
|
|
||||||
set({ phase })
|
set({ phase })
|
||||||
|
|
||||||
|
// Clear tool and catalog when switching phases
|
||||||
|
set({ tool: null, catalogCategory: null })
|
||||||
|
|
||||||
const viewer = useViewer.getState()
|
const viewer = useViewer.getState()
|
||||||
const scene = useScene.getState()
|
const scene = useScene.getState()
|
||||||
|
|
||||||
@@ -116,21 +119,51 @@ const useEditor = create<EditorState>()((set, get) => ({
|
|||||||
case 'furnish':
|
case 'furnish':
|
||||||
selectBuildingAndLevel0()
|
selectBuildingAndLevel0()
|
||||||
viewer.setLevelMode('solo')
|
viewer.setLevelMode('solo')
|
||||||
|
// Furnish mode only supports elements layer, not zones
|
||||||
|
set({ structureLayer: 'elements' })
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mode: 'select',
|
mode: 'select',
|
||||||
setMode: (mode) => set({ mode }),
|
setMode: (mode) => {
|
||||||
|
set({ mode })
|
||||||
|
|
||||||
|
const { phase, structureLayer, tool } = get()
|
||||||
|
|
||||||
|
// When entering build mode in structure phase with zones layer, activate zone tool
|
||||||
|
if (mode === 'build' && phase === 'structure' && structureLayer === 'zones') {
|
||||||
|
set({ tool: 'zone' })
|
||||||
|
}
|
||||||
|
// When leaving build mode, clear tool
|
||||||
|
else if (mode !== 'build' && tool) {
|
||||||
|
set({ tool: null })
|
||||||
|
}
|
||||||
|
},
|
||||||
tool: null,
|
tool: null,
|
||||||
setTool: (tool) => set({ tool }),
|
setTool: (tool) => set({ tool }),
|
||||||
structureLayer: 'elements',
|
structureLayer: 'elements',
|
||||||
setStructureLayer: (layer) => {
|
setStructureLayer: (layer) => {
|
||||||
|
const { mode, tool } = get()
|
||||||
set({ structureLayer: layer })
|
set({ structureLayer: layer })
|
||||||
|
|
||||||
const viewer = useViewer.getState()
|
const viewer = useViewer.getState()
|
||||||
viewer.setSelection({
|
viewer.setSelection({
|
||||||
selectedIds: [],
|
selectedIds: [],
|
||||||
zoneId: null,
|
zoneId: null,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Handle tool changes based on layer
|
||||||
|
if (layer === 'zones') {
|
||||||
|
// In zones layer with build mode, activate zone tool
|
||||||
|
if (mode === 'build') {
|
||||||
|
set({ tool: 'zone' })
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// In elements layer, clear zone tool if it was active
|
||||||
|
if (tool === 'zone') {
|
||||||
|
set({ tool: null })
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
catalogCategory: null,
|
catalogCategory: null,
|
||||||
setCatalogCategory: (category) => set({ catalogCategory: category }),
|
setCatalogCategory: (category) => set({ catalogCategory: category }),
|
||||||
|
|||||||
Reference in New Issue
Block a user