Skip to content
Permalink
Browse files

fix(event): fix unbind arcball camera controller->keydown event

  • Loading branch information...
yyc-git committed May 21, 2019
1 parent dce7094 commit 2290309eb4d16858abdf93521b0f7f3f5afc239b
@@ -44,6 +44,8 @@ let loadConfig = LoaderManagerAPI.loadConfig;

let isBindArcballCameraControllerEvent = ArcballCameraControllerAPI.isBindArcballCameraControllerEvent;

let unbindArcballCameraControllerPointScaleEvent = ArcballCameraControllerAPI.unbindArcballCameraControllerPointScaleEvent;

let unbindArcballCameraControllerEvent = ArcballCameraControllerAPI.unbindArcballCameraControllerEvent;

let bindArcballCameraControllerEvent = ArcballCameraControllerAPI.bindArcballCameraControllerEvent;
@@ -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,
);

@@ -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
@@ -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(

0 comments on commit 2290309

Please sign in to comment.
You can’t perform that action at this time.