Skip to content

Commit

Permalink
feat(script-component): add "script attribute" logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed Apr 4, 2019
1 parent 0cbcaa0 commit afaba0c
Show file tree
Hide file tree
Showing 8 changed files with 1,457 additions and 223 deletions.

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion src/core/config/data/LanguageInspectorData.re
Expand Up @@ -319,7 +319,7 @@ let inspector_language_array = [|
{
title: "script-add-scriptEventFunction",
language: {
zh: {j|添加Script Event Function|j},
zh: {j|添加script event function|j},
en: "Add script event function",
},
},
Expand All @@ -330,6 +330,20 @@ let inspector_language_array = [|
en: "script event function asset in use",
},
},
{
title: "script-add-scriptAttribute",
language: {
zh: {j|添加script attribute|j},
en: "Add script attribute",
},
},
{
title: "script-use-scriptAttribute-describe",
language: {
zh: {j|使用的script attribute资产|j},
en: "script attribute asset in use",
},
},
{
title: "texture-name-describe",
language: {
Expand Down
8 changes: 7 additions & 1 deletion src/core/config/data/LanguageMessageData.re
Expand Up @@ -106,12 +106,18 @@ let message_language_array = [|
en: "the point light count is exceed max count!",
},
},

{
title: "need-add-scriptEventFunction",
language: {
zh: {j|请添加ScriptEventFunction资产|j},
en: "please add script event function asset",
},
},
{
title: "need-add-scriptAttribute",
language: {
zh: {j|请添加ScriptAttribute资产|j},
en: "please add script attribute asset",
},
},
|];
Expand Up @@ -26,4 +26,13 @@ let getNameAndAttribute = (nodeId, editorState) => {
|> ScriptAttributeNodeAssetService.getNodeData;

(name, attribute);
};
};

let findAllScriptAttributeNodes = editorState =>
IterateTreeAssetEditorService.filter(
~acc=[||],
~pushNodeFunc=(node, acc) => acc |> ArrayService.push(node),
~editorState,
~predScriptAttributeNodeFunc=node => true,
(),
);
46 changes: 46 additions & 0 deletions src/service/state/engine/script/ScriptEngineService.re
Expand Up @@ -38,6 +38,20 @@ let removeScriptAttribute = ScriptAPI.removeScriptAttribute;

/* let replaceScriptAttribute = OperateScriptDataMainService.replaceScriptAttribute; */

let replaceScriptAttribute =
(
script,
(sourceScriptAttributeName, targetScriptAttributeName),
targetScriptAttribute,
state,
) =>
removeScriptAttribute(script, sourceScriptAttributeName, state)
|> addScriptAttribute(
script,
targetScriptAttributeName,
targetScriptAttribute,
);

let unsafeGetScriptAttributeEntries = ScriptAPI.unsafeGetScriptAttributeEntries;

let unsafeGetScriptAttribute = ScriptAPI.unsafeGetScriptAttribute;
Expand Down Expand Up @@ -75,4 +89,36 @@ let hasScriptEventFunctionData =
Some() : None
)
|> Js.Option.isSome;
};

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

switch (
scriptAttributeMap
|> WonderCommonlib.ImmutableSparseMapService.get(script)
) {
| None => WonderCommonlib.ArrayService.createEmpty()
| Some(attributeMap) =>
attributeMap |> WonderCommonlib.ImmutableHashMapService.getValidEntries
};
};

let hasScriptAttributeData =
(
script,
scriptAttributeName,
({scriptRecord}: StateDataMainType.state) as engineState,
) => {
let {scriptAttributeMap}: StateDataMainType.scriptRecord = scriptRecord;

scriptAttributeMap
|> WonderCommonlib.ImmutableSparseMapService.get(script)
|> Js.Option.andThen((. attributeMap) =>
attributeMap
|> WonderCommonlib.ImmutableHashMapService.has(scriptAttributeName) ?
Some() : None
)
|> Js.Option.isSome;
};
@@ -1,19 +1,3 @@
let changeScriptEventFunction =
(
~currentScript,
~currentScriptEventFunctionNodeIdOpt,
~targetScriptEventFunctionNodeId,
~editorState=StateEditorService.getState(),
~engineState=StateEngineService.unsafeGetState(),
(),
) =>
MainEditorScript.Method._changeScriptEventFunction(
currentScript,
currentScriptEventFunctionNodeIdOpt,
targetScriptEventFunctionNodeId,
(editorState, engineState),
);

let buildState =
(
~currentScript,
Expand All @@ -22,26 +6,29 @@ let buildState =
~lastScriptEventFunctionNodeIdForAdd=None,
~lastScriptEventFunctionNodeIdForChange=None,
~unUsedScriptEventFunctionNodeIds=[||],
~isShowScriptAttributeGroupForAdd=false,
~isShowScriptAttributeGroupForChange=false,
~lastScriptAttributeNodeIdForAdd=None,
~lastScriptAttributeNodeIdForChange=None,
~unUsedScriptAttributeNodeIds=[||],
(),
)
: MainEditorScript.state => {
currentScript,
isShowScriptEventFunctionGroupForAdd,
isShowScriptEventFunctionGroupForChange,
currentScript,
lastScriptEventFunctionNodeIdForAdd,
lastScriptEventFunctionNodeIdForChange,
unUsedScriptEventFunctionNodeIds,
isShowScriptAttributeGroupForAdd,
isShowScriptAttributeGroupForChange,
lastScriptAttributeNodeIdForAdd,
lastScriptAttributeNodeIdForChange,
unUsedScriptAttributeNodeIds,
};

let reducer = (~action, ~state) => MainEditorScript.reducer(action, state);

let addScriptEventFunction =
(~script, ~send, ~languageType=LanguageType.EN, ()) =>
MainEditorScript.Method.addScriptEventFunction(
languageType,
(buildState(~currentScript=script, ()), send),
);

let getUpdateState = (~state, ~func) => {
let actionRef = ref(Obj.magic(-1));

Expand All @@ -54,6 +41,29 @@ let getUpdateState = (~state, ~func) => {
reducer(~action=actionRef^, ~state) |> ReactTool.getUpdateState;
};

let changeScriptEventFunction =
(
~currentScript,
~currentScriptEventFunctionNodeIdOpt,
~targetScriptEventFunctionNodeId,
~editorState=StateEditorService.getState(),
~engineState=StateEngineService.unsafeGetState(),
(),
) =>
MainEditorScript.Method._changeScriptEventFunction(
currentScript,
currentScriptEventFunctionNodeIdOpt,
targetScriptEventFunctionNodeId,
(editorState, engineState),
);

let addScriptEventFunction =
(~script, ~send, ~languageType=LanguageType.EN, ()) =>
MainEditorScript.Method.addScriptEventFunction(
languageType,
(buildState(~currentScript=script, ()), send),
);

let sendShowScriptEventFunctionGroupForChange =
(
~send,
Expand Down Expand Up @@ -114,4 +124,87 @@ let removeScriptEventFunction =
script,
eventFunctionName,
dispatchFunc,
);

let changeScriptAttribute =
(
~currentScript,
~currentScriptAttributeNodeIdOpt,
~targetScriptAttributeNodeId,
~editorState=StateEditorService.getState(),
~engineState=StateEngineService.unsafeGetState(),
(),
) =>
MainEditorScript.Method._changeScriptAttribute(
currentScript,
currentScriptAttributeNodeIdOpt,
targetScriptAttributeNodeId,
(editorState, engineState),
);

let addScriptAttribute = (~script, ~send, ~languageType=LanguageType.EN, ()) =>
MainEditorScript.Method.addScriptAttribute(
languageType,
(buildState(~currentScript=script, ()), send),
);

let sendShowScriptAttributeGroupForChange =
(
~send,
~script,
~scriptAttributeNodeId,
~editorState=StateEditorService.getState(),
~engineState=StateEngineService.unsafeGetState(),
(),
) =>
MainEditorScript.Method._sendShowScriptAttributeGroupForChange(
script,
scriptAttributeNodeId,
send,
(editorState, engineState),
);

let getUnUsedScriptAttributeNodeIds = (script, (editorState, engineState)) =>
MainEditorScript.Method._getUnUsedScriptAttributeNodes(
script,
(editorState, engineState),
)
|> Js.Array.map(node => NodeAssetService.getNodeId(~node));

let getScriptAllAttributeNodeIds = (script, (editorState, engineState)) =>
ScriptEngineService.getScriptAllAttributeEntries(script, engineState)
|> Js.Array.map(((name, attributeData)) =>
OperateTreeAssetLogicService.findNodeIdByName(
name,
(editorState, engineState),
)
|> OptionService.unsafeGet
);

let handleChangeScriptAttribute =
(
~script,
~send,
~currentScriptAttributeNodeId,
~targetScriptAttributeNodeId,
) =>
MainEditorScript.Method._handleChangeScriptAttribute(
script,
(targetScriptAttributeNodeId, unUsedScriptAttributeNodeIds) =>
send(
MainEditorScript.ChangeScriptAttributeForAdd(
targetScriptAttributeNodeId,
unUsedScriptAttributeNodeIds,
),
),
currentScriptAttributeNodeId,
targetScriptAttributeNodeId,
);

let removeScriptAttribute =
(~script, ~attributeName, ~dispatchFunc=TestTool.getDispatch(), ()) =>
MainEditorScript.Method._removeScriptAttribute(
script,
attributeName,
dispatchFunc,
);

0 comments on commit afaba0c

Please sign in to comment.