Skip to content

Commit

Permalink
fix(inspectorEngine): need fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyOrz committed Mar 26, 2019
1 parent 7cf4536 commit 192843c
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let render = ((uiState, dispatchFunc), addableComponentConfig, _self) => {
),
)
}
<canvas id="asset-canvas" key="assetCanvas" />
<canvas id="inspector-canvas" key="inspectorCanvas" />
</article>;
};

Expand All @@ -75,31 +75,31 @@ let make =
shouldUpdate,
render: self =>
render((uiState, dispatchFunc), addableComponentConfig, self),
didUpdate: self => {
let assetCanvas = DomHelper.getElementById("asset-canvas");
let editorState = StateEditorService.getState();
/* didUpdate: self => {
let inspectorCanvas = DomHelper.getElementById("inspector-canvas");
let editorState = StateEditorService.getState();
Js.log("did update");
Js.log("did update");
switch (
CurrentSelectSourceEditorService.getCurrentSelectSource(editorState)
) {
| None
| Some(SceneTree) => DomHelper.hideCanvas(assetCanvas)
| Some(Asset) =>
switch (OperateTreeAssetEditorService.getCurrentNode(editorState)) {
| None => DomHelper.hideCanvas(assetCanvas)
| Some(currentNode) =>
switch (currentNode) {
| TextureNode(nodeId, textureNodeData) =>
DomHelper.hideCanvas(assetCanvas)
| FolderNode(nodeId, folderNodeData, children) =>
DomHelper.hideCanvas(assetCanvas)
| MaterialNode(nodeId, materialNodeData) =>
DomHelper.showCanvas(assetCanvas)
| WDBNode(nodeId, wdbNodeData) => DomHelper.showCanvas(assetCanvas)
}
}
};
},
switch (
CurrentSelectSourceEditorService.getCurrentSelectSource(editorState)
) {
| None
| Some(SceneTree) => DomHelper.hideCanvas(inspectorCanvas)
| Some(Asset) =>
switch (OperateTreeAssetEditorService.getCurrentNode(editorState)) {
| None => DomHelper.hideCanvas(inspectorCanvas)
| Some(currentNode) =>
switch (currentNode) {
| TextureNode(nodeId, textureNodeData) =>
DomHelper.hideCanvas(inspectorCanvas)
| FolderNode(nodeId, folderNodeData, children) =>
DomHelper.hideCanvas(inspectorCanvas)
| MaterialNode(nodeId, materialNodeData) =>
DomHelper.showCanvas(inspectorCanvas)
| WDBNode(nodeId, wdbNodeData) => DomHelper.showCanvas(inspectorCanvas)
}
}
};
}, */
};
8 changes: 7 additions & 1 deletion src/core/composable_component/mainEditor/ui/MainEditor.re
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ let _buildElementBeforeInitEngine = (uiState, dispatchFunc) =>
</div>
<div className="bottom-widget" />
</div>
<div key="rightComponent" className="right-component" />
<div key="rightComponent" className="right-component">
<div className="inline-component inspector-parent">
<article key="inspector" className="wonder-inspector-component">
<canvas id="inspector-canvas" key="inspectorCanvas" />
</article>
</div>
</div>
</article>;

let _buildElementAfterInitEngine = (uiState, dispatchFunc) =>
Expand Down
49 changes: 45 additions & 4 deletions src/core/utils/engine/MainUtils.re
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
open Js.Promise;

let _getLoadData = () => {
let _getLoadEngineData = () => {
let engineConfigDir = "./config/engine/";

AssetEngineService.loadConfig(
[|"./config/engine/setting.json", engineConfigDir|],
StateDataEngineService.getEngineStateData(),
StateDataEngineService.getStateData(),
);
};

let _getLoadInspectorEngineData = () => {
let engineConfigDir = "./config/inspectorEngine/";

AssetEngineService.loadConfig(
[|"./config/inspectorEngine/setting.json", engineConfigDir|],
StateDataInspectorEngineService.getStateData(),
);
};

Expand Down Expand Up @@ -86,9 +95,21 @@ let _handleEngineState = engineState => {
|> StateEngineService.setState;
};

let _handleInspectorEngineState = inspectorEngineState => {
let inspectorEngineState = _registerJob(inspectorEngineState);

inspectorEngineState
|> DirectorEngineService.init
|> StateInspectorEngineService.setState;

Js.log(StateDataInspectorEngineService.getStateData());

StateInspectorEngineService.unsafeGetState() |> Js.log;
};

let initEngine = () =>
Wonderjs.StateDataMainType.(
_getLoadData()
_getLoadEngineData()
|> WonderBsMost.Most.flatMap(engineState =>
LoaderManagerEngineService.loadIMGUIAsset(
"./public/font/empty.fnt",
Expand Down Expand Up @@ -123,6 +144,26 @@ let initEngine = () =>
)
|> WonderBsMost.Most.fromPromise
)
|> WonderBsMost.Most.map(engineState => engineState |> _handleEngineState)
|> WonderBsMost.Most.tap(engineState => {
engineState |> _handleEngineState |> ignore;

();
})
|> WonderBsMost.Most.merge(
_getLoadInspectorEngineData()
|> WonderBsMost.Most.tap(inspectorEngineState => {
Js.log("inspctor data ");
Js.log((
inspectorEngineState,
StateDataInspectorEngineService.getStateData(),
));

inspectorEngineState |> _handleInspectorEngineState |> ignore;

();
}),
)
/* |> WonderBsMost.Most.flatMap(engineState =>
) */
|> WonderBsMost.Most.drain
);
12 changes: 8 additions & 4 deletions src/core/utils/ui/ResizeUtils.re
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ let isViewSizeChange =
(_, _, gameViewWidth, gameViewHeight),
(canvasWidth, canvasHeight),
) =>
! isSizeEqual(getViewWidth(sceneViewWidth, gameViewWidth), canvasWidth)
!isSizeEqual(getViewWidth(sceneViewWidth, gameViewWidth), canvasWidth)
|| !
isSizeEqual(
getViewHeight(sceneViewHeight, gameViewHeight),
Expand All @@ -111,19 +111,23 @@ let isViewSizeChange =

let resizeScreen = () => {
let canvasParentSize = getCanvasParentSize();
let engineState = StateEngineService.unsafeGetState();
let inspectorEngineState = StateInspectorEngineService.unsafeGetState();

resizeCanvas(canvasParentSize);

DeviceManagerEngineService.getGl(StateEngineService.unsafeGetState())
|> Js.Option.isSome ?
engineState |> DeviceManagerEngineService.getGl |> Js.Option.isSome ?
{
updateViewRect(canvasParentSize)
|> StateLogicService.getAndSetEditorState;

StateEngineService.unsafeGetState()
engineState
|> resizeViewport(canvasParentSize)
|> StateLogicService.refreshEngineState
|> ignore;
} :
();

inspectorEngineState |> DeviceManagerEngineService.getGl |> Js.Option.isSome ?
inspectorEngineState |> StateLogicService.refreshEngineState |> ignore : ();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
open Wonderjs;

open StateDataMainType;

let createStateData = () => {state: None, isDebug: false};
2 changes: 1 addition & 1 deletion src/service/state/engine/StateDataEngineService.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
open Wonderjs;

let getEngineStateData = () => StateDataMain.stateData;
let getStateData = () => StateDataMain.stateData;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
open Wonderjs;

let getStateData = () =>
CreateInspectorEngineStateDataService.createStateData();

let unsafeGetState = () =>
StateDataMainService.unsafeGetState(getStateData());

let setState = (state: StateDataMainType.state) =>
StateDataMainService.setState(getStateData(), state);
13 changes: 13 additions & 0 deletions src/service/state/inspectorEngine/StateInspectorEngineService.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let deepCopyForRestore = Wonderjs.StateAPI.deepCopyForRestore;

let createState = Wonderjs.StateAPI.createState;

let createStateData = CreateInspectorEngineStateDataService.createStateData;

let getStateFromData = Wonderjs.StateAPI.getStateFromData;

let unsafeGetState = StateDataInspectorEngineService.unsafeGetState;

let setStateToData = Wonderjs.StateAPI.setStateToData;

let setState = StateDataInspectorEngineService.setState;

0 comments on commit 192843c

Please sign in to comment.