Skip to content

Commit

Permalink
fix(dragWdb): fix drag wdb before/after scene gameObject, throw error
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyOrz committed Feb 16, 2019
1 parent bfaa6b7 commit d12342b
Show file tree
Hide file tree
Showing 10 changed files with 1,075 additions and 675 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,85 +13,6 @@ module CustomEventHandler = {
);
type return = unit;

let _handleDragIntoTarget =
(targetGameObject, draggedGameObject, engineState) => {
SceneTreeEditorService.setIsShowChildren(targetGameObject, true)
|> StateLogicService.getAndSetEditorState;

engineState
|> HierarchyGameObjectEngineService.setParentKeepOrder(
targetGameObject,
draggedGameObject,
);
};

let _handleDragToBeSceneGameObjectChild =
(dragPosition, sceneGameObject, draggedGameObject, engineState) =>
switch (dragPosition) {
| DragIntoTarget =>
_handleDragIntoTarget(sceneGameObject, draggedGameObject, engineState)

| DragBeforeTarget
| DragAfterTarget =>
let targetGameObject =
engineState
|> HierarchyGameObjectEngineService.getChildren(sceneGameObject)
|> ArrayService.unsafeGetFirst;
engineState
|> HierarchyGameObjectEngineService.setParentKeepOrder(
HierarchyGameObjectEngineService.getParentGameObject(
targetGameObject,
engineState,
)
|> OptionService.unsafeGet,
draggedGameObject,
)
|> HierarchyGameObjectEngineService.changeGameObjectChildOrder(
draggedGameObject,
targetGameObject,
Wonderjs.TransformType.Before,
);
};

let _handleDragToBeTargetGameObjectSib =
(dragPosition, targetGameObject, draggedGameObject, engineState) =>
switch (dragPosition) {
| DragBeforeTarget =>
engineState
|> HierarchyGameObjectEngineService.setParentKeepOrder(
HierarchyGameObjectEngineService.getParentGameObject(
targetGameObject,
engineState,
)
|> OptionService.unsafeGet,
draggedGameObject,
)
|> HierarchyGameObjectEngineService.changeGameObjectChildOrder(
draggedGameObject,
targetGameObject,
Wonderjs.TransformType.Before,
)

| DragIntoTarget =>
_handleDragIntoTarget(targetGameObject, draggedGameObject, engineState)

| DragAfterTarget =>
engineState
|> HierarchyGameObjectEngineService.setParentKeepOrder(
HierarchyGameObjectEngineService.getParentGameObject(
targetGameObject,
engineState,
)
|> OptionService.unsafeGet,
draggedGameObject,
)
|> HierarchyGameObjectEngineService.changeGameObjectChildOrder(
draggedGameObject,
targetGameObject,
Wonderjs.TransformType.After,
)
};

let handleSelfLogic =
(
(uiState, dispatchFunc),
Expand All @@ -103,13 +24,13 @@ module CustomEventHandler = {
let engineState =
SceneEngineService.isSceneGameObject(targetGameObject)
|> StateLogicService.getEngineStateToGetData ?
_handleDragToBeSceneGameObjectChild(
DragGameObjectUtils.handleDragToBeSceneGameObjectChild(
dragPosition,
targetGameObject,
draggedGameObject,
engineState,
) :
_handleDragToBeTargetGameObjectSib(
DragGameObjectUtils.handleDragToBeTargetGameObjectSib(
dragPosition,
targetGameObject,
draggedGameObject,
Expand Down
80 changes: 80 additions & 0 deletions src/core/utils/dragGameObject/DragGameObjectUtils.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
open SceneTreeNodeType;

let _handleDragIntoTarget = (targetGameObject, draggedGameObject, engineState) => {
SceneTreeEditorService.setIsShowChildren(targetGameObject, true)
|> StateLogicService.getAndSetEditorState;

engineState
|> HierarchyGameObjectEngineService.setParentKeepOrder(
targetGameObject,
draggedGameObject,
);
};

let handleDragToBeSceneGameObjectChild =
(dragPosition, sceneGameObject, draggedGameObject, engineState) =>
switch (dragPosition) {
| DragIntoTarget =>
_handleDragIntoTarget(sceneGameObject, draggedGameObject, engineState)

| DragBeforeTarget
| DragAfterTarget =>
let targetGameObject =
engineState
|> HierarchyGameObjectEngineService.getChildren(sceneGameObject)
|> ArrayService.unsafeGetFirst;

engineState
|> HierarchyGameObjectEngineService.setParentKeepOrder(
HierarchyGameObjectEngineService.getParentGameObject(
targetGameObject,
engineState,
)
|> OptionService.unsafeGet,
draggedGameObject,
)
|> HierarchyGameObjectEngineService.changeGameObjectChildOrder(
draggedGameObject,
targetGameObject,
Wonderjs.TransformType.Before,
);
};

let handleDragToBeTargetGameObjectSib =
(dragPosition, targetGameObject, draggedGameObject, engineState) =>
switch (dragPosition) {
| DragBeforeTarget =>
engineState
|> HierarchyGameObjectEngineService.setParentKeepOrder(
HierarchyGameObjectEngineService.getParentGameObject(
targetGameObject,
engineState,
)
|> OptionService.unsafeGet,
draggedGameObject,
)
|> HierarchyGameObjectEngineService.changeGameObjectChildOrder(
draggedGameObject,
targetGameObject,
Wonderjs.TransformType.Before,
)

| DragIntoTarget =>
_handleDragIntoTarget(targetGameObject, draggedGameObject, engineState)

| DragAfterTarget =>
engineState
|> HierarchyGameObjectEngineService.setParentKeepOrder(
HierarchyGameObjectEngineService.getParentGameObject(
targetGameObject,
engineState,
)
|> OptionService.unsafeGet,
draggedGameObject,
)
|> HierarchyGameObjectEngineService.changeGameObjectChildOrder(
draggedGameObject,
targetGameObject,
Wonderjs.TransformType.After,
)
};
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -47,49 +47,6 @@ let _checkLightCount = (gameObject, (editorState, engineState)) => {
(engineState, result);
};

let _setHierachy =
(dragPosition, targetGameObject, clonedWDBGameObject, engineState) =>
switch (dragPosition) {
| DragBeforeTarget =>
engineState
|> HierarchyGameObjectEngineService.addChild(
HierarchyGameObjectEngineService.getParentGameObject(
targetGameObject,
engineState,
)
|> OptionService.unsafeGet,
clonedWDBGameObject,
)
|> HierarchyGameObjectEngineService.changeGameObjectChildOrder(
clonedWDBGameObject,
targetGameObject,
Wonderjs.TransformType.Before,
)

| DragIntoTarget =>
engineState
|> HierarchyGameObjectEngineService.addChild(
targetGameObject,
clonedWDBGameObject,
)

| DragAfterTarget =>
engineState
|> HierarchyGameObjectEngineService.addChild(
HierarchyGameObjectEngineService.getParentGameObject(
targetGameObject,
engineState,
)
|> OptionService.unsafeGet,
clonedWDBGameObject,
)
|> HierarchyGameObjectEngineService.changeGameObjectChildOrder(
clonedWDBGameObject,
targetGameObject,
Wonderjs.TransformType.After,
)
};

let dragWDB =
(
wdbGameObject,
Expand All @@ -111,12 +68,21 @@ let dragWDB =
let clonedWDBGameObject =
cloneGameObjectArr |> CloneGameObjectLogicService.getClonedGameObject;

_setHierachy(
dragPosition,
targetGameObject,
clonedWDBGameObject,
engineState,
);
let engineState =
SceneEngineService.isSceneGameObject(targetGameObject)
|> StateLogicService.getEngineStateToGetData ?
DragGameObjectUtils.handleDragToBeSceneGameObjectChild(
dragPosition,
targetGameObject,
clonedWDBGameObject,
engineState,
) :
DragGameObjectUtils.handleDragToBeTargetGameObjectSib(
dragPosition,
targetGameObject,
clonedWDBGameObject,
engineState,
);

let engineState =
SceneEngineService.isNeedReInitAllLightMaterials(
Expand Down
Loading

0 comments on commit d12342b

Please sign in to comment.