diff --git a/public/unity/Build/unity.data b/public/unity/Build/unity.data index 393ab46..b2caeee 100644 --- a/public/unity/Build/unity.data +++ b/public/unity/Build/unity.data @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2a7c9735ceed5baf44657b950e4b1e6f83fe0afa1fed7ac3e9e904fbfdcd57de -size 13415551 +oid sha256:c37394e2247c280eeb611aa7a2e252d0449f3f415e8ea945ed08318c12ee4cfd +size 13415072 diff --git a/public/unity/Build/unity.wasm b/public/unity/Build/unity.wasm index d5728e3..b2c0a56 100644 Binary files a/public/unity/Build/unity.wasm and b/public/unity/Build/unity.wasm differ diff --git a/src/components/Providers/PlannerProvider/index.tsx b/src/components/Providers/PlannerProvider/index.tsx index 988401b..7cf6e6c 100644 --- a/src/components/Providers/PlannerProvider/index.tsx +++ b/src/components/Providers/PlannerProvider/index.tsx @@ -609,6 +609,28 @@ export const PlannerProvider: React.FC = ({ children, proj useEffect(() => { let finishedSetup = false; + + const updateProjectModuleState = ( + projectModule: UnityProjectModuleJson, + prevProjectModule?: UnityProjectModuleJson, + childrenModules?: UnityProjectModuleJsonChildren + ) => { + const hasModuleMoved = + prevProjectModule?.posX !== projectModule.posX || + prevProjectModule?.posY !== projectModule.posY || + prevProjectModule?.posZ !== projectModule.posZ || + prevProjectModule?.rotY !== projectModule.rotY; + + const isSameModule = prevProjectModule?.nanoId === projectModule.nanoId; + + // Only calls upsertModule if the selected module has been moved + if (!isSameModule || (isSameModule && hasModuleMoved) || childrenModules?.children.some((x) => x.module.isEdge)) { + shouldCreateOrUpdate.current = true; + } + + return projectModule; + }; + /* * Unity -> React * */ @@ -634,7 +656,7 @@ export const PlannerProvider: React.FC = ({ children, proj console.log('createModule: ', projectModule, childrenModules); // setIsPending(false); - setProjectModule(projectModule); + setProjectModule((prevProjectModule) => updateProjectModuleState(projectModule, prevProjectModule)); setChildrenModules(childrenModules?.children); setState('Created'); @@ -650,21 +672,7 @@ export const PlannerProvider: React.FC = ({ children, proj console.log('selectedModule: ', projectModule, childrenModules); // setIsPending(false); - setProjectModule((prevProjectModule) => { - // Only calls upsertModule if the selected module has been moved - if ( - (prevProjectModule && - prevProjectModule.nanoId === projectModule.nanoId && - (prevProjectModule?.posX !== projectModule.posX || - prevProjectModule?.posY !== projectModule.posY || - prevProjectModule?.posZ !== projectModule.posZ || - prevProjectModule?.rotY !== projectModule.rotY)) || - childrenModules?.children.some((x) => x.module.isEdge) - ) { - shouldCreateOrUpdate.current = true; - } - return projectModule; - }); + setProjectModule((prevProjectModule) => updateProjectModuleState(projectModule, prevProjectModule)); setChildrenModules(childrenModules?.children); setState('Selected'); }, @@ -675,7 +683,7 @@ export const PlannerProvider: React.FC = ({ children, proj console.log('editedModule: ', projectModule, childrenModules); - setProjectModule(projectModule); + setProjectModule((prevProjectModule) => updateProjectModuleState(projectModule, prevProjectModule)); setChildrenModules(childrenModules?.children); setState('Editing'); }, @@ -692,9 +700,8 @@ export const PlannerProvider: React.FC = ({ children, proj await handleUpsertProjectModule(projectModule, childrenModules?.children || []); setProjectModule(undefined); setChildrenModules(undefined); + shouldCreateOrUpdate.current = false; } - - shouldCreateOrUpdate.current = false; }, deletedModule: async (projectModuleJson: string, childrenJson?: string) => { if (!finishedSetup) return;