Refactor aisle API services: remove createAisleApi, update deleteAisleApi to include versionId, and modify wall asset APIs for consistency in endpoint naming. Enhance floor and wall store functionality with new setters and methods for managing floors and walls, including decal handling. Introduce FloorInstance and FloorInstances components for rendering floor data, and implement FloorCreator for interactive floor creation. Add reference floor visualization with snapping capabilities. Update wall API services for improved error handling and response management.
This commit is contained in:
@@ -7,14 +7,29 @@ interface FloorStore {
|
||||
addFloor: (floor: Floor) => void;
|
||||
updateFloor: (uuid: string, updated: Partial<Floor>) => void;
|
||||
removeFloor: (uuid: string) => void;
|
||||
removePointFromFloors: (pointUuid: string) => void;
|
||||
removePoint: (pointUuid: string) => Floor[];
|
||||
removeFloorByPoints: (Points: [Point, Point]) => Floor[];
|
||||
clearFloors: () => void;
|
||||
setPosition: (
|
||||
pointUuid: string,
|
||||
position: [number, number, number]
|
||||
) => Floor | undefined;
|
||||
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;
|
||||
addDecal: (floors: string, decal: Decal) => void;
|
||||
updateDecal: (decalUuid: string, decal: Decal) => void;
|
||||
removeDecal: (decalUuid: string) => void;
|
||||
updateDecalPosition: (decalUuid: string, position: [number, number, number]) => void;
|
||||
updateDecalRotation: (decalUuid: string, rotation: number) => void;
|
||||
updateDecalScale: (decalUuid: string, scale: number) => void;
|
||||
|
||||
getFloorById: (uuid: string) => Floor | undefined;
|
||||
getFloorsByPointId: (uuid: string) => Floor | undefined;
|
||||
getFloorByPoints: (points: Point[]) => Floor | undefined;
|
||||
getFloorPointById: (uuid: string) => Point | undefined;
|
||||
getConnectedPoints: (uuid: string) => Point[];
|
||||
}
|
||||
|
||||
export const createFloorStore = () => {
|
||||
@@ -41,16 +56,98 @@ export const createFloorStore = () => {
|
||||
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);
|
||||
}
|
||||
}),
|
||||
removePoint: (pointUuid) => {
|
||||
const removedFloors: Floor[] = [];
|
||||
|
||||
set(state => {
|
||||
const updatedFloors: Floor[] = [];
|
||||
|
||||
for (const floor of state.floors) {
|
||||
const hasPoint = floor.points.some(p => p.pointUuid === pointUuid);
|
||||
if (!hasPoint) {
|
||||
updatedFloors.push(floor);
|
||||
continue;
|
||||
}
|
||||
|
||||
const remainingPoints = floor.points.filter(p => p.pointUuid !== pointUuid);
|
||||
if (remainingPoints.length > 2) {
|
||||
floor.points = remainingPoints;
|
||||
updatedFloors.push(floor);
|
||||
} else {
|
||||
removedFloors.push(floor);
|
||||
}
|
||||
}
|
||||
|
||||
state.floors = updatedFloors;
|
||||
});
|
||||
|
||||
return removedFloors;
|
||||
},
|
||||
removeFloorByPoints: ([pointA, pointB]) => {
|
||||
const removedFloors: Floor[] = [];
|
||||
|
||||
set(state => {
|
||||
const updatedFloors: Floor[] = [];
|
||||
|
||||
for (const floor of state.floors) {
|
||||
const indices = floor.points
|
||||
.map((p, i) => ({ uuid: p.pointUuid, index: i }));
|
||||
|
||||
const idxA = indices.find(i => i.uuid === pointA.pointUuid)?.index ?? -1;
|
||||
const idxB = indices.find(i => i.uuid === pointB.pointUuid)?.index ?? -1;
|
||||
|
||||
if (idxA === -1 || idxB === -1) {
|
||||
updatedFloors.push(floor);
|
||||
continue;
|
||||
}
|
||||
|
||||
const areAdjacent =
|
||||
Math.abs(idxA - idxB) === 1 ||
|
||||
(idxA === 0 && idxB === floor.points.length - 1) ||
|
||||
(idxB === 0 && idxA === floor.points.length - 1);
|
||||
|
||||
if (!areAdjacent) {
|
||||
updatedFloors.push(floor);
|
||||
continue;
|
||||
}
|
||||
|
||||
const remainingPoints = floor.points.filter(
|
||||
p => p.pointUuid !== pointA.pointUuid && p.pointUuid !== pointB.pointUuid
|
||||
);
|
||||
|
||||
if (remainingPoints.length > 2) {
|
||||
floor.points = remainingPoints;
|
||||
updatedFloors.push(floor);
|
||||
} else {
|
||||
removedFloors.push(floor);
|
||||
}
|
||||
}
|
||||
|
||||
state.floors = updatedFloors;
|
||||
});
|
||||
|
||||
return removedFloors;
|
||||
},
|
||||
|
||||
clearFloors: () => set(state => {
|
||||
state.floors = [];
|
||||
}),
|
||||
|
||||
setPosition: (pointUuid, position) => {
|
||||
let updatedFloor: Floor | undefined;
|
||||
set((state) => {
|
||||
for (const floor of state.floors) {
|
||||
const point = floor.points.find((p) => p.pointUuid === pointUuid);
|
||||
if (point) {
|
||||
point.position = position;
|
||||
updatedFloor = JSON.parse(JSON.stringify(floor));
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return updatedFloor;
|
||||
},
|
||||
|
||||
setIsBeveled: (uuid, isBeveled) => set(state => {
|
||||
const floor = state.floors.find(f => f.floorUuid === uuid);
|
||||
if (floor) {
|
||||
@@ -80,9 +177,97 @@ export const createFloorStore = () => {
|
||||
}
|
||||
}),
|
||||
|
||||
addDecal: (floorUuid, decal) => set(state => {
|
||||
const floor = state.floors.find(f => f.floorUuid === floorUuid);
|
||||
if (floor) {
|
||||
floor.decals.push(decal);
|
||||
}
|
||||
}),
|
||||
|
||||
updateDecal: (decalUuid, updatedDecal) => set(state => {
|
||||
for (const floor of state.floors) {
|
||||
const index = floor.decals.findIndex(d => d.decalUuid === decalUuid);
|
||||
if (index !== -1) {
|
||||
floor.decals[index] = updatedDecal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
removeDecal: (decalUuid) => set(state => {
|
||||
for (const floor of state.floors) {
|
||||
floor.decals = floor.decals.filter(d => d.decalUuid !== decalUuid);
|
||||
}
|
||||
}),
|
||||
|
||||
updateDecalPosition: (decalUuid, position) => set(state => {
|
||||
for (const floor of state.floors) {
|
||||
const decal = floor.decals.find(d => d.decalUuid === decalUuid);
|
||||
if (decal) {
|
||||
decal.decalPosition = position;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
updateDecalRotation: (decalUuid, rotation) => set(state => {
|
||||
for (const floor of state.floors) {
|
||||
const decal = floor.decals.find(d => d.decalUuid === decalUuid);
|
||||
if (decal) {
|
||||
decal.decalRotation = rotation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
updateDecalScale: (decalUuid, scale) => set(state => {
|
||||
for (const floor of state.floors) {
|
||||
const decal = floor.decals.find(d => d.decalUuid === decalUuid);
|
||||
if (decal) {
|
||||
decal.decalScale = scale;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
|
||||
getFloorById: (uuid) => {
|
||||
return get().floors.find(f => f.floorUuid === uuid);
|
||||
},
|
||||
|
||||
getFloorsByPointId: (pointUuid) => {
|
||||
return get().floors.find(floor =>
|
||||
floor.points.some(p => p.pointUuid === pointUuid)
|
||||
);
|
||||
},
|
||||
|
||||
getFloorByPoints: (points) => {
|
||||
return get().floors.find(floor => {
|
||||
const floorPointIds = new Set(floor.points.map(p => p.pointUuid));
|
||||
const givenPointIds = new Set(points.map(p => p.pointUuid));
|
||||
return floorPointIds.size === givenPointIds.size &&
|
||||
[...floorPointIds].every(id => givenPointIds.has(id));
|
||||
});
|
||||
},
|
||||
|
||||
getFloorPointById: (pointUuid) => {
|
||||
for (const floor of get().floors) {
|
||||
const point = floor.points.find(p => p.pointUuid === pointUuid);
|
||||
if (point) return point;
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getConnectedPoints: (pointUuid) => {
|
||||
const connected: Point[] = [];
|
||||
for (const floor of get().floors) {
|
||||
if (floor.points.some(p => p.pointUuid === pointUuid)) {
|
||||
connected.push(...floor.points.filter(p => p.pointUuid !== pointUuid));
|
||||
}
|
||||
}
|
||||
return connected;
|
||||
}
|
||||
|
||||
}))
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user