v2-ui #84

Merged
Vishnu merged 53 commits from v2-ui into main 2025-05-10 13:42:19 +00:00
1 changed files with 48 additions and 26 deletions
Showing only changes of commit 11fc5c2dbf - Show all commits

View File

@ -21,6 +21,7 @@ function StorageMechanics() {
setCurrentMaterials,
clearCurrentMaterials,
updateStorageUnitLoad,
getStorageUnitById,
} = useStorageUnitStore();
const email = localStorage.getItem('email')
@ -76,12 +77,19 @@ function StorageMechanics() {
}
if (validOption === "spawn") {
clearCurrentMaterials(selectedEventData.data.modelUuid);
updateStorageUnitLoad(selectedEventData.data.modelUuid, selectedPointData.action.storageCapacity);
} else {
const materialType = selectedPointData.action.materialType || "default";
const storageUnit = getStorageUnitById(selectedEventData.data.modelUuid);
if (storageUnit) {
const materialType = selectedPointData.action.materialType || "default";
const materials = Array.from({ length: selectedPointData.action.storageCapacity }, () =>
createNewMaterial(materialType)
).filter(Boolean) as { materialType: string; materialId: string }[];
updateStorageUnitLoad(selectedEventData.data.modelUuid, selectedPointData.action.storageCapacity);
setCurrentMaterials(selectedEventData.data.modelUuid, materials);
updateStorageUnitLoad(selectedEventData.data.modelUuid, selectedPointData.action.storageCapacity);
}
} else {
clearCurrentMaterials(selectedEventData.data.modelUuid);
updateStorageUnitLoad(selectedEventData.data.modelUuid, 0);
}
};
@ -115,34 +123,41 @@ function StorageMechanics() {
event
);
if (activeOption === "store") {
const materialType = selectedPointData.action.materialType || "default";
if (activeOption === "spawn") {
const storageUnit = getStorageUnitById(selectedEventData.data.modelUuid);
if (storageUnit) {
const materialType = selectedPointData.action.materialType || "default";
const currentCount = storageUnit.currentMaterials.length;
updateStorageUnitLoad(selectedEventData.data.modelUuid, newCapacity);
if (newCapacity > currentCount) {
const newMaterials = Array.from({ length: newCapacity - currentCount }, () =>
createNewMaterial(materialType)
).filter(Boolean) as { materialType: string; materialId: string }[];
setCurrentMaterials(selectedEventData.data.modelUuid, [
...storageUnit.currentMaterials,
...newMaterials
]);
} else if (newCapacity < currentCount) {
setCurrentMaterials(
selectedEventData.data.modelUuid,
storageUnit.currentMaterials.slice(0, newCapacity)
);
}
updateStorageUnitLoad(selectedEventData.data.modelUuid, newCapacity);
}
} else {
updateStorageUnitLoad(selectedEventData.data.modelUuid, 0);
}
}
};
const createNewMaterial = (materialType: string): MaterialSchema | null => {
const createNewMaterial = (materialType: string): { materialType: string; materialId: string } | null => {
if (!selectedEventData || !selectedPointData) return null;
const materialId = THREE.MathUtils.generateUUID();
return {
materialId,
materialName: `${materialType}-${Date.now()}`,
materialType,
isActive: false,
isVisible: true,
isPaused: false,
isRendered: true,
startTime: performance.now(),
current: {
modelUuid: selectedEventData.data.modelUuid || '',
pointUuid: selectedPointData?.uuid || '',
actionUuid: selectedPointData?.action.actionUuid || ''
},
endTime: undefined,
previous: undefined,
next: null
materialId
};
};
@ -161,8 +176,15 @@ function StorageMechanics() {
event
);
if (activeOption === "store") {
const capacity = selectedPointData.action.storageCapacity || 0;
if (activeOption === "spawn") {
const storageUnit = getStorageUnitById(selectedEventData.data.modelUuid);
if (storageUnit) {
const materials = Array.from({ length: storageUnit.currentMaterials.length }, () =>
createNewMaterial(value)
).filter(Boolean) as { materialType: string; materialId: string }[];
setCurrentMaterials(selectedEventData.data.modelUuid, materials);
}
}
}
};