Skip to content

Commit

Permalink
fix(redo-undo): fix redo-undo->rotation: transform inspector ui->rota…
Browse files Browse the repository at this point in the history
…tion should undo
  • Loading branch information
yyc-git committed Feb 15, 2019
1 parent ff5f3ea commit dfcd287
Show file tree
Hide file tree
Showing 9 changed files with 2,371 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@ module CustomEventHandler = {
type return = unit;

let setUndoValueToCopiedEngineState =
((uiState, dispatchFunc), transformComponent, (x, y, z)) =>
StateEngineService.unsafeGetState()
((uiState, dispatchFunc), transformComponent, (x, y, z)) => {
let editorState = StateEditorService.getState();
let engineState = StateEngineService.unsafeGetState();
let editorState =
TransformEditorService.removeLocalEulerAngleData(
GameObjectComponentEngineService.unsafeGetTransformComponent(
SceneTreeEditorService.unsafeGetCurrentSceneTreeNode(editorState),
engineState,
),
editorState,
);
editorState |> StateEditorService.setState |> ignore;

engineState
|> StateEngineService.deepCopyForRestore
|> TransformEngineService.setLocalEulerAngles(
(x, y, z),
transformComponent,
);
};
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ let handleDragDropEvent = (event, (editorState, engineState)) => {
let engineState =
engineState
|> CurrentRotationGizmosUtils.restoreRotationGizmoColor(editorState);
/*
let editorState =
TransformEditorService.removeLocalEulerAngleData(
GameObjectComponentEngineService.unsafeGetTransformComponent(
SceneTreeEditorService.unsafeGetCurrentSceneTreeNode(editorState),
engineState,
),
editorState,
); */

let engineState =
InitTransformGizmosUtils.pushUndoStack(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ let changeRotationY = (transform, value) =>
let changeRotationZ = (transform, value) =>
MainEditorTransform.Method.changeRotationZ(transform, value);

let changeRotationYAndBlur =
(
~value,
~transform=GameObjectTool.getCurrentSceneTreeNodeTransform(),
~uiState=TestTool.buildEmptyAppState(),
~dispatchFunc=TestTool.getDispatch(),
(),
) => {
let oldRotation = TransformUtils.getTransformRotationData(transform);

changeRotationY(transform, value);

MainEditorTransform.Method.blurRotationEvent(
(uiState, dispatchFunc),
transform,
oldRotation,
);
};

let changeScaleX = (transform, value) =>
MainEditorTransform.Method.changeScaleX(transform, value);

Expand Down
53 changes: 23 additions & 30 deletions test/integration/job/gizmo/initTransformGizmosJob_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -2564,10 +2564,7 @@ let _ =
~pageY=172,
(),
);
TransformUtils.getTransformRotationData(
GameObjectTool.getCurrentSceneTreeNodeTransform(),
)
|> ignore;
RotationGizmosTool.refreshInspectorTransform();
EventTransformGizmosTool.triggerMouseMove(
~sandbox,
~pageX=226 + 20,
Expand Down Expand Up @@ -2794,34 +2791,30 @@ let _ =
InitTransformGizmosJobTool.getCurrentSceneTreeNodeLocalScale()
|> expect == (0.5, 0.5, 0.5);
});
test(
"should avoid scale to 0",
() => {
let gameObject1 =
_prepare(sandbox, prepareGameObject);
test("should avoid scale to 0", () => {
let gameObject1 = _prepare(sandbox, prepareGameObject);

EventTransformGizmosTool.triggerMouseDown(
~sandbox,
~pageX=250,
~pageY=100,
(),
);
EventTransformGizmosTool.triggerMouseMove(
~sandbox,
~pageX=250 - 40,
~pageY=100,
(),
);
EventTransformGizmosTool.triggerMouseDown(
~sandbox,
~pageX=250,
~pageY=100,
(),
);
EventTransformGizmosTool.triggerMouseMove(
~sandbox,
~pageX=250 - 40,
~pageY=100,
(),
);

TransformGameObjectEngineService.getLocalScale(
SceneTreeEditorService.unsafeGetCurrentSceneTreeNode
|> StateLogicService.getEditorState,
)
|> StateLogicService.getEngineStateToGetData
|> Vector3Service.truncate(3)
|> expect == (0.001, 0.001, 0.001);
},
);
TransformGameObjectEngineService.getLocalScale(
SceneTreeEditorService.unsafeGetCurrentSceneTreeNode
|> StateLogicService.getEditorState,
)
|> StateLogicService.getEngineStateToGetData
|> Vector3Service.truncate(3)
|> expect == (0.001, 0.001, 0.001);
});
});
})
);
Expand Down
2 changes: 2 additions & 0 deletions test/integration/job/tool/RotationGizmosTool.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let refreshInspectorTransform = () =>
BuildComponentForCurryTool.buildMainEditorTransformComponent();
Loading

0 comments on commit dfcd287

Please sign in to comment.