@ives_xxz/framework 2.3.5 → 2.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/manager/FWResManager.ts +49 -63
- package/package.json +1 -1
package/manager/FWResManager.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FWSystemConfig } from
|
|
2
|
-
import { FWLodash } from
|
|
3
|
-
import { FWAssetManager } from
|
|
4
|
-
import { FWBundleManager } from
|
|
5
|
-
import { FWManager } from
|
|
1
|
+
import { FWSystemConfig } from '../config/FWSystemConfig';
|
|
2
|
+
import { FWLodash } from '../utils/FWLodash';
|
|
3
|
+
import { FWAssetManager } from './FWAssetManager';
|
|
4
|
+
import { FWBundleManager } from './FWBundleManager';
|
|
5
|
+
import { FWManager } from './FWManager';
|
|
6
6
|
|
|
7
7
|
export class FWResManager extends FWManager implements FW.ResManager {
|
|
8
8
|
private bundleMgr: FW.BundleManager;
|
|
@@ -22,65 +22,60 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
22
22
|
* @returns
|
|
23
23
|
*/
|
|
24
24
|
async loadBundle(bundleName: string): Promise<cc.AssetManager.Bundle> {
|
|
25
|
-
return
|
|
26
|
-
|
|
25
|
+
return new Promise(async (resolve, reject) => {
|
|
26
|
+
try {
|
|
27
27
|
const depends = FWLodash.cloneDeep(FW.Entry.getDepend(bundleName));
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (depend === undefined) continue;
|
|
28
|
+
if (depends && depends.length > 0) {
|
|
29
|
+
for (const depend of depends) {
|
|
30
|
+
if (depend === undefined) continue;
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
if (this.bundleMgr.has(depend)) continue;
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
await this.loadBundle(depend);
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
const config = FW.Entry.getComponent<FW.AssetConfig>(
|
|
37
|
+
`${depend}${FW.SystemDefine.FWBindTag.CONFIG}`,
|
|
38
|
+
);
|
|
39
|
+
if (!config) continue;
|
|
40
|
+
const preLoad = config.preLoad;
|
|
41
|
+
const keys = Object.keys(preLoad);
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
for (const key of Object.keys(obj)) {
|
|
49
|
-
const value: any = (obj as any)[key];
|
|
43
|
+
if (keys.length > 0) {
|
|
44
|
+
const preloadRecursive = async (obj: FW.LoadConfig | FW.AssetProperty) => {
|
|
45
|
+
for (const key of Object.keys(obj)) {
|
|
46
|
+
const value: any = (obj as any)[key];
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
if (value && typeof value.path === 'string') {
|
|
49
|
+
const path: string = value.path;
|
|
50
|
+
const type: string = value.type;
|
|
51
|
+
const d: string = value.bundle || depend;
|
|
52
|
+
const priorityLoaded = value.priorityLoaded || false;
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
} else if (value && typeof value === "object") {
|
|
65
|
-
await preloadRecursive(value);
|
|
54
|
+
if (path && priorityLoaded) {
|
|
55
|
+
await this.assetMgr.load({
|
|
56
|
+
path,
|
|
57
|
+
bundle: d,
|
|
58
|
+
type,
|
|
59
|
+
});
|
|
66
60
|
}
|
|
61
|
+
} else if (value && typeof value === 'object') {
|
|
62
|
+
await preloadRecursive(value);
|
|
67
63
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
await preloadRecursive(config.preLoad);
|
|
71
67
|
}
|
|
72
68
|
}
|
|
69
|
+
}
|
|
73
70
|
|
|
74
|
-
|
|
71
|
+
const bundle = await this.bundleMgr.load(bundleName);
|
|
75
72
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
`loadBundle -> ${bundleName}`,
|
|
83
|
-
);
|
|
73
|
+
resolve(bundle);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
this.rejectHandlerListener?.loadBundleHandler?.(e, bundleName);
|
|
76
|
+
reject(e);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
84
79
|
}
|
|
85
80
|
/**
|
|
86
81
|
* 从远程加载spine动画
|
|
@@ -96,10 +91,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
96
91
|
return await this.assetMgr.loadSpineDataFromRemote(data);
|
|
97
92
|
}
|
|
98
93
|
|
|
99
|
-
async loadRemote<T extends cc.Asset = cc.Asset>(
|
|
100
|
-
url: string,
|
|
101
|
-
texture?: boolean,
|
|
102
|
-
): Promise<T> {
|
|
94
|
+
async loadRemote<T extends cc.Asset = cc.Asset>(url: string, texture?: boolean): Promise<T> {
|
|
103
95
|
try {
|
|
104
96
|
const asset = await this.assetMgr.loadRemote(url);
|
|
105
97
|
if (texture) {
|
|
@@ -191,10 +183,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
191
183
|
* @param bundleName
|
|
192
184
|
* @returns
|
|
193
185
|
*/
|
|
194
|
-
getAssetData<T extends cc.Asset>(
|
|
195
|
-
assetProperty: FW.AssetProperty,
|
|
196
|
-
texture?: boolean,
|
|
197
|
-
) {
|
|
186
|
+
getAssetData<T extends cc.Asset>(assetProperty: FW.AssetProperty, texture?: boolean) {
|
|
198
187
|
const res = this.assetMgr.get(assetProperty);
|
|
199
188
|
if (texture) {
|
|
200
189
|
return res;
|
|
@@ -206,10 +195,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
206
195
|
* @param assetProperty
|
|
207
196
|
* @returns
|
|
208
197
|
*/
|
|
209
|
-
getAsset<T extends cc.Asset>(
|
|
210
|
-
assetProperty: FW.AssetProperty,
|
|
211
|
-
texture?: boolean,
|
|
212
|
-
): T {
|
|
198
|
+
getAsset<T extends cc.Asset>(assetProperty: FW.AssetProperty, texture?: boolean): T {
|
|
213
199
|
const res = this.assetMgr.get(assetProperty);
|
|
214
200
|
if (texture) {
|
|
215
201
|
return res.asset as T;
|