Skip to content
Permalink
Browse files

feat(redo-undo): script component->event function add redo/undo

  • Loading branch information...
yyc-git committed Apr 7, 2019
1 parent db43291 commit 6e58c7c41f1ee71c21198abda86cbc54ae05cbb0
@@ -0,0 +1,67 @@
open MainEditorLightType;

module CustomEventHandler = {
include EmptyEventHandler.EmptyEventHandler;
type prepareTuple = (
LanguageType.languageType,
(NodeAssetType.nodeId, array(NodeAssetType.nodeId)) => unit,
);
type dataTuple = Wonderjs.ScriptType.script;
type return = unit;

let handleSelfLogic =
((uiState, dispatchFunc), (languageType, sendFunc), script) => {
let editorState = StateEditorService.getState();
let engineState = StateEngineService.unsafeGetState();

let unUsedScriptEventFunctionNodes =
MainEditorScriptEventFunctionUtils.getUnUsedScriptEventFunctionNodes(
script,
(editorState, engineState),
);

unUsedScriptEventFunctionNodes |> Js.Array.length > 0 ?
{
let unUsedScriptEventFunctionNodeIds =
unUsedScriptEventFunctionNodes
|> Js.Array.map(node => NodeAssetService.getNodeId(~node));

let (
lastScriptEventFunctionNodeIdForAdd,
unUsedScriptEventFunctionNodeIds,
) =
unUsedScriptEventFunctionNodeIds |> ArrayService.removeFirst;

let (name, attribute) =
ScriptEventFunctionNodeAssetEditorService.getNameAndData(
lastScriptEventFunctionNodeIdForAdd,
editorState,
);

let engineState =
ScriptEngineService.addScriptEventFunctionData(
script,
name,
attribute,
engineState,
);

engineState |> StateEngineService.setState |> ignore;
editorState |> StateEditorService.setState |> ignore;
sendFunc(
lastScriptEventFunctionNodeIdForAdd,
unUsedScriptEventFunctionNodeIds,
);
} :
ConsoleUtils.warn(
LanguageUtils.getMessageLanguageDataByType(
"need-add-scriptEventFunction",
languageType,
),
)
|> StateLogicService.getEditorState
|> ignore;
};
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);
@@ -0,0 +1,136 @@
open MainEditorLightType;

module CustomEventHandler = {
include EmptyEventHandler.EmptyEventHandler;
type prepareTuple =
(NodeAssetType.nodeId, array(NodeAssetType.nodeId)) => unit;
type dataTuple = (
Wonderjs.ScriptType.script,
option(NodeAssetType.nodeId),
NodeAssetType.nodeId,
);
type return = unit;

let _changeScriptEventFunction =
(
currentScript,
currentScriptEventFunctionNodeIdOpt,
targetScriptEventFunctionNodeId,
(editorState, engineState),
) => {
WonderLog.Contract.requireCheck(
() =>
WonderLog.(
Contract.(
Operators.(
test(
Log.buildAssertMessage(
~expect={j|targetScriptEventFunctionNodeId not be used|j},
~actual={j|be used|j},
),
() => {
let (name, _) =
ScriptEventFunctionNodeAssetEditorService.getNameAndData(
targetScriptEventFunctionNodeId,
editorState,
);

ScriptEngineService.hasScriptEventFunctionData(
currentScript,
name,
engineState,
)
|> assertFalse;
},
)
)
)
),
StateEditorService.getStateIsDebug(),
);

let (targetName, targetEventFunction) =
ScriptEventFunctionNodeAssetEditorService.getNameAndData(
targetScriptEventFunctionNodeId,
editorState,
);

switch (currentScriptEventFunctionNodeIdOpt) {
| None =>
ScriptEngineService.addScriptEventFunctionData(
currentScript,
targetName,
targetEventFunction,
engineState,
)
| Some(currentScriptEventFunctionNodeId) =>
let (sourceName, _) =
ScriptEventFunctionNodeAssetEditorService.getNameAndData(
currentScriptEventFunctionNodeId,
editorState,
);

ScriptEngineService.replaceScriptEventFunctionData(
currentScript,
(sourceName, targetName),
targetEventFunction,
engineState,
);
};
};

let handleSelfLogic =
(
(uiState, dispatchFunc),
sendFunc,
(
script,
currentScriptEventFunctionNodeId,
targetScriptEventFunctionNodeId,
),
) => {
WonderLog.Contract.requireCheck(
() =>
WonderLog.(
Contract.(
Operators.(
test(
Log.buildAssertMessage(
~expect={j|currentScriptEventFunctionNodeId|j},
~actual={j|not|j},
),
() =>
currentScriptEventFunctionNodeId |> assertExist
)
)
)
),
StateEditorService.getStateIsDebug(),
);

MainEditorScriptUtils.isNodeIdEqual(
currentScriptEventFunctionNodeId,
targetScriptEventFunctionNodeId,
) ?
() :
{
_changeScriptEventFunction(
script,
currentScriptEventFunctionNodeId,
targetScriptEventFunctionNodeId,
)
|> StateLogicService.getStateToGetData
|> StateEngineService.setState;

sendFunc(
targetScriptEventFunctionNodeId,
MainEditorScriptEventFunctionUtils.getUnUsedScriptEventFunctionNodeIds(
script,
)
|> StateLogicService.getStateToGetData,
);
};
};
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);
@@ -0,0 +1,19 @@
open MainEditorLightType;

module CustomEventHandler = {
include EmptyEventHandler.EmptyEventHandler;
type prepareTuple = unit;
type dataTuple = (Wonderjs.ScriptType.script, string);
type return = unit;

let handleSelfLogic =
((uiState, dispatchFunc), (), (script, attributeName)) => {
ScriptEngineService.removeScriptEventFunctionData(script, attributeName)
|> StateLogicService.getAndSetEngineState;

dispatchFunc(AppStore.UpdateAction(Update([|UpdateStore.Inspector|])))
|> ignore;
};
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);

0 comments on commit 6e58c7c

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