Refactor builder store and remove wall store - Consolidated wall-related state management into the builder store by removing the useWallStore. - Added new properties and setters for wall attributes (thickness, height, materials) in the builder store. - Introduced SelectedWallProperties and WallProperties components for managing wall properties in the sidebar. - Created a new floor store for managing floor-related state. - Added a wall asset store for managing wall assets. - Implemented a zone store for managing zones and their properties. - Updated sidebar styles for better layout and appearance.
90 lines
3.0 KiB
TypeScript
90 lines
3.0 KiB
TypeScript
import { create } from 'zustand';
|
|
import { immer } from 'zustand/middleware/immer';
|
|
|
|
interface FloorStore {
|
|
floors: Floor[];
|
|
setFloors: (floors: Floor[]) => void;
|
|
addFloor: (floor: Floor) => void;
|
|
updateFloor: (uuid: string, updated: Partial<Floor>) => void;
|
|
removeFloor: (uuid: string) => void;
|
|
removePointFromFloors: (pointUuid: string) => void;
|
|
clearFloors: () => void;
|
|
setIsBeveled: (uuid: string, isBeveled: boolean) => void;
|
|
setBevelStrength: (uuid: string, strength: number) => void;
|
|
setDepth: (uuid: string, depth: number) => void;
|
|
setMaterial: (uuid: string, sideMaterial: string, topMaterial: string) => void;
|
|
|
|
getFloorById: (uuid: string) => Floor | undefined;
|
|
}
|
|
|
|
export const createFloorStore = () => {
|
|
return create<FloorStore>()(
|
|
immer((set, get) => ({
|
|
floors: [],
|
|
|
|
setFloors: (floors) => set(state => {
|
|
state.floors = floors;
|
|
}),
|
|
|
|
addFloor: (floor) => set(state => {
|
|
state.floors.push(floor);
|
|
}),
|
|
|
|
updateFloor: (uuid, updated) => set(state => {
|
|
const floor = state.floors.find(f => f.floorUuid === uuid);
|
|
if (floor) {
|
|
Object.assign(floor, updated);
|
|
}
|
|
}),
|
|
|
|
removeFloor: (uuid) => set(state => {
|
|
state.floors = state.floors.filter(f => f.floorUuid !== uuid);
|
|
}),
|
|
|
|
removePointFromFloors: (pointUuid) => set(state => {
|
|
for (const floor of state.floors) {
|
|
floor.points = floor.points.filter(p => p.pointUuid !== pointUuid);
|
|
}
|
|
}),
|
|
|
|
clearFloors: () => set(state => {
|
|
state.floors = [];
|
|
}),
|
|
|
|
setIsBeveled: (uuid, isBeveled) => set(state => {
|
|
const floor = state.floors.find(f => f.floorUuid === uuid);
|
|
if (floor) {
|
|
floor.isBeveled = isBeveled;
|
|
}
|
|
}),
|
|
|
|
setBevelStrength: (uuid, strength) => set(state => {
|
|
const floor = state.floors.find(f => f.floorUuid === uuid);
|
|
if (floor) {
|
|
floor.bevelStrength = strength;
|
|
}
|
|
}),
|
|
|
|
setDepth: (uuid, depth) => set(state => {
|
|
const floor = state.floors.find(f => f.floorUuid === uuid);
|
|
if (floor) {
|
|
floor.floorDepth = depth;
|
|
}
|
|
}),
|
|
|
|
setMaterial: (uuid, sideMaterial, topMaterial) => set(state => {
|
|
const floor = state.floors.find(f => f.floorUuid === uuid);
|
|
if (floor) {
|
|
floor.sideMaterial = sideMaterial;
|
|
floor.topMaterial = topMaterial;
|
|
}
|
|
}),
|
|
|
|
getFloorById: (uuid) => {
|
|
return get().floors.find(f => f.floorUuid === uuid);
|
|
},
|
|
}))
|
|
);
|
|
};
|
|
|
|
export type FloorStoreType = ReturnType<typeof createFloorStore>; |