Skip to content

Commit

Permalink
feat(redo-undo): script component->event function add redo/undo
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed Apr 8, 2019
1 parent db43291 commit 6e58c7c
Show file tree
Hide file tree
Showing 10 changed files with 867 additions and 248 deletions.
@@ -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.