schema change
This commit is contained in:
@@ -3,53 +3,51 @@ import InputWithDropDown from "../../../../../ui/inputs/InputWithDropDown";
|
||||
import LabledDropdown from "../../../../../ui/inputs/LabledDropdown";
|
||||
|
||||
interface StorageActionProps {
|
||||
type: "store" | "spawn" | "default";
|
||||
value: string;
|
||||
maxCapacity: string;
|
||||
spawnedCount: string;
|
||||
min: number;
|
||||
max?: number;
|
||||
defaultValue: string;
|
||||
maxCapacityDefault: string;
|
||||
spawnedCountCefault: string;
|
||||
currentMaterialType: string;
|
||||
handleCapacityChange: (value: string) => void;
|
||||
handleSpawnCountChange: (value: string) => void;
|
||||
handleMaterialTypeChange: (value: string) => void;
|
||||
}
|
||||
|
||||
const StorageAction: React.FC<StorageActionProps> = ({ type, value, min, max, defaultValue, currentMaterialType, handleCapacityChange, handleMaterialTypeChange }) => {
|
||||
const StorageAction: React.FC<StorageActionProps> = ({ maxCapacity, spawnedCount, min, max, maxCapacityDefault, spawnedCountCefault, currentMaterialType, handleCapacityChange, handleSpawnCountChange, handleMaterialTypeChange }) => {
|
||||
return (
|
||||
<>
|
||||
{type === 'store' &&
|
||||
<InputWithDropDown
|
||||
label="Storage Capacity"
|
||||
value={value}
|
||||
min={min}
|
||||
step={1}
|
||||
max={max}
|
||||
defaultValue={defaultValue}
|
||||
activeOption="unit"
|
||||
onClick={() => { }}
|
||||
onChange={handleCapacityChange}
|
||||
/>
|
||||
}
|
||||
{type === 'spawn' &&
|
||||
<>
|
||||
<InputWithDropDown
|
||||
label="Spawn Capacity"
|
||||
value={value}
|
||||
min={min}
|
||||
step={1}
|
||||
max={max}
|
||||
defaultValue={defaultValue}
|
||||
activeOption="unit"
|
||||
onClick={() => { }}
|
||||
onChange={handleCapacityChange}
|
||||
/>
|
||||
<LabledDropdown
|
||||
label={"Material Type"}
|
||||
defaultOption={currentMaterialType}
|
||||
options={["Default material", "Material 1", "Material 2", "Material 3"]}
|
||||
onSelect={handleMaterialTypeChange}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
<InputWithDropDown
|
||||
key={'Storage Capacity'}
|
||||
label="Storage Capacity"
|
||||
value={maxCapacity}
|
||||
min={min}
|
||||
step={1}
|
||||
max={max}
|
||||
defaultValue={maxCapacityDefault}
|
||||
activeOption="unit"
|
||||
onClick={() => { }}
|
||||
onChange={handleCapacityChange}
|
||||
/>
|
||||
<InputWithDropDown
|
||||
key={"Spawn Count"}
|
||||
label="Spawn Count"
|
||||
value={spawnedCount}
|
||||
min={min}
|
||||
step={1}
|
||||
max={max}
|
||||
defaultValue={spawnedCountCefault}
|
||||
activeOption="unit"
|
||||
onClick={() => { }}
|
||||
onChange={handleSpawnCountChange}
|
||||
/>
|
||||
<LabledDropdown
|
||||
label={"Material Type"}
|
||||
defaultOption={currentMaterialType}
|
||||
options={["Default material", "Material 1", "Material 2", "Material 3"]}
|
||||
onSelect={handleMaterialTypeChange}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -14,10 +14,13 @@ import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
|
||||
|
||||
function StorageMechanics() {
|
||||
const [activeOption, setActiveOption] = useState<"default" | "store" | "spawn">("default");
|
||||
const [currentCapacity, setCurrentCapacity] = useState("1");
|
||||
const [spawnedCount, setSpawnedCount] = useState("0");
|
||||
const [spawnedMaterial, setSpawnedMaterial] = useState("Default material");
|
||||
const [selectedPointData, setSelectedPointData] = useState<StoragePointSchema | undefined>();
|
||||
const { selectedEventData } = useSelectedEventData();
|
||||
const { productStore } = useSceneContext();
|
||||
const { getPointByUuid, updateAction } = productStore();
|
||||
const { getPointByUuid, updateAction, updateEvent, getEventByModelUuid } = productStore();
|
||||
const { selectedProductStore } = useProductContext();
|
||||
const { selectedProduct } = selectedProductStore();
|
||||
const { setSelectedAction, clearSelectedAction } = useSelectedAction();
|
||||
@@ -52,6 +55,24 @@ function StorageMechanics() {
|
||||
setSelectedPointData(point);
|
||||
const uiOption = point.action.actionType === "retrieve" ? "spawn" : point.action.actionType;
|
||||
setActiveOption(uiOption as "store" | "spawn");
|
||||
setCurrentCapacity(
|
||||
(getEventByModelUuid(
|
||||
selectedProduct.productUuid,
|
||||
selectedEventData.data.modelUuid
|
||||
) as StorageEventSchema | undefined)?.storageCapacity?.toString() || "1"
|
||||
);
|
||||
setSpawnedCount(
|
||||
(getEventByModelUuid(
|
||||
selectedProduct.productUuid,
|
||||
selectedEventData.data.modelUuid
|
||||
) as StorageEventSchema | undefined)?.storageCount?.toString() || "0"
|
||||
)
|
||||
setSpawnedMaterial(
|
||||
(getEventByModelUuid(
|
||||
selectedProduct.productUuid,
|
||||
selectedEventData.data.modelUuid
|
||||
) as StorageEventSchema | undefined)?.materialType?.toString() || "Default material"
|
||||
)
|
||||
setSelectedAction(point.action.actionUuid, point.action.actionName);
|
||||
}
|
||||
} else {
|
||||
@@ -95,29 +116,55 @@ function StorageMechanics() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleRenameAction = (newName: string) => {
|
||||
if (!selectedPointData) return;
|
||||
const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { actionName: newName });
|
||||
|
||||
if (event) {
|
||||
updateBackend(
|
||||
selectedProduct.productName,
|
||||
selectedProduct.productUuid,
|
||||
projectId || '',
|
||||
event
|
||||
);
|
||||
updateSelectedPointData();
|
||||
}
|
||||
};
|
||||
|
||||
const handleCapacityChange = (value: string) => {
|
||||
if (!selectedEventData || !selectedPointData) return;
|
||||
const newCapacity = parseInt(value);
|
||||
|
||||
const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, {
|
||||
storageCapacity: newCapacity,
|
||||
const newCapacity = parseInt(value);
|
||||
let updatedEvent: EventsSchema | undefined;
|
||||
|
||||
updatedEvent = updateEvent(
|
||||
selectedProduct.productUuid,
|
||||
selectedEventData.data.modelUuid,
|
||||
{ storageCapacity: newCapacity }
|
||||
);
|
||||
|
||||
const currentCount = parseInt(spawnedCount);
|
||||
if (currentCount > newCapacity) {
|
||||
updatedEvent = updateEvent(
|
||||
selectedProduct.productUuid,
|
||||
selectedEventData.data.modelUuid,
|
||||
{ storageCount: newCapacity }
|
||||
);
|
||||
setSpawnedCount(newCapacity.toString());
|
||||
}
|
||||
|
||||
setCurrentCapacity(value);
|
||||
|
||||
if (updatedEvent) {
|
||||
updateBackend(
|
||||
selectedProduct.productName,
|
||||
selectedProduct.productUuid,
|
||||
projectId || '',
|
||||
updatedEvent
|
||||
);
|
||||
updateSelectedPointData();
|
||||
}
|
||||
};
|
||||
|
||||
const handleSpawnCountChange = (value: string) => {
|
||||
if (!selectedEventData || !selectedPointData) return;
|
||||
|
||||
const newCount = parseInt(value);
|
||||
const maxCapacity = parseInt(currentCapacity);
|
||||
|
||||
if (newCount > maxCapacity) return;
|
||||
|
||||
const event = updateEvent(selectedProduct.productUuid, selectedEventData.data.modelUuid, {
|
||||
storageCount: newCount,
|
||||
});
|
||||
|
||||
setSpawnedCount(value);
|
||||
|
||||
if (event) {
|
||||
updateBackend(
|
||||
selectedProduct.productName,
|
||||
@@ -129,19 +176,10 @@ function StorageMechanics() {
|
||||
}
|
||||
};
|
||||
|
||||
const createNewMaterial = (materialType: string): { materialType: string; materialId: string } | null => {
|
||||
if (!selectedEventData || !selectedPointData) return null;
|
||||
const materialId = THREE.MathUtils.generateUUID();
|
||||
return {
|
||||
materialType,
|
||||
materialId
|
||||
};
|
||||
};
|
||||
|
||||
const handleMaterialTypeChange = (value: string) => {
|
||||
if (!selectedEventData || !selectedPointData) return;
|
||||
|
||||
const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, {
|
||||
const event = updateEvent(selectedProduct.productUuid, selectedEventData.data.modelUuid, {
|
||||
materialType: value,
|
||||
});
|
||||
|
||||
@@ -161,16 +199,6 @@ function StorageMechanics() {
|
||||
[selectedPointData]
|
||||
);
|
||||
|
||||
const currentCapacity = useMemo(() =>
|
||||
selectedPointData ? selectedPointData.action.storageCapacity.toString() : "0",
|
||||
[selectedPointData]
|
||||
);
|
||||
|
||||
const currentMaterialType = useMemo(() =>
|
||||
selectedPointData?.action.materialType || "Default material",
|
||||
[selectedPointData]
|
||||
);
|
||||
|
||||
const availableActions = {
|
||||
defaultOption: "store",
|
||||
options: ["store", "spawn"],
|
||||
@@ -184,38 +212,44 @@ function StorageMechanics() {
|
||||
return (
|
||||
<>
|
||||
{selectedEventData && (
|
||||
<section>
|
||||
<ActionsList
|
||||
selectedPointData={selectedPointData}
|
||||
/>
|
||||
<div className="selected-actions-details">
|
||||
<div className="selected-actions-header">
|
||||
<RenameInput
|
||||
value={currentActionName}
|
||||
canEdit={false}
|
||||
/>
|
||||
<>
|
||||
<section>
|
||||
<StorageAction
|
||||
maxCapacity={currentCapacity}
|
||||
spawnedCount={spawnedCount}
|
||||
maxCapacityDefault="0"
|
||||
spawnedCountCefault="0"
|
||||
min={0}
|
||||
currentMaterialType={spawnedMaterial}
|
||||
handleCapacityChange={handleCapacityChange}
|
||||
handleSpawnCountChange={handleSpawnCountChange}
|
||||
handleMaterialTypeChange={handleMaterialTypeChange}
|
||||
/>
|
||||
</section>
|
||||
<section>
|
||||
<ActionsList
|
||||
selectedPointData={selectedPointData}
|
||||
/>
|
||||
<div className="selected-actions-details">
|
||||
<div className="selected-actions-header">
|
||||
<RenameInput
|
||||
value={currentActionName}
|
||||
canEdit={false}
|
||||
/>
|
||||
</div>
|
||||
<div className="selected-actions-list">
|
||||
<LabledDropdown
|
||||
defaultOption={activeOption}
|
||||
options={availableActions.options}
|
||||
onSelect={handleActionTypeChange}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="selected-actions-list">
|
||||
<LabledDropdown
|
||||
defaultOption={activeOption}
|
||||
options={availableActions.options}
|
||||
onSelect={handleActionTypeChange}
|
||||
/>
|
||||
<StorageAction
|
||||
type={activeOption}
|
||||
value={currentCapacity}
|
||||
defaultValue="0"
|
||||
min={0}
|
||||
currentMaterialType={currentMaterialType}
|
||||
handleCapacityChange={handleCapacityChange}
|
||||
handleMaterialTypeChange={handleMaterialTypeChange}
|
||||
/>
|
||||
<div className="tirgger">
|
||||
<Trigger selectedPointData={selectedPointData as any} type={'StorageUnit'} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="tirgger">
|
||||
<Trigger selectedPointData={selectedPointData as any} type={'StorageUnit'} />
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user