diff --git a/src/Index.re b/src/Index.re index 843cfb9847..a21ff2b32c 100755 --- a/src/Index.re +++ b/src/Index.re @@ -44,6 +44,8 @@ let loadConfig = LoaderManagerAPI.loadConfig; let isBindArcballCameraControllerEvent = ArcballCameraControllerAPI.isBindArcballCameraControllerEvent; +let unbindArcballCameraControllerPointScaleEvent = ArcballCameraControllerAPI.unbindArcballCameraControllerPointScaleEvent; + let unbindArcballCameraControllerEvent = ArcballCameraControllerAPI.unbindArcballCameraControllerEvent; let bindArcballCameraControllerEvent = ArcballCameraControllerAPI.bindArcballCameraControllerEvent; diff --git a/src/service/state/main/camera_controller/arcball/EventArcballCameraControllerMainService.re b/src/service/state/main/camera_controller/arcball/EventArcballCameraControllerMainService.re index 36b6873f8e..7425417072 100755 --- a/src/service/state/main/camera_controller/arcball/EventArcballCameraControllerMainService.re +++ b/src/service/state/main/camera_controller/arcball/EventArcballCameraControllerMainService.re @@ -210,11 +210,13 @@ let prepareBindEvent = (cameraController, state) => { event: EventType.keyboardEvent, {arcballCameraControllerRecord} as state, ) => - TargetArcballCameraControllerMainService.setTargetByKeyboardEvent( - cameraController, - event, - state, - ); + isTriggerKeydownEventHandler(event) ? + TargetArcballCameraControllerMainService.setTargetByKeyboardEvent( + cameraController, + event, + state, + ) : + state; let state = { ...state, @@ -295,10 +297,7 @@ let bindEvent = (cameraController, state) => { let state = ManageEventMainService.onKeyboardEvent( ~eventName=EventType.KeyDown, - ~handleFunc= - (. event, state) => - isTriggerKeydownEventHandler(event) ? - keydownHandleFunc(. event, state) : state, + ~handleFunc=keydownHandleFunc, ~state, (), ); @@ -471,6 +470,11 @@ let _disposeKeyDownEventHandleFuncListMap = |> List.fold_left( (state, func) => _unbindKeyboardEvent(EventType.KeyDown, func, state), + /* ManageEventMainService.offKeyboardEventByHandleFunc( + ~eventName, + ~handleFunc, + ~state, + ); */ state, ); diff --git a/src/service/state/main/event/bind/BindDomEventMainService.re b/src/service/state/main/event/bind/BindDomEventMainService.re index 365c2a9624..092c199403 100755 --- a/src/service/state/main/event/bind/BindDomEventMainService.re +++ b/src/service/state/main/event/bind/BindDomEventMainService.re @@ -1,5 +1,7 @@ let addToEventArr = (eventName, eventData, getPriorityFunc, eventArrMap) => - switch (eventArrMap |> WonderCommonlib.MutableSparseMapService.get(eventName)) { + switch ( + eventArrMap |> WonderCommonlib.MutableSparseMapService.get(eventName) + ) { | None => eventArrMap |> WonderCommonlib.MutableSparseMapService.set(eventName, [|eventData|]) @@ -17,7 +19,9 @@ let addToEventArr = (eventName, eventData, getPriorityFunc, eventArrMap) => let removeFromEventArrMapByHandleFunc = (eventName, (getHandleFuncFunc, targetHandleFunc), eventArrMap) => - switch (eventArrMap |> WonderCommonlib.MutableSparseMapService.get(eventName)) { + switch ( + eventArrMap |> WonderCommonlib.MutableSparseMapService.get(eventName) + ) { | None => eventArrMap | Some(arr) => eventArrMap diff --git a/test/unit/ecs/component/cameraController/EventArcballCameraController_test.re b/test/unit/ecs/component/cameraController/EventArcballCameraController_test.re index c9de672971..9bbb69c53f 100755 --- a/test/unit/ecs/component/cameraController/EventArcballCameraController_test.re +++ b/test/unit/ecs/component/cameraController/EventArcballCameraController_test.re @@ -18,6 +18,44 @@ let _ = let _prepareMouseEvent = () => EventArcballCameraControllerTool.prepareMouseEvent(sandbox); + let _prepareKeyEvent = () => { + let state = + EventArcballCameraControllerTool.prepareKeyboardEvent(sandbox); + let ( + state, + gameObject, + transform, + (cameraController, basicCameraView, perspectiveCameraProjection), + ) = + ArcballCameraControllerTool.createGameObject(state); + let (posX, posY, posZ) as pos = (1., 2., 3.); + let state = + state |> TransformAPI.setTransformLocalPosition(transform, pos); + let _ = TransformAPI.getTransformPosition(transform, state); + let target = pos; + let moveSpeedX = 0.1; + let moveSpeedY = 0.2; + let state = + state + |> setArcballCameraControllerTarget(cameraController, target) + |> setArcballCameraControllerMoveSpeedX( + cameraController, + moveSpeedX, + ) + |> setArcballCameraControllerMoveSpeedY( + cameraController, + moveSpeedY, + ); + let state = state |> NoWorkerJobTool.execInitJobs; + let state = + ArcballCameraControllerAPI.bindArcballCameraControllerEvent( + cameraController, + state, + ); + + (state, cameraController, (moveSpeedX, moveSpeedY), pos); + }; + describe("test bind one arcballCameraController's event", () => { describe("bind event", () => { describe("support pointer lock", () => { @@ -348,51 +386,6 @@ let _ = }); describe("bind keydown event", () => { - let _prepareKeyEvent = () => { - let state = - EventArcballCameraControllerTool.prepareKeyboardEvent( - sandbox, - ); - let ( - state, - gameObject, - transform, - ( - cameraController, - basicCameraView, - perspectiveCameraProjection, - ), - ) = - ArcballCameraControllerTool.createGameObject(state); - let (posX, posY, posZ) as pos = (1., 2., 3.); - let state = - state - |> TransformAPI.setTransformLocalPosition(transform, pos); - let _ = TransformAPI.getTransformPosition(transform, state); - let target = pos; - let moveSpeedX = 0.1; - let moveSpeedY = 0.2; - let state = - state - |> setArcballCameraControllerTarget(cameraController, target) - |> setArcballCameraControllerMoveSpeedX( - cameraController, - moveSpeedX, - ) - |> setArcballCameraControllerMoveSpeedY( - cameraController, - moveSpeedY, - ); - let state = state |> NoWorkerJobTool.execInitJobs; - let state = - ArcballCameraControllerAPI.bindArcballCameraControllerEvent( - cameraController, - state, - ); - - (state, cameraController, (moveSpeedX, moveSpeedY), pos); - }; - test("if is combined key, not set target", () => { let ( state, @@ -587,6 +580,32 @@ let _ = preventDefaultFunc |> expect |> not_ |> toCalled; }); + test("test unbind keydown event", () => { + let ( + state, + cameraController, + (moveSpeedX, moveSpeedY), + (posX, posY, posZ), + ) = + _prepareKeyEvent(); + let state = + ArcballCameraControllerAPI.unbindArcballCameraControllerEvent( + cameraController, + state, + ); + + let state = MainStateTool.setState(state); + EventTool.triggerDomEvent( + "keydown", + EventTool.getKeyboardEventBindedDom(state), + KeyboardEventTool.buildKeyboardEvent(~keyCode=65, ()), + ); + let state = EventTool.restore(state); + + state + |> unsafeGetArcballCameraControllerTarget(cameraController) + |> expect == (posX, posY, posZ); + }); describe("fix bug", () => test(