From b149ac7552aac5f35e0859d641d5becef95b4ccd Mon Sep 17 00:00:00 2001 From: yyc <395976266@qq.com> Date: Sun, 2 Jun 2019 06:20:52 +0800 Subject: [PATCH] feat(asset-bundle): fix generate single rab: added light material shouldn't add to basic material resource data --- .../HeaderAssetBundleGenerateSingleRAB.re | 14 +- ...ader_assetBundle_generateSingleRAB_test.re | 259 ++++++++++-------- 2 files changed, 151 insertions(+), 122 deletions(-) diff --git a/src/core/composable_component/header/atom_component/asset_bundle/HeaderAssetBundleGenerateSingleRAB.re b/src/core/composable_component/header/atom_component/asset_bundle/HeaderAssetBundleGenerateSingleRAB.re index 0dc68f60e..a766dec40 100644 --- a/src/core/composable_component/header/atom_component/asset_bundle/HeaderAssetBundleGenerateSingleRAB.re +++ b/src/core/composable_component/header/atom_component/asset_bundle/HeaderAssetBundleGenerateSingleRAB.re @@ -116,18 +116,6 @@ module Method = { let value = ValueNodeSelectTreeService.getValue(nodeData); switch (ValueNodeSelectTreeService.getType(nodeData)) { - | "texture" => ( - basicMaterials, - lightMaterials, - _addResourceData( - textures, - value, - HeaderAssetBundleType.convertValueToTextureData, - ), - geometrys, - scriptEventFunctionDataArr, - scriptAttributeDataArr, - ) | "basicMaterial" => ( _addResourceData(basicMaterials, value, value => value @@ -142,7 +130,7 @@ module Method = { ) | "lightMaterial" => ( basicMaterials, - _addResourceData(basicMaterials, value, value => + _addResourceData(lightMaterials, value, value => value |> HeaderAssetBundleType.convertValueToMaterialData |> _getMaterialComponentFromMaterialData diff --git a/test/unit/composable_component/header/Header_assetBundle_generateSingleRAB_test.re b/test/unit/composable_component/header/Header_assetBundle_generateSingleRAB_test.re index e505c5f84..771a2bed8 100644 --- a/test/unit/composable_component/header/Header_assetBundle_generateSingleRAB_test.re +++ b/test/unit/composable_component/header/Header_assetBundle_generateSingleRAB_test.re @@ -197,120 +197,161 @@ let _ = }) ); - describe("add lightMaterial contained textureData to textures", () => - testPromise( - "if selectTree->textures not has selectTree->lightMaterials contained textureData, resourceData->textures should has them", - () => { + describe("test resource data->material data", () => { + describe( + "add light material contained textureData to textures", () => + testPromise( + "if selectTree->textures not has selectTree->lightMaterials contained textureData, resourceData->textures should has them", + () => { + let addedMaterialNodeId1 = + MainEditorAssetIdTool.getNewAssetId(); + MainEditorAssetHeaderOperateNodeTool.addMaterial(); + + let addedMaterialNodeId2 = + MainEditorAssetIdTool.getNewAssetId(); + MainEditorAssetHeaderOperateNodeTool.addMaterial(); + + let addedFolderNodeId1 = + MainEditorAssetIdTool.getNewAssetId(); + MainEditorAssetHeaderOperateNodeTool.addFolder(); + + MainEditorAssetTreeTool.Select.selectFolderNode( + ~nodeId=addedFolderNodeId1, + (), + ); + + MainEditorAssetUploadTool.loadOneTexture( + ~imgName="image1.png", + ~imgSrc=Base64Tool.buildFakeBase64_1(), + (), + ) + |> then_(uploadedTextureNodeId1 => + MainEditorAssetUploadTool.loadOneTexture( + ~imgName="image2.png", + ~imgSrc=Base64Tool.buildFakeBase64_2(), + (), + ) + |> then_(uploadedTextureNodeId2 => { + MainEditorLightMaterialForAssetTool.dragAssetTextureToMap( + ~currentNodeId=addedMaterialNodeId2, + ~textureNodeId=uploadedTextureNodeId2, + ~material= + MainEditorAssetMaterialNodeTool.getMaterialComponent( + ~nodeId=addedMaterialNodeId2, + (), + ), + (), + ); + + let selectTree = + HeaderAssetBundleTool.GenerateSingleRAB.buildSelectTreeForGenerateSingleRAB + |> StateLogicService.getStateToGetData + |> SelectTreeTool.setSelectForSelectTree( + true, + MainEditorAssetMaterialNodeTool.getMaterialName( + ~nodeId=addedMaterialNodeId2, + (), + ), + ) + |> SelectTreeTool.setSelectForSelectTree( + true, + MainEditorAssetTextureNodeTool.getTextureName( + ~nodeId=uploadedTextureNodeId1, + (), + ), + ); + + let ( + basicMaterials, + lightMaterials, + textures, + geometrys, + scriptEventFunctionDataArr, + scriptAttributeDataArr, + imageDataMap, + ) = + HeaderAssetBundleTool.GenerateSingleRAB.generateSingleRABResourceData( + selectTree, + ) + |> StateLogicService.getStateToGetData; + + let editorState = StateEditorService.getState(); + (lightMaterials, textures) + |> expect + == ( + [| + MainEditorAssetMaterialNodeTool.getMaterialComponent( + ~nodeId=addedMaterialNodeId2, + (), + ), + |], + [| + HeaderAssetBundleTool.GenerateSingleRAB.buildTextureData( + MainEditorAssetTextureNodeTool.getTextureComponent( + uploadedTextureNodeId1, + editorState, + ), + MainEditorAssetTextureNodeTool.getTextureImageDataIndex( + uploadedTextureNodeId1, + editorState, + ), + ), + HeaderAssetBundleTool.GenerateSingleRAB.buildTextureData( + MainEditorAssetTextureNodeTool.getTextureComponent( + uploadedTextureNodeId2, + editorState, + ), + MainEditorAssetTextureNodeTool.getTextureImageDataIndex( + uploadedTextureNodeId2, + editorState, + ), + ), + |], + ) + |> resolve; + }) + ); + }, + ) + ); + + describe("fix bug", () => + test( + "added light material shouldn't add to basic material resource data", + () => { let addedMaterialNodeId1 = MainEditorAssetIdTool.getNewAssetId(); MainEditorAssetHeaderOperateNodeTool.addMaterial(); - let addedMaterialNodeId2 = - MainEditorAssetIdTool.getNewAssetId(); - MainEditorAssetHeaderOperateNodeTool.addMaterial(); + let selectTree = + HeaderAssetBundleTool.GenerateSingleRAB.buildSelectTreeForGenerateSingleRAB + |> StateLogicService.getStateToGetData + |> SelectTreeTool.setSelectForSelectTree( + true, + MainEditorAssetMaterialNodeTool.getMaterialName( + ~nodeId=addedMaterialNodeId1, + (), + ), + ); - let addedFolderNodeId1 = MainEditorAssetIdTool.getNewAssetId(); - MainEditorAssetHeaderOperateNodeTool.addFolder(); - - MainEditorAssetTreeTool.Select.selectFolderNode( - ~nodeId=addedFolderNodeId1, - (), - ); - - MainEditorAssetUploadTool.loadOneTexture( - ~imgName="image1.png", - ~imgSrc=Base64Tool.buildFakeBase64_1(), - (), - ) - |> then_(uploadedTextureNodeId1 => - MainEditorAssetUploadTool.loadOneTexture( - ~imgName="image2.png", - ~imgSrc=Base64Tool.buildFakeBase64_2(), - (), - ) - |> then_(uploadedTextureNodeId2 => { - MainEditorLightMaterialForAssetTool.dragAssetTextureToMap( - ~currentNodeId=addedMaterialNodeId2, - ~textureNodeId=uploadedTextureNodeId2, - ~material= - MainEditorAssetMaterialNodeTool.getMaterialComponent( - ~nodeId=addedMaterialNodeId2, - (), - ), - (), - ); - - let selectTree = - HeaderAssetBundleTool.GenerateSingleRAB.buildSelectTreeForGenerateSingleRAB - |> StateLogicService.getStateToGetData - |> SelectTreeTool.setSelectForSelectTree( - true, - MainEditorAssetMaterialNodeTool.getMaterialName( - ~nodeId=addedMaterialNodeId2, - (), - ), - ) - |> SelectTreeTool.setSelectForSelectTree( - true, - MainEditorAssetTextureNodeTool.getTextureName( - ~nodeId=uploadedTextureNodeId1, - (), - ), - ); - - let ( - basicMaterials, - lightMaterials, - textures, - geometrys, - scriptEventFunctionDataArr, - scriptAttributeDataArr, - imageDataMap, - ) = - HeaderAssetBundleTool.GenerateSingleRAB.generateSingleRABResourceData( - selectTree, - ) - |> StateLogicService.getStateToGetData; - - let editorState = StateEditorService.getState(); - (lightMaterials, textures) - |> expect - == ( - [| - MainEditorAssetMaterialNodeTool.getMaterialComponent( - ~nodeId=addedMaterialNodeId2, - (), - ), - |], - [| - HeaderAssetBundleTool.GenerateSingleRAB.buildTextureData( - MainEditorAssetTextureNodeTool.getTextureComponent( - uploadedTextureNodeId1, - editorState, - ), - MainEditorAssetTextureNodeTool.getTextureImageDataIndex( - uploadedTextureNodeId1, - editorState, - ), - ), - HeaderAssetBundleTool.GenerateSingleRAB.buildTextureData( - MainEditorAssetTextureNodeTool.getTextureComponent( - uploadedTextureNodeId2, - editorState, - ), - MainEditorAssetTextureNodeTool.getTextureImageDataIndex( - uploadedTextureNodeId2, - editorState, - ), - ), - |], - ) - |> resolve; - }) - ); - }, - ) - ); + let ( + basicMaterials, + lightMaterials, + textures, + geometrys, + scriptEventFunctionDataArr, + scriptAttributeDataArr, + imageDataMap, + ) = + HeaderAssetBundleTool.GenerateSingleRAB.generateSingleRABResourceData( + selectTree, + ) + |> StateLogicService.getStateToGetData; + + basicMaterials |> expect == [||]; + }) + ); + }); describe("test resource data->geometrys", () => testPromise("test", () =>