Skip to content

Commit

Permalink
fix(composer): Adjusting logic for reparenting scene nodes (#369)
Browse files Browse the repository at this point in the history
Co-authored-by: Emily Dodds <dodemily@amazon.com>
  • Loading branch information
mumanity and mumanity committed Nov 15, 2022
1 parent 8a66f94 commit 3475ebd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/scene-composer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@
"global": {
"lines": 77.0,
"statements": 76.0,
"functions": 76.76,
"branches": 63.17,
"functions": 76.0,
"branches": 62.0,
"branchesTrue": 100
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,20 @@ const SceneHierarchyDataProvider: FC<SceneHierarchyDataProviderProps> = ({ selec

const move = useCallback(
(objectRef: string, newParentRef?: string) => {
updateSceneNodeInternal(objectRef, { parentRef: newParentRef });

const originalObject = getSceneNodeByRef(objectRef);
if (newParentRef) {
const parentNode = getSceneNodeByRef(newParentRef);
updateSceneNodeInternal(newParentRef, { childRefs: [...parentNode!.childRefs, objectRef] });
const objectToMoveRef = originalObject?.ref as string;
const oldParentRef = originalObject?.parentRef as string;
const newParent = getSceneNodeByRef(newParentRef);
const oldParent = getSceneNodeByRef(oldParentRef);
const oldParentChildren = oldParent?.childRefs.filter((child) => child !== objectToMoveRef);
// remove child ref from parent
updateSceneNodeInternal(oldParentRef, { childRefs: oldParentChildren });
// update node to have new parent
updateSceneNodeInternal(objectToMoveRef, { parentRef: newParentRef });
// update new parent to have new child
updateSceneNodeInternal(newParentRef, { childRefs: [...newParent!.childRefs, objectRef] });
// TODO: create single call to handle this
}
},
[updateSceneNodeInternal, getSceneNodeByRef, nodeMap],
Expand Down

0 comments on commit 3475ebd

Please sign in to comment.