Skip to content
Permalink
Browse files

feat(asset-bundle): add "release asset bundle data" logic

  • Loading branch information...
yyc-git committed Apr 18, 2019
1 parent 07ea399 commit 9067e17112997619f94f56cb39e5c7038bc12c43
@@ -1,18 +1,28 @@
open StateDataMainType;

let markAssembled = (rabRelativePath, {assetBundleRecord} as state) => {
let _markIsAssembled =
(rabRelativePath, isAssembled, {assetBundleRecord} as state) => {
...state,
assetBundleRecord: {
...assetBundleRecord,
assembleRABData: {
...assetBundleRecord.assembleRABData,
isAssembledMap:
assetBundleRecord.assembleRABData.isAssembledMap
|> WonderCommonlib.ImmutableHashMapService.set(rabRelativePath, true),
|> WonderCommonlib.ImmutableHashMapService.set(
rabRelativePath,
isAssembled,
),
},
},
};

let markAssembled = (rabRelativePath, {assetBundleRecord} as state) =>
_markIsAssembled(rabRelativePath, true, state);

let markNotAssembled = (rabRelativePath, {assetBundleRecord} as state) =>
_markIsAssembled(rabRelativePath, false, state);

let isAssembled = (rabRelativePath, {assetBundleRecord} as state) =>
switch (
assetBundleRecord.assembleRABData.isAssembledMap
@@ -22,6 +32,57 @@ let isAssembled = (rabRelativePath, {assetBundleRecord} as state) =>
| Some(isAssembled) => isAssembled
};

let releaseAssembleRABData = (rabRelativePath, {assetBundleRecord} as state) => {
let {assembleRABData} = assetBundleRecord;

{
...state,
assetBundleRecord: {
...assetBundleRecord,
assembleRABData: {
...assembleRABData,
imageMap:
assembleRABData.imageMap
|> WonderCommonlib.ImmutableHashMapService.deleteVal(
rabRelativePath,
),
textureMap:
assembleRABData.textureMap
|> WonderCommonlib.ImmutableHashMapService.deleteVal(
rabRelativePath,
),
basicMaterialMap:
assembleRABData.basicMaterialMap
|> WonderCommonlib.ImmutableHashMapService.deleteVal(
rabRelativePath,
),
lightMaterialMap:
assembleRABData.lightMaterialMap
|> WonderCommonlib.ImmutableHashMapService.deleteVal(
rabRelativePath,
),
geometryMap:
assembleRABData.geometryMap
|> WonderCommonlib.ImmutableHashMapService.deleteVal(
rabRelativePath,
),
scriptEventFunctionDataMap:
assembleRABData.scriptEventFunctionDataMap
|> WonderCommonlib.ImmutableHashMapService.deleteVal(
rabRelativePath,
),
scriptAttributeMap:
assembleRABData.scriptAttributeMap
|> WonderCommonlib.ImmutableHashMapService.deleteVal(
rabRelativePath,
),
},
},
}
/* TODO test */
|> markNotAssembled(rabRelativePath);
};

let setAssembleRABData =
(
rabRelativePath,
@@ -54,24 +54,51 @@ let setLoadedSAB = (sabRelativePath, sab, {assetBundleRecord} as state) => {
},
};

let markLoaded = (sabRelativePath, {assetBundleRecord} as state) => {
let _markIsLoaded = (sabRelativePath, isLoaded, {assetBundleRecord} as state) => {
...state,
assetBundleRecord: {
...assetBundleRecord,
assembleSABData: {
...assetBundleRecord.assembleSABData,
isLoadedMap:
assetBundleRecord.assembleSABData.isLoadedMap
|> WonderCommonlib.ImmutableHashMapService.set(sabRelativePath, true),
|> WonderCommonlib.ImmutableHashMapService.set(
sabRelativePath,
isLoaded,
),
},
},
};

let markLoaded = (sabRelativePath, {assetBundleRecord} as state) =>
_markIsLoaded(sabRelativePath, true, state);

let markNotLoaded = (sabRelativePath, {assetBundleRecord} as state) =>
_markIsLoaded(sabRelativePath, false, state);

let isLoaded = (sabRelativePath, {assetBundleRecord} as state) =>
switch (
assetBundleRecord.assembleSABData.isLoadedMap
|> WonderCommonlib.ImmutableHashMapService.get(sabRelativePath)
) {
| None => false
| Some(isLoaded) => isLoaded
};
};

let releaseLoadedSAB = (sabRelativePath, {assetBundleRecord} as state) =>
{
...state,
assetBundleRecord: {
...assetBundleRecord,
assembleSABData: {
...assetBundleRecord.assembleSABData,
loadedSABMap:
assetBundleRecord.assembleSABData.loadedSABMap
|> WonderCommonlib.ImmutableHashMapService.deleteVal(
sabRelativePath,
),
},
},
}
/* TODO test */
|> markNotLoaded(sabRelativePath);

0 comments on commit 9067e17

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