Skip to content

Commit

Permalink
feat(hotKey): bind hotKeys from setting.json
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyOrz authored and yyc-git committed Jan 26, 2019
1 parent 5710664 commit cb5c109
Show file tree
Hide file tree
Showing 30 changed files with 242 additions and 128 deletions.
12 changes: 10 additions & 2 deletions src/config/editor/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@
},
"hotkeys": {
"redo": [
"ctrl+r"
"ctrl+y",
"command+y"
],
"undo": [
"ctrl+z"
"ctrl+z",
"command+z"
],
"duplicate": [
"ctrl+d"
],
"delete": [
"delete"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module CustomEventHandler = {
);

SceneUtils.addGameObject(
PrimitiveEngineService.createCube((
PrimitiveLogicService.createCube((
defaultCubeGeometry,
defaultLightMaterialData,
)),
Expand All @@ -43,14 +43,14 @@ module CustomEventHandler = {
);

SceneUtils.addGameObject(
PrimitiveEngineService.createSphere((
PrimitiveLogicService.createSphere((
defaultSphereGeometry,
defaultLightMaterialData,
)),
);

| EmptyGameObject =>
SceneUtils.addGameObject(PrimitiveEngineService.createEmptyGameObject)
SceneUtils.addGameObject(PrimitiveLogicService.createEmptyGameObject)
};

SceneTreeEditorService.setIsShowChildren(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ module CustomEventHandler = {
engineState
|> HierarchyGameObjectEngineService.addChild(
engineState
|> HierarchyGameObjectEngineService.getParentGameObject(targetGameObject)
|> HierarchyGameObjectEngineService.getParentGameObject(
targetGameObject,
)
|> OptionService.unsafeGet,
clonedGameObject,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,8 @@ let _renderCloneGameObjectComponent =
let render =
(reduxTuple, ({state, send}: ReasonReact.self('a, 'b, 'c)) as self) => {
let _isCurrentSceneTreeNodeCanBeOperate =
switch (
SceneTreeEditorService.getCurrentSceneTreeNode
|> StateLogicService.getEditorState
) {
| None => false
| Some(gameObject) =>
SceneEngineService.isSceneGameObject(gameObject)
|> StateLogicService.getEngineStateToGetData
};
GameObjectLogicService.isCurrentSceneTreeNodeCanBeOperate
|> StateLogicService.getStateToGetData;

<article
key="mainEditorScenetreeHeader" className="wonder-left-components-header">
Expand Down
10 changes: 8 additions & 2 deletions src/core/external/type/ReactEventType.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
external convertReactMouseEventToJsEvent : ReactEventRe.Mouse.t => Js.t({..}) = "%identity";
external convertReactKeyboardEventToJsEvent :
ReactEventRe.Keyboard.t => Js.t({..}) =
"%identity";

external convertReactFormEventToJsEvent : ReactEventRe.Form.t => Js.t({..}) = "%identity";
external convertReactMouseEventToJsEvent : ReactEventRe.Mouse.t => Js.t({..}) =
"%identity";

external convertReactFormEventToJsEvent : ReactEventRe.Form.t => Js.t({..}) =
"%identity";
5 changes: 0 additions & 5 deletions src/core/ui/App.re
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ let render = ((uiState: AppStore.appState, dispatchFunc), _self) =>
let make = (~state as uiState: AppStore.appState, ~dispatch, _children) => {
...component,
didMount: _self => {
HotKeysJs.hotkeys("shift+m", (e, handler) => {
Js.log(23123);
Js.log(handler);
});

WonderLog.Wonder_Console.makeObjInToWindow();

AppExtensionUtils.getExtension(Method.getStorageParentKey())
Expand Down
7 changes: 4 additions & 3 deletions src/core/utils/engine/DefaultSceneUtils.re
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let prepareSpecificGameObjects = (editorState, engineState) => {
engineState,
);
let (editorState, engineState, camera) =
CameraEngineService.createCamera(editorState, engineState);
CameraLogicService.createCamera(editorState, engineState);
let (engineState, arcballCameraController) =
ArcballCameraEngineService.create(engineState);

Expand Down Expand Up @@ -73,7 +73,8 @@ let prepareSpecificGameObjects = (editorState, engineState) => {
(editorState, engineState, camera);
};

let _prepareEngineState = ((camera, directionLight, cube1, cube2), engineState) =>
let _prepareEngineState =
((camera, directionLight, cube1, cube2), engineState) =>
engineState
|> GameObjectComponentEngineService.unsafeGetBasicCameraViewComponent(
camera,
Expand Down Expand Up @@ -110,7 +111,7 @@ let createDefaultScene = (cubeGeometry, editorState, engineState) => {
MaterialDataAssetEditorService.unsafeGetDefaultLightMaterial(editorState);

let (editorState, engineState, camera, cube1, cube2, directionLight) =
SceneEngineService.createDefaultSceneGameObjects(
SceneLogicService.createDefaultSceneGameObjects(
(cubeGeometry, defaultLightMaterialData),
editorState,
engineState,
Expand Down
1 change: 1 addition & 0 deletions src/core/utils/engine/MainUtils.re
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ let init = () =>
_,
StateEditorService.getState(),
)
|> HotKeysSettingEditorService.bindHotKeys
|> StateEditorService.setState
|> ignore;

Expand Down
5 changes: 5 additions & 0 deletions src/service/record/editor/data/HotKeysType.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type hotKeyAction =
| Redo
| Undo
| Duplicate
| Delete;
8 changes: 8 additions & 0 deletions src/service/record/editor/data/SettingType.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ type debug = {

type redoUndo = {maxStackSize: int};

type hotKeys = {
redo: array(string),
undo: array(string),
duplicate: array(string),
delete: array(string),
};

type settingRecord = {
debug: option(debug),
redoUndo: option(redoUndo),
hotKeys: option(hotKeys),
};
44 changes: 44 additions & 0 deletions src/service/record/editor/hotKeys/OperateHotKeysService.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
open HotKeysType;

let getHandleFuncByHotKeyAction = hotKeyAction => {
let uiState = UIStateService.getState();
let dispatch = UIStateService.getDispatch();
let isCurrentSceneTreeNodeCanBeOperate =
GameObjectLogicService.isCurrentSceneTreeNodeCanBeOperate
|> StateLogicService.getStateToGetData;


switch (hotKeyAction) {
| Undo => (() => AllHistoryService.handleUndo(uiState, dispatch))
| Redo => (
() =>
OperateStateHistoryService.hasRedoState(
AllStateData.getHistoryState(),
) ?
AllHistoryService.redoHistoryState(uiState, dispatch)
|> StateHistoryService.getAndRefreshStateForHistory :
()
)

| Duplicate => (
() =>
isCurrentSceneTreeNodeCanBeOperate ?
MainEditorLeftHeader.Method.cloneCurrentSceneTreeNode(
(uiState, dispatch),
(),
(),
) :
()
)
| Delete => (
() =>
isCurrentSceneTreeNodeCanBeOperate ?
MainEditorLeftHeader.Method.disposeCurrentSceneTreeNode(
(uiState, dispatch),
(),
(),
) :
()
)
};
};
13 changes: 1 addition & 12 deletions src/service/record/editor/setting/OperateSettingService.re
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
open SettingType;

let setSetting = ({debug, redoUndo}) => {
debug:
switch (debug) {
| None => None
| Some(debug) => Some(debug)
},
redoUndo:
switch (redoUndo) {
| None => None
| Some(redoUndo) => Some(redoUndo)
},
};
let unsafeGetHotKeys = ({hotKeys}) => hotKeys |> OptionService.unsafeGet;

let unsafeGetIsDebug = ({debug}) => {
let {isDebug} = debug |> OptionService.unsafeGet;
Expand Down
13 changes: 12 additions & 1 deletion src/service/record/editor/setting/ParseSettingService.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ let convertToRecord = setting => {
open Decode;

let json = setting;

{
debug:
json
Expand All @@ -24,5 +23,17 @@ let convertToRecord = setting => {
{maxStackSize: json |> field("max_stack_size", int)}
),
),
hotKeys:
json
|> optional(
field("hotkeys", json =>
{
redo: json |> field("redo", array(string)),
undo: json |> field("undo", array(string)),
duplicate: json |> field("duplicate", array(string)),
delete: json |> field("delete", array(string)),
}
),
),
};
};
2 changes: 1 addition & 1 deletion src/service/record/editor/setting/RecordSettingService.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
open SettingType;

let create = () => {debug: None, redoUndo: None};
let create = () => {debug: None, redoUndo: None, hotKeys: None};
40 changes: 40 additions & 0 deletions src/service/state/editor/setting/HotKeysSettingEditorService.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
open EditorType;

open HotKeysType;

let unsafeGetHotKeys = ({settingRecord}) =>
OperateSettingService.unsafeGetHotKeys(settingRecord);

let _preventBrowserHotKeys = event => {
let e = ReactEventType.convertReactKeyboardEventToJsEvent(event);

EventHelper.preventDefault(e);
};

let _handleHotKeyFunc = hotKeyDataArray =>
hotKeyDataArray
|> Js.Array.forEach(((hotKeys, hotKeyAction)) =>
hotKeys
|> Js.Array.joinWith(",")
|. HotKeysJs.hotkeys((e, handler) => {
_preventBrowserHotKeys(e);

let handleFunc =
OperateHotKeysService.getHandleFuncByHotKeyAction(hotKeyAction);

handleFunc();
})
);

let bindHotKeys = editorState => {
let hotKeySetting = editorState |> unsafeGetHotKeys;
[|
(hotKeySetting.redo, Redo),
(hotKeySetting.undo, Undo),
(hotKeySetting.duplicate, Duplicate),
(hotKeySetting.delete, Delete),
|]
|> _handleHotKeyFunc;

editorState;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ let setSetting = (setting, editorState) => {
StateEditorService.setStateIsDebug(isDebug);
StateEngineService.setIsDebug(isDebug) |> ignore;

{...editorState, settingRecord: OperateSettingService.setSetting(setting)};
{...editorState, settingRecord: setting};
};
22 changes: 0 additions & 22 deletions src/service/state/engine/SceneEngineService.re
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
open Wonderjs;

let createDefaultSceneGameObjects = (componentData, editorState, engineState) => {
let (editorState, engineState, cube1) =
PrimitiveEngineService.createCube(
componentData,
editorState,
engineState,
);
let (editorState, engineState, cube2) =
PrimitiveEngineService.createCube(
componentData,
editorState,
engineState,
);
let (editorState, engineState, directionLight) =
PrimitiveEngineService.createDirectionLight(editorState, engineState);
let (editorState, engineState, camera) =
CameraEngineService.createCamera(editorState, engineState);

(editorState, engineState, camera, cube1, cube2, directionLight);
};

let getAmbientLightColor = SceneAPI.getAmbientLightColor;

let setAmbientLightColor = SceneAPI.setAmbientLightColor;
Expand Down
19 changes: 0 additions & 19 deletions src/service/state/engine/camera/CameraEngineService.re
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,6 @@ let createCameraGroup = engineState =>
createPerspectiveCamera,
));

let createCamera = (editorState, engineState) => {
let (editorState, (engineState, gameObject)) =
GameObjectLogicService.createGameObject((editorState, engineState));
let (engineState, cameraComponentRecord) = createCameraGroup(engineState);

let engineState =
engineState
|> GameObjectEngineService.setGameObjectName("Camera", gameObject);

let (editorState, engineState) =
(editorState, engineState)
|> GameObjectLogicService.addCameraGroup(
gameObject,
cameraComponentRecord,
);

(editorState, engineState, gameObject);
};

let hasCameraGroup = (gameObject, engineState) =>
engineState
|> CameraGroupEngineService.hasCameraGroupComponents(
Expand Down
19 changes: 19 additions & 0 deletions src/service/stateTuple/logic/CameraLogicService.re
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@
);
}; */

let createCamera = (editorState, engineState) => {
let (editorState, (engineState, gameObject)) =
GameObjectLogicService.createGameObject((editorState, engineState));
let (engineState, cameraComponentRecord) =
CameraEngineService.createCameraGroup(engineState);

let engineState =
engineState
|> GameObjectEngineService.setGameObjectName("Camera", gameObject);

let (editorState, engineState) =
(editorState, engineState)
|> GameObjectLogicService.addCameraGroup(
gameObject,
cameraComponentRecord,
);

(editorState, engineState, gameObject);
};
let unbindArcballCameraControllerEventIfHasComponentForGameView =
(gameObject, editorState, engineState) => {
let targetRemoveBasicCameraView =
Expand Down
Loading

0 comments on commit cb5c109

Please sign in to comment.