Merge remote-tracking branch 'origin/dev-r3f-wall' into merge/wall-collab

This commit is contained in:
2025-06-30 15:57:56 +05:30
21 changed files with 609 additions and 700 deletions

View File

@@ -473,6 +473,7 @@ export const useWidgetSubOption = create<any>((set: any) => ({
widgetSubOption: "2D",
setWidgetSubOption: (x: any) => set({ widgetSubOption: x }),
}));
export const useLimitDistance = create<any>((set: any) => ({
limitDistance: true,
setLimitDistance: (x: any) => set({ limitDistance: x }),

View File

@@ -257,8 +257,7 @@ export const createFloorStore = () => {
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));
return floorPointIds.size === givenPointIds.size && [...floorPointIds].every(id => givenPointIds.has(id));
});
},

View File

@@ -10,11 +10,19 @@ interface ZoneStore {
setZoneHeight: (uuid: string, height: number) => void;
setZoneColor: (uuid: string, color: string) => void;
removeZone: (uuid: string) => void;
removePointFromZones: (pointUuid: string) => void;
removePoint: (pointUuid: string) => { removedZones: Zone[], updatedZones: Zone[] };
removeZoneByPoints: (points: Point[]) => { removedZones: Zone[], updatedZones: Zone[] };
clearZones: () => void;
setPosition: (
pointUuid: string,
position: [number, number, number]
) => Zone[] | [];
setViewPort: (uuid: string, position: [number, number, number], target: [number, number, number]) => void;
getZoneById: (uuid: string) => Zone | undefined;
getZonesByPointId: (uuid: string) => Zone[] | [];
getZoneByPoints: (points: Point[]) => Zone | undefined;
getZonePointById: (uuid: string) => Point | undefined;
getConnectedPoints: (uuid: string) => Point[];
}
@@ -63,16 +71,97 @@ export const createZoneStore = () => {
state.zones = state.zones.filter(z => z.zoneUuid !== uuid);
}),
removePointFromZones: (pointUuid) => set(state => {
for (const zone of state.zones) {
zone.points = zone.points.filter(p => p.pointUuid !== pointUuid);
}
}),
removePoint: (pointUuid) => {
const removedZones: Zone[] = [];
const updatedZones: Zone[] = [];
set(state => {
for (const zone of state.zones) {
const pointIndex = zone.points.findIndex(p => p.pointUuid === pointUuid);
if (pointIndex === -1) {
updatedZones.push(JSON.parse(JSON.stringify(zone)));
continue;
}
const remainingPoints = zone.points.filter(p => p.pointUuid !== pointUuid);
if (remainingPoints.length <= 2) {
removedZones.push(JSON.parse(JSON.stringify(zone)));
continue;
}
zone.points = remainingPoints;
updatedZones.push(JSON.parse(JSON.stringify(zone)));
}
state.zones = updatedZones;
});
return { removedZones, updatedZones };
},
removeZoneByPoints: ([pointA, pointB]) => {
const removedZones: Zone[] = [];
const updatedZones: Zone[] = [];
set(state => {
for (const zone of state.zones) {
const indices = zone.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) {
updatedZones.push(JSON.parse(JSON.stringify(zone)));
continue;
}
const areAdjacent =
Math.abs(idxA - idxB) === 1 ||
(idxA === 0 && idxB === zone.points.length - 1) ||
(idxB === 0 && idxA === zone.points.length - 1);
if (!areAdjacent) {
updatedZones.push(JSON.parse(JSON.stringify(zone)));
continue;
}
const remainingPoints = zone.points.filter(
p => p.pointUuid !== pointA.pointUuid && p.pointUuid !== pointB.pointUuid
);
if (remainingPoints.length > 2) {
zone.points = remainingPoints;
updatedZones.push(JSON.parse(JSON.stringify(zone)));
} else {
removedZones.push(JSON.parse(JSON.stringify(zone)));
}
}
state.zones = updatedZones;
});
return { removedZones, updatedZones };
},
clearZones: () => set(state => {
state.zones = [];
}),
setPosition: (pointUuid, position) => {
let updatedZone: Zone[] = [];
set((state) => {
for (const zone of state.zones) {
const point = zone.points.find((p) => p.pointUuid === pointUuid);
if (point) {
point.position = position;
updatedZone.push(JSON.parse(JSON.stringify(zone)));
}
}
});
return updatedZone;
},
setViewPort: (uuid, position, target) => set(state => {
const zone = state.zones.find(z => z.zoneUuid === uuid);
if (zone) {
@@ -85,6 +174,28 @@ export const createZoneStore = () => {
return get().zones.find(z => z.zoneUuid === uuid);
},
getZonesByPointId: (pointUuid) => {
return get().zones.filter(zone => {
return zone.points.some(p => p.pointUuid === pointUuid);
});
},
getZoneByPoints: (points) => {
return get().zones.find(zone => {
const zonePointIds = new Set(zone.points.map(p => p.pointUuid));
const givenPointIds = new Set(points.map(p => p.pointUuid));
return zonePointIds.size === givenPointIds.size && [...zonePointIds].every(id => givenPointIds.has(id));
});
},
getZonePointById: (pointUuid) => {
for (const zone of get().zones) {
const point = zone.points.find(p => p.pointUuid === pointUuid);
if (point) return point;
}
return undefined;
},
getConnectedPoints: (pointUuid) => {
const connected: Point[] = [];
for (const zone of get().zones) {