From 51fba9dda581bcfdb25b84fe47989c835d4f6e8d Mon Sep 17 00:00:00 2001 From: yyc <395976266@qq.com> Date: Mon, 6 May 2019 12:31:49 +0800 Subject: [PATCH] feat(asset-bundle): add "asset->load assetBundle" logic --- .../utils/AssetHeaderUtils.re | 60 ++++++++++++++++++- .../asset/utils/LoadAssetUtils.re | 13 +++- .../record/editor/data/asset/NodeAssetType.re | 1 + .../AssetBundleNodeAssetEditorService.re | 6 ++ .../mainEditorAssetHeaderLoadFile_test.re | 2 +- 5 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 src/service/state/editor/asset/AssetBundleNodeAssetEditorService.re diff --git a/src/core/composable_component/mainEditor/composable_component/bottom_components/composable_component/project/composable_component/asset/composable_component/utils/AssetHeaderUtils.re b/src/core/composable_component/mainEditor/composable_component/bottom_components/composable_component/project/composable_component/asset/composable_component/utils/AssetHeaderUtils.re index f5614c795..a5f82fea1 100755 --- a/src/core/composable_component/mainEditor/composable_component/bottom_components/composable_component/project/composable_component/asset/composable_component/utils/AssetHeaderUtils.re +++ b/src/core/composable_component/mainEditor/composable_component/bottom_components/composable_component/project/composable_component/asset/composable_component/utils/AssetHeaderUtils.re @@ -122,6 +122,44 @@ let _handleAssetWDBType = (editorState, engineState) |> resolve; }); +/* TODO test */ +let _handleAssetAssetBundleType = + ( + (fileName, assetBundleArrayBuffer), + (assetBundleNodeId, selectedFolderNodeInAssetTree), + (editorState, engineState), + ) => + make((~resolve, ~reject) => { + let editorState = + AssetBundleNodeAssetEditorService.addAssetBundleNodeToAssetTree( + selectedFolderNodeInAssetTree, + AssetBundleNodeAssetService.buildNode( + ~nodeId=assetBundleNodeId, + ~name=FileNameService.getBaseName(fileName), + ~assetBundle=assetBundleArrayBuffer, + ~type_= + switch (FileNameService.getExtName(fileName)) { + | ".rab" => RAB + | ".sab" => SAB + | ".wab" => WAB + | extName => + WonderLog.Log.fatal( + WonderLog.Log.buildFatalMessage( + ~title="_handleAssetAssetBundleType", + ~description={j|unknown extName: $extName|j}, + ~reason="", + ~solution={j||j}, + ~params={j||j}, + ), + ) + }, + ), + editorState, + ); + + resolve(. (editorState, engineState)); + }); + let _handleGLBType = ( (fileName, glbArrayBuffer), @@ -153,11 +191,18 @@ let _handleGLTFZipType = let _handleSpecificFuncByTypeAsync = ( type_, - (handleTextureFunc, handleWDBFunc, handleGLBFunc, handleGLTFZipFuncc), + ( + handleTextureFunc, + handleWDBFunc, + handleAssetBundleFunc, + handleGLBFunc, + handleGLTFZipFuncc, + ), ) => switch (type_) { | LoadTexture => handleTextureFunc() | LoadWDB => handleWDBFunc() + | LoadAssetBundle => handleAssetBundleFunc() | LoadGLB => handleGLBFunc() | LoadGLTFZip => handleGLTFZipFuncc() | LoadError => @@ -222,6 +267,15 @@ let handleFileByTypeAsync = (fileResult: nodeResultType, createJsZipFunc) => { (assetNodeId, selectedFolderNodeInAssetTree), (editorState, engineState), ), + () => + _handleAssetAssetBundleType( + ( + fileResult.name, + fileResult.result |> FileReader.convertResultToArrayBuffer, + ), + (assetNodeId, selectedFolderNodeInAssetTree), + (editorState, engineState), + ), () => _handleGLBType( ( @@ -287,7 +341,9 @@ let fileLoad = ((uiState, dispatchFunc), createJsZipFunc, event) => { FileReader.makeSureCanLoadSameNameFileAgain(target); dispatchFunc( - AppStore.UpdateAction(Update([|UpdateStore.Inspector,UpdateStore.Project|])), + AppStore.UpdateAction( + Update([|UpdateStore.Inspector, UpdateStore.Project|]), + ), ); resolve(); diff --git a/src/core/composable_component/mainEditor/composable_component/bottom_components/composable_component/project/composable_component/asset/utils/LoadAssetUtils.re b/src/core/composable_component/mainEditor/composable_component/bottom_components/composable_component/project/composable_component/asset/utils/LoadAssetUtils.re index 53d87784e..0c73f742c 100755 --- a/src/core/composable_component/mainEditor/composable_component/bottom_components/composable_component/project/composable_component/asset/utils/LoadAssetUtils.re +++ b/src/core/composable_component/mainEditor/composable_component/bottom_components/composable_component/project/composable_component/asset/utils/LoadAssetUtils.re @@ -11,6 +11,9 @@ let getUploadAssetType = name => { | ".jpg" | ".jpeg" | ".png" => LoadTexture + | ".rab" + | ".sab" + | ".wab" => LoadAssetBundle | ".zip" => LoadGLTFZip | _ => ConsoleUtils.error( @@ -66,11 +69,18 @@ let _handlePackageSpecificFuncByTypeSync = (type_, handleWPKFunc) => let _handleAssetSpecificFuncByTypeSync = ( type_, - (handleTextureFunc, handleWDBFunc, handleGLBFunc, handleGLTFZipFunc), + ( + handleTextureFunc, + handleWDBFunc, + handleAssetBundleFunc, + handleGLBFunc, + handleGLTFZipFunc, + ), ) => switch (type_) { | LoadTexture => handleTextureFunc() | LoadWDB => handleWDBFunc() + | LoadAssetBundle => handleAssetBundleFunc() | LoadGLB => handleGLBFunc() | LoadGLTFZip => handleGLTFZipFunc() | LoadError => () @@ -90,5 +100,6 @@ let readAssetByTypeSync = (reader, fileInfo: fileInfoType) => () => FileReader.readAsArrayBuffer(reader, fileInfo.file), () => FileReader.readAsArrayBuffer(reader, fileInfo.file), () => FileReader.readAsArrayBuffer(reader, fileInfo.file), + () => FileReader.readAsArrayBuffer(reader, fileInfo.file), ), ); \ No newline at end of file diff --git a/src/service/record/editor/data/asset/NodeAssetType.re b/src/service/record/editor/data/asset/NodeAssetType.re index e69642b3f..90ab528f0 100755 --- a/src/service/record/editor/data/asset/NodeAssetType.re +++ b/src/service/record/editor/data/asset/NodeAssetType.re @@ -5,6 +5,7 @@ type uploadFileType = | LoadGLB | LoadGLTFZip | LoadTexture + | LoadAssetBundle | LoadWPK | LoadError; diff --git a/src/service/state/editor/asset/AssetBundleNodeAssetEditorService.re b/src/service/state/editor/asset/AssetBundleNodeAssetEditorService.re new file mode 100644 index 000000000..1a67f1bf1 --- /dev/null +++ b/src/service/state/editor/asset/AssetBundleNodeAssetEditorService.re @@ -0,0 +1,6 @@ +let addAssetBundleNodeToAssetTree = (targetTreeNode, newNode, editorState) => + NodeAssetEditorService.addNodeToAssetTree( + targetTreeNode, + newNode, + editorState, + ); \ No newline at end of file diff --git a/test/integration/asset/composable_component/header/mainEditorAssetHeaderLoadFile_test.re b/test/integration/asset/composable_component/header/mainEditorAssetHeaderLoadFile_test.re index a45c093ce..6a3a32c97 100755 --- a/test/integration/asset/composable_component/header/mainEditorAssetHeaderLoadFile_test.re +++ b/test/integration/asset/composable_component/header/mainEditorAssetHeaderLoadFile_test.re @@ -295,7 +295,7 @@ let _ = LoadAssetUtils._handleAssetSpecificFuncByTypeSync( _getErrorTypeFile(), - (() => (), () => (), () => (), () => ()), + (() => (), () => (), () => (), () => (), () => ()), ); ConsoleTool.judgeError("type is error", errorStub);