Skip to content
Permalink
Browse files

feat(asset): fix rename script attribute asset->attribute name: now u…

…pdate in all script components
  • Loading branch information...
yyc-git committed Apr 11, 2019
1 parent ce19924 commit fee5180e17ef45a07d128b0be47d83c338c5fc7d
@@ -28,6 +28,9 @@ let getNodeName = node => getNodeData(node).name;

let getNodeNameByData = (nodeData: scriptAttributeNodeData) => nodeData.name;

let getAttributeByData = (nodeData: scriptAttributeNodeData) =>
nodeData.attribute;

let isScriptAttributeNode = node =>
switch (node) {
| ScriptAttributeNode(_, _) => true
@@ -112,7 +112,7 @@ let _replaceScriptDataByEntriesMap =
script,
scriptDataEntriesMap
/* |> WonderCommonlib.ImmutableHashMapService.getValidEntries
|> WonderCommonlib.SparseMapType.arrayNotNullableToArrayNullable */
|> WonderCommonlib.SparseMapType.arrayNotNullableToArrayNullable */
|> WonderCommonlib.ImmutableSparseMapService.reduceValid(
(. dataMap, (name, newData)) =>
dataMap |> WonderCommonlib.ImmutableHashMapService.has(name) ?
@@ -302,4 +302,29 @@ let removeAttributeInAllScriptComponents =
),
},
};
};
};

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

scriptAttributeMap |> WonderCommonlib.ImmutableSparseMapService.getValidKeys;
};

let replaceAttributeInAllScriptComponents =
(
(oldAttributeName, newAttributeName),
newAttribute,
({scriptRecord}: StateDataMainType.state) as engineState,
) =>
getAllScriptsWithAttribute(engineState)
|> WonderCommonlib.ArrayService.reduceOneParam(
(. engineState, script) =>
engineState
|> replaceScriptAttribute(
script,
(oldAttributeName, newAttributeName),
newAttribute,
),
engineState,
);
@@ -127,103 +127,104 @@ let _scriptEventFunctionNodeFunc =
(result, tree, engineState),
nodeId,
nodeData,
) => {
let (result, newTree, engineState) =
result
|> Result.RelationResult.isSuccess
&& NodeAssetService.isIdEqual(nodeId, targetNodeId) ?
{
let (result, newTree) =
switch (
_checkParentNode(parentFolderNode, name, engineState)
|> Result.RelationResult.handleSuccess(() =>
ScriptEventFunctionNodeNameAssetService.isTreeScriptEventFunctionNodesHasTargetName(
name,
tree,
) ?
Result.RelationResult.fail(
LanguageUtils.getMessageLanguageDataByType(
"asset-rename-scriptEventFunction",
LanguageEditorService.unsafeGetType
|> StateLogicService.getEditorState,
)
->Some,
) :
Result.RelationResult.success()
)
) {
| Success () as result => (
result,
OperateTreeAssetService.updateNode(
nodeId,
ScriptEventFunctionNodeNameAssetService.rename(
~name,
~nodeData,
),
ScriptEventFunctionNodeAssetService.buildNodeByNodeData,
tree,
) =>
result
|> Result.RelationResult.isSuccess
&& NodeAssetService.isIdEqual(nodeId, targetNodeId) ?
{
let (result, newTree) =
switch (
_checkParentNode(parentFolderNode, name, engineState)
|> Result.RelationResult.handleSuccess(() =>
ScriptEventFunctionNodeNameAssetService.isTreeScriptEventFunctionNodesHasTargetName(
name,
tree,
) ?
Result.RelationResult.fail(
LanguageUtils.getMessageLanguageDataByType(
"asset-rename-scriptEventFunction",
LanguageEditorService.unsafeGetType
|> StateLogicService.getEditorState,
)
->Some,
) :
Result.RelationResult.success()
)
) {
| Success () as result => (
result,
OperateTreeAssetService.updateNode(
nodeId,
ScriptEventFunctionNodeNameAssetService.rename(
~name,
~nodeData,
),
)
| Fail(msg) as result => (result, tree)
};

(result, newTree, engineState);
} :
(result, tree, engineState);
ScriptEventFunctionNodeAssetService.buildNodeByNodeData,
tree,
),
)
| Fail(msg) as result => (result, tree)
};

(result, newTree, engineState);
};
(result, newTree, engineState);
} :
(result, tree, engineState);

let _scriptAttributeNodeFunc =
(
(targetNodeId, name),
(targetNodeId, newName),
parentFolderNode,
(result, tree, engineState),
nodeId,
nodeData,
) => {
let (result, newTree, engineState) =
result
|> Result.RelationResult.isSuccess
&& NodeAssetService.isIdEqual(nodeId, targetNodeId) ?
{
let (result, newTree) =
switch (
_checkParentNode(parentFolderNode, name, engineState)
|> Result.RelationResult.handleSuccess(() =>
ScriptAttributeNodeNameAssetService.isTreeScriptAttributeNodesHasTargetName(
name,
tree,
) ?
Result.RelationResult.fail(
LanguageUtils.getMessageLanguageDataByType(
"asset-rename-scriptAttribute",
LanguageEditorService.unsafeGetType
|> StateLogicService.getEditorState,
)
->Some,
) :
Result.RelationResult.success()
) =>
result
|> Result.RelationResult.isSuccess
&& NodeAssetService.isIdEqual(nodeId, targetNodeId) ?
switch (
_checkParentNode(parentFolderNode, newName, engineState)
|> Result.RelationResult.handleSuccess(() =>
ScriptAttributeNodeNameAssetService.isTreeScriptAttributeNodesHasTargetName(
newName,
tree,
) ?
Result.RelationResult.fail(
LanguageUtils.getMessageLanguageDataByType(
"asset-rename-scriptAttribute",
LanguageEditorService.unsafeGetType
|> StateLogicService.getEditorState,
)
) {
| Success () as result => (
result,
OperateTreeAssetService.updateNode(
nodeId,
ScriptAttributeNodeNameAssetService.rename(~name, ~nodeData),
ScriptAttributeNodeAssetService.buildNodeByNodeData,
tree,
),
)
| Fail(msg) as result => (result, tree)
};

(result, newTree, engineState);
} :
(result, tree, engineState);
->Some,
) :
Result.RelationResult.success()
)
) {
| Success () as result =>
let oldName =
ScriptAttributeNodeAssetService.getNodeNameByData(nodeData);
let attribute =
ScriptAttributeNodeAssetService.getAttributeByData(nodeData);

(result, newTree, engineState);
};
(
result,
OperateTreeAssetService.updateNode(
nodeId,
ScriptAttributeNodeNameAssetService.rename(
~name=newName,
~nodeData,
),
ScriptAttributeNodeAssetService.buildNodeByNodeData,
tree,
),
engineState
|> ScriptEngineService.replaceAttributeInAllScriptComponents(
(oldName, newName),
attribute,
),
);
| Fail(msg) as result => (result, tree, engineState)
} :
(result, tree, engineState);

let _wdbNodeFunc =
(
@@ -492,4 +492,33 @@ let _ =
})
);
});

describe("test rename attribute", () =>
describe("test update script attribute in all script components", () => {
beforeEach(() =>
ScriptAttributeInspectorTool.TestUpdateScriptAttributeInAllScriptComponents.createDefaultSceneAndAddScriptComponent(
sandbox,
)
);

test("test update one script component", () => {
let (script, addedNodeId, fieldName) =
ScriptAttributeInspectorTool.TestUpdateScriptAttributeInAllScriptComponents.prepareForOneScriptComponent(
sandbox,
);
let newAttributeName = "zzz";

AssetTreeInspectorTool.Rename.renameAssetScriptAttributeNode(
~name=newAttributeName,
~nodeId=addedNodeId,
(),
);

ScriptToolEngine.getScriptAttributeEntries(script, newAttributeName)
|> StateLogicService.getEngineStateToGetData
|> Js.Array.length
|> expect == 1;
});
})
);
});

0 comments on commit fee5180

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