Skip to content
Permalink
Browse files

feat(redo-undo): script event function,script attribute asset add red…

…o-undo
  • Loading branch information...
yyc-git committed Apr 7, 2019
1 parent 119af1d commit dd482afe74c057db7e7429bb7f42f5cc34bd273c
Showing with 1,747 additions and 309 deletions.
  1. +53 −0 ...om_component/scriptAttribute_inspector/eventHandler/AddScriptAttributeDefaultFieldEventHandler.re
  2. +45 −0 ...r/atom_component/scriptAttribute_inspector/eventHandler/RemoveScriptAttributeFieldEventHandler.re
  3. +64 −0 ...r/atom_component/scriptAttribute_inspector/eventHandler/RenameScriptAttributeFieldEventHandler.re
  4. +103 −0 ...r/atom_component/scriptAttribute_inspector/eventHandler/UpdateScriptAttributeFieldEventHandler.re
  5. +40 −223 ...onent/assetTree_Inspector/atom_component/scriptAttribute_inspector/ui/ScriptAttributeInspector.re
  6. +10 −0 ...setTree_Inspector/atom_component/scriptAttribute_inspector/utils/ScriptAttributeInspectorUtils.re
  7. +50 −0 ...component/scriptEventFunction_inspector/eventHandler/UpdateScriptEventFunctionDataEventHandler.re
  8. +7 −41 ...setTree_Inspector/atom_component/scriptEventFunction_inspector/ui/ScriptEventFunctionInspector.re
  9. +15 −18 ...le_component/assetTree_inspector/atom_component/script_inspector/scriptAttributeInspector_test.re
  10. +32 −22 ...omponent/assetTree_inspector/atom_component/script_inspector/tool/ScriptAttributeInspectorTool.re
  11. +6 −3 ...nent/assetTree_inspector/atom_component/script_inspector/tool/ScriptEventFunctionInspectorTool.re
  12. +155 −0 ...ion/redo_undo/asset/scriptAttribute/__snapshots__/redo_undo_asset_addScriptAttribute_test.js.snap
  13. +34 −0 .../redo_undo/asset/scriptAttribute/__snapshots__/redo_undo_asset_removeScriptAttribute_test.js.snap
  14. +144 −0 .../asset/scriptAttribute/__snapshots__/redo_undo_asset_scriptAttribute_addDefaultField_test.js.snap
  15. +189 −0 ...ndo/asset/scriptAttribute/__snapshots__/redo_undo_asset_scriptAttribute_operateField_test.js.snap
  16. +43 −0 test/integration/redo_undo/asset/scriptAttribute/redo_undo_asset_addScriptAttribute_test.re
  17. +63 −0 test/integration/redo_undo/asset/scriptAttribute/redo_undo_asset_removeScriptAttribute_test.re
  18. +81 −0 ...tegration/redo_undo/asset/scriptAttribute/redo_undo_asset_scriptAttribute_addDefaultField_test.re
  19. +226 −0 .../integration/redo_undo/asset/scriptAttribute/redo_undo_asset_scriptAttribute_operateField_test.re
  20. +155 −0 ..._undo/asset/scriptEventFunction/__snapshots__/redo_undo_asset_addScriptEventFunction_test.js.snap
  21. +34 −0 ...do/asset/scriptEventFunction/__snapshots__/redo_undo_asset_removeScriptEventFunction_test.js.snap
  22. +43 −0 test/integration/redo_undo/asset/scriptEventFunction/redo_undo_asset_addScriptEventFunction_test.re
  23. +64 −0 ...integration/redo_undo/asset/scriptEventFunction/redo_undo_asset_removeScriptEventFunction_test.re
  24. +87 −0 ...ration/redo_undo/asset/scriptEventFunction/redo_undo_asset_scriptEventFunction_updateData_test.re
  25. +4 −2 test/tool/BuildComponentTool.re
@@ -0,0 +1,53 @@
module CustomEventHandler = {
include EmptyEventHandler.EmptyEventHandler;
type prepareTuple = Wonderjs.ScriptAttributeType.scriptAttribute => unit;

type dataTuple = NodeAssetType.nodeId;

type return = unit;

let _getAttributeNodeData = (nodeId, editorState) =>
OperateTreeAssetEditorService.unsafeFindNodeById(nodeId)
|> StateLogicService.getEditorState
|> ScriptAttributeNodeAssetService.getNodeData;

let _getDefaultFieldType = () => "float";

let _getDefaultFieldDefaultValue = () =>
0.0 |> Wonderjs.ScriptAttributeType.floatToScriptAttributeValue;

let handleSelfLogic = ((uiState, dispatchFunc), sendFunc, nodeId) => {
let {name as attributeName, attribute}: NodeAssetType.scriptAttributeNodeData =
_getAttributeNodeData(nodeId) |> StateLogicService.getEditorState;

let attribute =
ScriptAttributeEngineService.addScriptAttributeField(
OperateTreeAssetLogicService.getUniqueScriptAttributeFieldName(
ScriptAttributeNodeNameAssetService.getNewFieldName(),
attribute,
),
{
"type": _getDefaultFieldType(),
"defaultValue": _getDefaultFieldDefaultValue(),
},
attribute,
);

ScriptAttributeInspectorUtils.updateScriptAttributeNode(
nodeId,
attributeName,
attribute,
)
|> StateLogicService.getAndSetEditorState;

ScriptEngineService.updateAttributeInAllScriptComponents(
attributeName,
attribute,
)
|> StateLogicService.getAndSetEngineState;

sendFunc(attribute);
};
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);
@@ -0,0 +1,45 @@
module CustomEventHandler = {
include EmptyEventHandler.EmptyEventHandler;
type prepareTuple = Wonderjs.ScriptAttributeType.scriptAttribute => unit;
type dataTuple = (NodeAssetType.nodeId, string);
type return = unit;

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

let (attributeName, attribute) =
ScriptAttributeNodeAssetEditorService.getNameAndAttribute(
nodeId,
editorState,
);

let newAttribute =
ScriptAttributeEngineService.removeScriptAttributeField(
fieldName,
attribute,
);

let editorState =
editorState
|> ScriptAttributeInspectorUtils.updateScriptAttributeNode(
nodeId,
attributeName,
newAttribute,
);

let engineState =
ScriptEngineService.updateAttributeInAllScriptComponents(
attributeName,
newAttribute,
engineState,
);

sendFunc(newAttribute);

(editorState, engineState) |> StateLogicService.setState;
};
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);
@@ -0,0 +1,64 @@
module CustomEventHandler = {
include EmptyEventHandler.EmptyEventHandler;
type prepareTuple = (
LanguageType.languageType,
Wonderjs.ScriptAttributeType.scriptAttribute => unit,
);
type dataTuple = (NodeAssetType.nodeId, string, string);
type return = unit;

let handleSelfLogic =
(
(uiState, dispatchFunc),
(languageType, sendFunc),
(nodeId, oldFieldName, newFieldName),
) =>
oldFieldName === newFieldName ?
() :
{
let (attributeName, attribute) =
ScriptAttributeNodeAssetEditorService.getNameAndAttribute(nodeId)
|> StateLogicService.getEditorState;

ScriptAttributeEngineService.hasScriptAttributeField(
newFieldName,
attribute,
) ?
{
ConsoleUtils.warn(
LanguageUtils.getMessageLanguageDataByType(
"asset-rename-scriptAttribute-field",
languageType,
),
)
|> StateLogicService.getEditorState;

sendFunc(attribute);
} :
{
let newAttribute =
ScriptAttributeEngineService.renameScriptAttributeField(
oldFieldName,
newFieldName,
attribute,
);

ScriptAttributeInspectorUtils.updateScriptAttributeNode(
nodeId,
attributeName,
newAttribute,
)
|> StateLogicService.getAndSetEditorState;

ScriptEngineService.updateAttributeInAllScriptComponents(
attributeName,
newAttribute,
)
|> StateLogicService.getAndSetEngineState;

sendFunc(newAttribute);
};
};
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);
@@ -0,0 +1,103 @@
module CustomEventHandler = {
include EmptyEventHandler.EmptyEventHandler;
type prepareTuple = unit;
type dataTuple = (NodeAssetType.nodeId, string, string);
type return = unit;


let _isOnlyFieldDefaultValueChange =
(
(
{type_, defaultValue}: Wonderjs.ScriptAttributeType.scriptAttributeField
) as oldAttributeField,
newAttributeFieldJsObj,
) => {
let newType =
ScriptAttributeTypeService.getTypeFromJsObj(newAttributeFieldJsObj);

let newDefaultValue = newAttributeFieldJsObj##defaultValue;

type_
|> ScriptAttributeTypeService.convertFieldTypeToJsObjStr === newType
&& defaultValue !== newDefaultValue;
};


let handleSelfLogic =
(
(uiState, dispatchFunc),
(),
(nodeId, fieldName, newFieldDataJsObjStr),
) => {
let editorState = StateEditorService.getState();
let engineState = StateEngineService.unsafeGetState();

let (editorState, engineState) =
Console.tryCatch(
() => {
let (attributeName, attribute) =
ScriptAttributeNodeAssetEditorService.getNameAndAttribute(nodeId)
|> StateLogicService.getEditorState;

let newAttributeFieldJsObj =
newFieldDataJsObjStr |> Js.Json.parseExn |> Obj.magic;

let isOnlyFieldDefaultValueChange =
_isOnlyFieldDefaultValueChange(
ScriptAttributeEngineService.unsafeGetScriptAttributeField(
fieldName,
attribute,
),
newAttributeFieldJsObj,
);

let newAttribute =
ScriptAttributeEngineService.replaceScriptAttributeField(
fieldName,
newAttributeFieldJsObj,
attribute,
);

let editorState =
ScriptAttributeInspectorUtils.updateScriptAttributeNode(
nodeId,
attributeName,
newAttribute,
editorState,
);

isOnlyFieldDefaultValueChange ?
(editorState, engineState) :
{
let engineState =
ScriptEngineService.updateAttributeInAllScriptComponents(
attributeName,
newAttribute,
engineState,
);

(editorState, engineState);
};
},
e => {
let message = e##message;

ConsoleUtils.error(
LogUtils.buildErrorMessage(
~description={j|$message|j},
~reason="",
~solution={j||j},
~params={j||j},
),
)
|> StateLogicService.getEditorState;

(editorState, engineState);
},
);

(editorState, engineState) |> StateLogicService.setState;
};
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);

0 comments on commit dd482af

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