feat: Enhance material handling and storage unit interactions; refactor MaterialAnimator and useRetrieveHandler for improved state management

This commit is contained in:
2025-08-04 12:00:48 +05:30
parent 0da9e8997c
commit c9cc8d3534
6 changed files with 168 additions and 63 deletions

View File

@@ -1,15 +1,26 @@
import * as THREE from 'three';
import { create } from 'zustand';
import { immer } from 'zustand/middleware/immer';
interface MaterialPosition {
materialId: string;
position: THREE.Vector3;
}
type MaterialsStore = {
materials: MaterialsSchema;
materialHistory: MaterialHistorySchema;
materialPositions: MaterialPosition[];
addMaterial: (material: MaterialSchema) => MaterialSchema | undefined;
removeMaterial: (materialId: string) => MaterialSchema | undefined;
clearMaterials: () => void;
updateMaterial: (materialId: string, updates: Partial<MaterialSchema>) => MaterialSchema | undefined;
setMaterialPositions: (materialPosition: MaterialPosition[]) => void;
getMaterialPosition: (materialId: string) => THREE.Vector3 | undefined;
setPreviousLocation: (
materialId: string,
location: {
@@ -61,6 +72,7 @@ export const createMaterialStore = () => {
immer((set, get) => ({
materials: [],
materialHistory: [],
materialPositions: [],
addMaterial: (material) => {
let updatedMaterial: MaterialSchema | undefined;
@@ -262,6 +274,23 @@ export const createMaterialStore = () => {
return updatedMaterial;
},
setMaterialPositions: (materials) => {
set((state) => {
state.materialPositions = materials;
});
},
getMaterialPosition: (materialid) => {
let position: THREE.Vector3 | undefined;
set((state) => {
const material = state.materialPositions.find(m => m.materialId === materialid);
if (material) {
position = material.position;
}
});
return position;
},
getMaterialById: (materialId) => {
return get().materials.find(m => m.materialId === materialId);
},