2025-06-10 15:28:23 +05:30
|
|
|
import { useEffect } from 'react';
|
|
|
|
|
import { useActionHandler } from '../actions/useActionHandler';
|
|
|
|
|
import { usePlayButtonStore, useResetButtonStore } from '../../../store/usePlayButtonStore';
|
|
|
|
|
import { determineExecutionOrder } from './functions/determineExecutionOrder';
|
|
|
|
|
import { useProductContext } from '../products/productContext';
|
2025-06-23 09:37:53 +05:30
|
|
|
import { useSceneContext } from '../../scene/sceneContext';
|
2025-06-10 15:28:23 +05:30
|
|
|
|
|
|
|
|
function Simulator() {
|
|
|
|
|
const { selectedProductStore } = useProductContext();
|
2025-06-23 09:37:53 +05:30
|
|
|
const { productStore } = useSceneContext();
|
|
|
|
|
const { products, getProductById } = productStore();
|
2025-06-10 15:28:23 +05:30
|
|
|
const { handleAction } = useActionHandler();
|
|
|
|
|
const { selectedProduct } = selectedProductStore();
|
|
|
|
|
const { isPlaying } = usePlayButtonStore();
|
|
|
|
|
const { isReset } = useResetButtonStore();
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!isPlaying || isReset || !selectedProduct.productUuid) return;
|
|
|
|
|
|
|
|
|
|
const product = getProductById(selectedProduct.productUuid);
|
|
|
|
|
if (!product) return;
|
|
|
|
|
|
|
|
|
|
const executionOrder = determineExecutionOrder([product]);
|
|
|
|
|
executionOrder.forEach(point => {
|
|
|
|
|
const action = 'actions' in point ? point.actions[0] : point.action;
|
|
|
|
|
handleAction(action);
|
|
|
|
|
});
|
|
|
|
|
}, [products, isPlaying, isReset, selectedProduct]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
|
|
<>
|
|
|
|
|
|
|
|
|
|
</>
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Simulator;
|