Skip to content

Commit

Permalink
feat(asset): add "remove script event function, script attribute asset"
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed Apr 7, 2019
1 parent 9e5a8a8 commit 119af1d
Show file tree
Hide file tree
Showing 16 changed files with 2,030 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Method = {
| None => ReasonReact.null
| Some(currentNode) =>
<AssetTreeInspector
key=(DomHelper.getRandomKey())
key={DomHelper.getRandomKey()}
uiState
dispatchFunc
currentNode
Expand All @@ -38,7 +38,7 @@ let component =
let render = ((uiState, dispatchFunc), addableComponentConfig, _self) => {
let editorState = StateEditorService.getState();
<article key="inspector" className="wonder-inspector-component">
(
{
Method.showInspectorBySourceType(
(uiState, dispatchFunc),
addableComponentConfig,
Expand All @@ -48,7 +48,7 @@ let render = ((uiState, dispatchFunc), addableComponentConfig, _self) => {
OperateTreeAssetEditorService.getCurrentNode(editorState),
),
)
)
}
</article>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,42 +64,41 @@ module Method = {
sceneGraphArr
|> Js.Array.map(({uid, name, children}) =>
<SceneTreeNode
key=(StringService.intToString(uid))
key={StringService.intToString(uid)}
gameObject=uid
name
isSelected=(_isSelected(uid, currentSceneTreeNode))
isSelected={_isSelected(uid, currentSceneTreeNode)}
isActive=true
dragImg
widget=(SceneTreeWidgetService.getWidget())
widget={SceneTreeWidgetService.getWidget()}
onSelect=onSelectFunc
dragGameObject=dragGameObjectFunc
dragWDB=dragWDBFunc
isWidget=SceneTreeWidgetService.isWidget
isShowChildren=(
isShowChildren={
SceneTreeEditorService.getIsShowChildern(
uid,
sceneGameObject,
editorState,
)
)
}
isAssetWDBFile=WDBNodeAssetEditorService.isWDBAssetFile
isHasChildren=(children |> Js.Array.length >= 1)
handleToggleShowTreeChildren=(
isHasChildren={children |> Js.Array.length >= 1}
handleToggleShowTreeChildren={
handleToggleShowTreeChildren(dispatchFunc)
)
}
checkNodeRelation=CheckSceneTreeLogicService.checkGameObjectRelation
treeChildren=(
treeChildren={
buildSceneTreeArray(
(uiState, dispatchFunc, dragImg),
currentSceneTreeNode,
(onSelectFunc, dragGameObjectFunc, dragWDBFunc),
(sceneGameObject, editorState),
children,
)
)
}
/>
);

};

let component =
Expand All @@ -114,7 +113,7 @@ let render = (uiState, dispatchFunc, _self) => {
className="wonder-sceneTree-component"
id="wonder-sceneTree-component">
<article className="wonder-tree">
(
{
ReasonReact.array(
SceneGraphUtils.getSceneGraphDataFromEngine((
editorState,
Expand Down Expand Up @@ -152,7 +151,7 @@ let render = (uiState, dispatchFunc, _self) => {
)
),
)
)
}
</article>
</article>;
};
Expand Down
10 changes: 9 additions & 1 deletion src/service/atom/ImmutableSparseMapService.re
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ let find = (func, map) =>
Js.Array.find(
func,
map |> WonderCommonlib.SparseMapType.arrayNullableToArrayNotNullable,
);
);

let filterValid = (func, map) =>
map
|> Js.Array.filter(value =>
WonderCommonlib.NullService.isInMap(value)
&& func(. value |> WonderCommonlib.SparseMapType.nullableToNotNullable)
);
/* |> WonderCommonlib.SparseMapType.arrayNullableToArrayNotNullable; */
43 changes: 43 additions & 0 deletions src/service/state/engine/script/ScriptEngineService.re
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,47 @@ let updateEventFunctionInAllScriptComponents =
),
},
};
};

let _removeScriptDataMapInAllScriptComponents = (dataName, scriptDataMap) =>
scriptDataMap
|> WonderEditor.ImmutableSparseMapService.filterValid((. dataMap) =>
!(dataMap |> WonderCommonlib.ImmutableHashMapService.has(dataName))
);

let removeEventFunctionInAllScriptComponents =
(
eventFunctionName,
({scriptRecord}: StateDataMainType.state) as engineState,
) => {
let {scriptEventFunctionDataMap}: StateDataMainType.scriptRecord = scriptRecord;

{
...engineState,
scriptRecord: {
...scriptRecord,
scriptEventFunctionDataMap:
_removeScriptDataMapInAllScriptComponents(
eventFunctionName,
scriptEventFunctionDataMap,
),
},
};
};

let removeAttributeInAllScriptComponents =
(attributeName, ({scriptRecord}: StateDataMainType.state) as engineState) => {
let {scriptAttributeMap}: StateDataMainType.scriptRecord = scriptRecord;

{
...engineState,
scriptRecord: {
...scriptRecord,
scriptAttributeMap:
_removeScriptDataMapInAllScriptComponents(
attributeName,
scriptAttributeMap,
),
},
};
};
20 changes: 17 additions & 3 deletions src/service/stateTuple/logic/asset/DisposeTreeAssetLogicService.re
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ let _disposeWDBNodeEngineData =
(editorState, engineState) |> _disposeWDBGameObjects(wdbGameObjects);
};

let _removeScriptEventFunctionFromScriptComponents =
({name}: NodeAssetType.scriptEventFunctionNodeData, engineState) =>
ScriptEngineService.removeEventFunctionInAllScriptComponents(
name,
engineState,
);

let _removeScriptAttributeFromScriptComponents =
({name}: NodeAssetType.scriptAttributeNodeData, engineState) =>
ScriptEngineService.removeAttributeInAllScriptComponents(name, engineState);

let _disposeNodeEngineData = (node, editorState, engineState) =>
NodeAssetService.handleNode(
~node,
Expand All @@ -135,9 +146,12 @@ let _disposeNodeEngineData = (node, editorState, engineState) =>
~materialNodeFunc=
(_, nodeData) =>
_disposeMaterialNodeEngineData(nodeData, (editorState, engineState)),
/* TODO remove from script component */
~scriptEventFunctionNodeFunc=(_, _) => engineState,
~scriptAttributeNodeFunc=(_, _) => engineState,
~scriptEventFunctionNodeFunc=
(_, nodeData) =>
_removeScriptEventFunctionFromScriptComponents(nodeData, engineState),
~scriptAttributeNodeFunc=
(_, nodeData) =>
_removeScriptAttributeFromScriptComponents(nodeData, engineState),
~wdbNodeFunc=
(_, nodeData) =>
_disposeWDBNodeEngineData(nodeData, (editorState, engineState)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,34 +439,6 @@ exports[`MainEditorAssetHeader->remove material
click remove-button;
should remove it from assetTreeRoot 1`] = `
<article
className="wonder-asset-assetTree"
>
<ul
className="wonder-tree-node"
>
<li>
<div
className="item-triangle"
/>
<img
className="treeNode-icon"
src="./public/img/package.png"
/>
<div
className="draggable-container select-not-active"
draggable={true}
onClick={[Function]}
onDragEnd={[Function]}
onDragEnter={[Function]}
onDragLeave={[Function]}
onDragOver={[Function]}
onDragStart={[Function]}
onDrop={[Function]}
style={Object {}}
>
Assets
</div>
</li>
</ul>
</article>
className="wonder-asset-assetChildren"
/>
`;
Loading

0 comments on commit 119af1d

Please sign in to comment.