Skip to content

Commit

Permalink
feat(asset-bundle): add "asset->load assetBundle" logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed May 6, 2019
1 parent f0f289c commit 51fba9d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 =>
Expand Down Expand Up @@ -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(
(
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ let getUploadAssetType = name => {
| ".jpg"
| ".jpeg"
| ".png" => LoadTexture
| ".rab"
| ".sab"
| ".wab" => LoadAssetBundle
| ".zip" => LoadGLTFZip
| _ =>
ConsoleUtils.error(
Expand Down Expand Up @@ -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 => ()
Expand All @@ -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),
),
);
1 change: 1 addition & 0 deletions src/service/record/editor/data/asset/NodeAssetType.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type uploadFileType =
| LoadGLB
| LoadGLTFZip
| LoadTexture
| LoadAssetBundle
| LoadWPK
| LoadError;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let addAssetBundleNodeToAssetTree = (targetTreeNode, newNode, editorState) =>
NodeAssetEditorService.addNodeToAssetTree(
targetTreeNode,
newNode,
editorState,
);
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ let _ =

LoadAssetUtils._handleAssetSpecificFuncByTypeSync(
_getErrorTypeFile(),
(() => (), () => (), () => (), () => ()),
(() => (), () => (), () => (), () => (), () => ()),
);

ConsoleTool.judgeError("type is error", errorStub);
Expand Down

0 comments on commit 51fba9d

Please sign in to comment.