Enhance StorageMechanics: improve material handling in spawn mode, update capacity change logic, and streamline material creation
This commit is contained in:
parent
42d465a977
commit
11fc5c2dbf
|
@ -21,6 +21,7 @@ function StorageMechanics() {
|
||||||
setCurrentMaterials,
|
setCurrentMaterials,
|
||||||
clearCurrentMaterials,
|
clearCurrentMaterials,
|
||||||
updateStorageUnitLoad,
|
updateStorageUnitLoad,
|
||||||
|
getStorageUnitById,
|
||||||
} = useStorageUnitStore();
|
} = useStorageUnitStore();
|
||||||
|
|
||||||
const email = localStorage.getItem('email')
|
const email = localStorage.getItem('email')
|
||||||
|
@ -76,13 +77,20 @@ function StorageMechanics() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validOption === "spawn") {
|
if (validOption === "spawn") {
|
||||||
clearCurrentMaterials(selectedEventData.data.modelUuid);
|
const storageUnit = getStorageUnitById(selectedEventData.data.modelUuid);
|
||||||
updateStorageUnitLoad(selectedEventData.data.modelUuid, selectedPointData.action.storageCapacity);
|
if (storageUnit) {
|
||||||
} else {
|
|
||||||
const materialType = selectedPointData.action.materialType || "default";
|
const materialType = selectedPointData.action.materialType || "default";
|
||||||
|
const materials = Array.from({ length: selectedPointData.action.storageCapacity }, () =>
|
||||||
|
createNewMaterial(materialType)
|
||||||
|
).filter(Boolean) as { materialType: string; materialId: string }[];
|
||||||
|
|
||||||
|
setCurrentMaterials(selectedEventData.data.modelUuid, materials);
|
||||||
updateStorageUnitLoad(selectedEventData.data.modelUuid, selectedPointData.action.storageCapacity);
|
updateStorageUnitLoad(selectedEventData.data.modelUuid, selectedPointData.action.storageCapacity);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
clearCurrentMaterials(selectedEventData.data.modelUuid);
|
||||||
|
updateStorageUnitLoad(selectedEventData.data.modelUuid, 0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRenameAction = (newName: string) => {
|
const handleRenameAction = (newName: string) => {
|
||||||
|
@ -115,34 +123,41 @@ function StorageMechanics() {
|
||||||
event
|
event
|
||||||
);
|
);
|
||||||
|
|
||||||
if (activeOption === "store") {
|
if (activeOption === "spawn") {
|
||||||
|
const storageUnit = getStorageUnitById(selectedEventData.data.modelUuid);
|
||||||
|
if (storageUnit) {
|
||||||
const materialType = selectedPointData.action.materialType || "default";
|
const materialType = selectedPointData.action.materialType || "default";
|
||||||
|
const currentCount = storageUnit.currentMaterials.length;
|
||||||
|
|
||||||
|
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);
|
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;
|
if (!selectedEventData || !selectedPointData) return null;
|
||||||
const materialId = THREE.MathUtils.generateUUID();
|
const materialId = THREE.MathUtils.generateUUID();
|
||||||
return {
|
return {
|
||||||
materialId,
|
|
||||||
materialName: `${materialType}-${Date.now()}`,
|
|
||||||
materialType,
|
materialType,
|
||||||
isActive: false,
|
materialId
|
||||||
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
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -161,8 +176,15 @@ function StorageMechanics() {
|
||||||
event
|
event
|
||||||
);
|
);
|
||||||
|
|
||||||
if (activeOption === "store") {
|
if (activeOption === "spawn") {
|
||||||
const capacity = selectedPointData.action.storageCapacity || 0;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue