@ives_xxz/framework 1.6.2 → 1.6.4
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/FW.d.ts +55 -125
- package/config/FWSystemConfig.ts +4 -4
- package/controller/FWLayerController.ts +14 -25
- package/manager/FWAssetManager.ts +46 -67
- package/manager/FWPromiseManager.ts +39 -76
- package/manager/FWResManager.ts +14 -21
- package/manager/FWUiManager.ts +11 -18
- package/package.json +2 -4
- package/service/http/FWHttp.ts +37 -57
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FWSystemConfig } from
|
|
2
|
-
import FWLog from
|
|
3
|
-
import { FWManager } from
|
|
1
|
+
import { FWSystemConfig } from '../config/FWSystemConfig';
|
|
2
|
+
import FWLog from '../log/FWLog';
|
|
3
|
+
import { FWManager } from './FWManager';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 资源数据
|
|
@@ -48,7 +48,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
48
48
|
const img = data.img;
|
|
49
49
|
const ske = data.ske;
|
|
50
50
|
const atlas = data.atlas;
|
|
51
|
-
const type = bin ?
|
|
51
|
+
const type = bin ? '.bin' : '.txt';
|
|
52
52
|
cc.assetManager.loadAny(
|
|
53
53
|
[
|
|
54
54
|
{ url: atlas, ext: type },
|
|
@@ -60,38 +60,34 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
60
60
|
asset.skeletonJson = assets[1];
|
|
61
61
|
asset.atlasText = assets[0];
|
|
62
62
|
asset.textures.push(texture);
|
|
63
|
-
asset[
|
|
64
|
-
asset[
|
|
63
|
+
asset['textureNames'] = [`${img}.png`];
|
|
64
|
+
asset['_uuid'] = ske;
|
|
65
65
|
resolve(asset);
|
|
66
|
-
}
|
|
66
|
+
},
|
|
67
67
|
);
|
|
68
|
-
}, FWSystemConfig.PromiseConfig.loadAsset).promise
|
|
68
|
+
}, FWSystemConfig.PromiseConfig.loadAsset).promise,
|
|
69
69
|
);
|
|
70
70
|
} catch (e) {
|
|
71
|
-
FWLog.error(
|
|
71
|
+
FWLog.error('从远程加载spine动画资源失败!');
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/** 加载远程资源 */
|
|
76
76
|
async loadRemote<T extends cc.Asset = cc.Asset>(
|
|
77
77
|
url?: string,
|
|
78
|
-
cb?: (asset: cc.Asset) => void
|
|
78
|
+
cb?: (asset: cc.Asset) => void,
|
|
79
79
|
): Promise<T> {
|
|
80
80
|
return await this.invoke(
|
|
81
81
|
FW.Entry.promiseMgr.execute((resolve, reject, signal) => {
|
|
82
|
-
cc.assetManager.loadRemote(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
(err, asset) => {
|
|
86
|
-
if (err || !asset) {
|
|
87
|
-
reject(err);
|
|
88
|
-
}
|
|
89
|
-
cb?.(asset as T);
|
|
90
|
-
resolve(asset as T);
|
|
82
|
+
cc.assetManager.loadRemote(url, { cacheEnabled: true, maxRetryCount: 3 }, (err, asset) => {
|
|
83
|
+
if (err || !asset) {
|
|
84
|
+
reject(err);
|
|
91
85
|
}
|
|
92
|
-
|
|
86
|
+
cb?.(asset as T);
|
|
87
|
+
resolve(asset as T);
|
|
88
|
+
});
|
|
93
89
|
}, FWSystemConfig.PromiseConfig.loadAsset).promise,
|
|
94
|
-
`loadAssets -> ${url}
|
|
90
|
+
`loadAssets -> ${url}`,
|
|
95
91
|
);
|
|
96
92
|
}
|
|
97
93
|
|
|
@@ -101,9 +97,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
101
97
|
return undefined;
|
|
102
98
|
}
|
|
103
99
|
|
|
104
|
-
const propertys = Array.isArray(assetProperty)
|
|
105
|
-
? assetProperty
|
|
106
|
-
: [assetProperty];
|
|
100
|
+
const propertys = Array.isArray(assetProperty) ? assetProperty : [assetProperty];
|
|
107
101
|
|
|
108
102
|
await Promise.all(
|
|
109
103
|
propertys.map(async (property) => {
|
|
@@ -112,19 +106,17 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
112
106
|
const path = property.path;
|
|
113
107
|
const progress = property.progress;
|
|
114
108
|
|
|
115
|
-
if (!bundleName || bundleName ===
|
|
109
|
+
if (!bundleName || bundleName === '') {
|
|
116
110
|
FWLog.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
117
111
|
return undefined;
|
|
118
112
|
}
|
|
119
113
|
|
|
120
|
-
if (!path || path ===
|
|
114
|
+
if (!path || path === '') {
|
|
121
115
|
FWLog.error(`找不到资源路径${path},请检查!`);
|
|
122
116
|
return undefined;
|
|
123
117
|
}
|
|
124
118
|
|
|
125
|
-
let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
|
|
126
|
-
bundleName
|
|
127
|
-
);
|
|
119
|
+
let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
|
|
128
120
|
|
|
129
121
|
if (!bundle) {
|
|
130
122
|
FWLog.error(`加载bundle失败,请检查!`);
|
|
@@ -136,24 +128,20 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
136
128
|
bundle.preload(
|
|
137
129
|
path,
|
|
138
130
|
type,
|
|
139
|
-
(
|
|
140
|
-
finish: number,
|
|
141
|
-
total: number,
|
|
142
|
-
item: cc.AssetManager.RequestItem
|
|
143
|
-
) => {
|
|
131
|
+
(finish: number, total: number, item: cc.AssetManager.RequestItem) => {
|
|
144
132
|
progress?.(finish, total, item);
|
|
145
133
|
},
|
|
146
134
|
(err: Error, item: cc.AssetManager.RequestItem[]) => {
|
|
147
135
|
if (err || !item || item?.length == 0) {
|
|
148
|
-
reject(err ||
|
|
136
|
+
reject(err || 'preload failed!');
|
|
149
137
|
}
|
|
150
138
|
resolve(item);
|
|
151
|
-
}
|
|
139
|
+
},
|
|
152
140
|
);
|
|
153
141
|
}, FWSystemConfig.PromiseConfig.loadAsset).promise,
|
|
154
|
-
`preLoadAssets -> ${property.path}
|
|
142
|
+
`preLoadAssets -> ${property.path}`,
|
|
155
143
|
);
|
|
156
|
-
})
|
|
144
|
+
}),
|
|
157
145
|
);
|
|
158
146
|
}
|
|
159
147
|
|
|
@@ -174,19 +162,17 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
174
162
|
const progress = assetProperty.progress;
|
|
175
163
|
const autoRelease = assetProperty.autoRelease;
|
|
176
164
|
|
|
177
|
-
if (!bundleName || bundleName ===
|
|
165
|
+
if (!bundleName || bundleName === '') {
|
|
178
166
|
FWLog.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
179
167
|
return undefined;
|
|
180
168
|
}
|
|
181
169
|
|
|
182
|
-
if (!path || path ===
|
|
170
|
+
if (!path || path === '') {
|
|
183
171
|
FWLog.error(`找不到资源路径${path},请检查!`);
|
|
184
172
|
return undefined;
|
|
185
173
|
}
|
|
186
174
|
|
|
187
|
-
let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
|
|
188
|
-
bundleName
|
|
189
|
-
);
|
|
175
|
+
let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
|
|
190
176
|
|
|
191
177
|
if (!bundle) {
|
|
192
178
|
FWLog.error(`加载bundle失败,请检查!`);
|
|
@@ -204,18 +190,13 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
204
190
|
|
|
205
191
|
assetData.loaded = false;
|
|
206
192
|
|
|
207
|
-
return
|
|
193
|
+
return this.invoke(
|
|
208
194
|
FW.Entry.promiseMgr.execute((resolve, reject, signal) => {
|
|
209
195
|
const self = this;
|
|
210
|
-
|
|
211
196
|
bundle.load(
|
|
212
197
|
path,
|
|
213
198
|
type,
|
|
214
|
-
(
|
|
215
|
-
finish: number,
|
|
216
|
-
total: number,
|
|
217
|
-
item: cc.AssetManager.RequestItem
|
|
218
|
-
) => {
|
|
199
|
+
(finish: number, total: number, item: cc.AssetManager.RequestItem) => {
|
|
219
200
|
progress?.(finish, total, item);
|
|
220
201
|
},
|
|
221
202
|
(err: Error, asset: cc.Asset) => {
|
|
@@ -225,7 +206,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
225
206
|
}
|
|
226
207
|
assetData.loaded = true;
|
|
227
208
|
assetData.dependentBundle = bundleName;
|
|
228
|
-
assetData.uuid = asset[
|
|
209
|
+
assetData.uuid = asset['_uuid'];
|
|
229
210
|
assetData.autoRelease = autoRelease;
|
|
230
211
|
assetData.asset = asset;
|
|
231
212
|
assetData.user = assetProperty.user;
|
|
@@ -236,10 +217,10 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
236
217
|
|
|
237
218
|
cb?.(assetData);
|
|
238
219
|
resolve(assetData);
|
|
239
|
-
}
|
|
220
|
+
},
|
|
240
221
|
);
|
|
241
222
|
}, FWSystemConfig.PromiseConfig.loadAsset).promise,
|
|
242
|
-
`loadAssets -> ${assetProperty.path}
|
|
223
|
+
`loadAssets -> ${assetProperty.path}`,
|
|
243
224
|
);
|
|
244
225
|
}
|
|
245
226
|
/**
|
|
@@ -258,19 +239,17 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
258
239
|
const cb = assetProperty.cb;
|
|
259
240
|
const autoRelease = assetProperty.autoRelease;
|
|
260
241
|
|
|
261
|
-
if (!bundleName || bundleName ===
|
|
242
|
+
if (!bundleName || bundleName === '') {
|
|
262
243
|
FWLog.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
263
244
|
return undefined;
|
|
264
245
|
}
|
|
265
246
|
|
|
266
|
-
if (!path || path ===
|
|
247
|
+
if (!path || path === '') {
|
|
267
248
|
FWLog.error(`找不到资源路径${path},请检查!`);
|
|
268
249
|
return undefined;
|
|
269
250
|
}
|
|
270
251
|
|
|
271
|
-
const bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
|
|
272
|
-
bundleName
|
|
273
|
-
);
|
|
252
|
+
const bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
|
|
274
253
|
|
|
275
254
|
if (!bundle) {
|
|
276
255
|
FWLog.error(`加载bundle失败,请检查!`);
|
|
@@ -280,7 +259,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
280
259
|
return new Promise(
|
|
281
260
|
(
|
|
282
261
|
resolve: (value: FW.AssetData[] | PromiseLike<FW.AssetData[]>) => void,
|
|
283
|
-
reject: (reason?: any) => void
|
|
262
|
+
reject: (reason?: any) => void,
|
|
284
263
|
) => {
|
|
285
264
|
bundle.loadDir(path, type, (err: Error, assets: cc.Asset[]) => {
|
|
286
265
|
if (err || assets.length === 0) {
|
|
@@ -294,7 +273,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
294
273
|
const assetData = new FWAssetData();
|
|
295
274
|
assetData.loaded = true;
|
|
296
275
|
assetData.dependentBundle = bundleName;
|
|
297
|
-
assetData.uuid = asset[
|
|
276
|
+
assetData.uuid = asset['_uuid'];
|
|
298
277
|
assetData.autoRelease = autoRelease;
|
|
299
278
|
assetData.asset = asset;
|
|
300
279
|
assetData.type = type;
|
|
@@ -303,7 +282,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
303
282
|
const key = `${this.createAssetMapKey({
|
|
304
283
|
bundle: bundleName,
|
|
305
284
|
path: path,
|
|
306
|
-
})}/${asset.name}${type ? `_${type?.name}` :
|
|
285
|
+
})}/${asset.name}${type ? `_${type?.name}` : ''}`;
|
|
307
286
|
|
|
308
287
|
this.assetsMap.set(key, assetData);
|
|
309
288
|
|
|
@@ -313,7 +292,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
313
292
|
cb?.(assetDataList);
|
|
314
293
|
resolve(assetDataList);
|
|
315
294
|
});
|
|
316
|
-
}
|
|
295
|
+
},
|
|
317
296
|
);
|
|
318
297
|
}
|
|
319
298
|
|
|
@@ -330,18 +309,18 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
330
309
|
const bundleName = assetProperty.bundle || FW.Entry.bundleName;
|
|
331
310
|
const path = assetProperty.path;
|
|
332
311
|
|
|
333
|
-
if (!bundleName || bundleName ===
|
|
312
|
+
if (!bundleName || bundleName === '') {
|
|
334
313
|
FWLog.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
335
314
|
return undefined;
|
|
336
315
|
}
|
|
337
316
|
|
|
338
|
-
if (!path || path ===
|
|
317
|
+
if (!path || path === '') {
|
|
339
318
|
FWLog.error(`找不到资源路径${path},请检查!`);
|
|
340
319
|
return undefined;
|
|
341
320
|
}
|
|
342
321
|
|
|
343
322
|
if (!this.has(assetProperty)) {
|
|
344
|
-
FWLog.error(
|
|
323
|
+
FWLog.error('获取资源失败,请先加载!');
|
|
345
324
|
return undefined;
|
|
346
325
|
}
|
|
347
326
|
|
|
@@ -365,12 +344,12 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
365
344
|
const path = assetProperty.path;
|
|
366
345
|
const autoRelease = assetProperty.autoRelease;
|
|
367
346
|
|
|
368
|
-
if (!bundleName || bundleName ===
|
|
347
|
+
if (!bundleName || bundleName === '') {
|
|
369
348
|
FWLog.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
370
349
|
return undefined;
|
|
371
350
|
}
|
|
372
351
|
|
|
373
|
-
if (!path || path ===
|
|
352
|
+
if (!path || path === '') {
|
|
374
353
|
FWLog.error(`找不到资源路径${path},请检查!`);
|
|
375
354
|
return undefined;
|
|
376
355
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { FWSystemDefine } from
|
|
2
|
-
import FWLog from
|
|
3
|
-
import { FWManager } from
|
|
4
|
-
|
|
5
|
-
export default class FWPromiseManager
|
|
6
|
-
extends FWManager
|
|
7
|
-
implements FW.PromiseManager
|
|
8
|
-
{
|
|
1
|
+
import { FWSystemDefine } from '../define/FWSystemDefine';
|
|
2
|
+
import FWLog from '../log/FWLog';
|
|
3
|
+
import { FWManager } from './FWManager';
|
|
4
|
+
|
|
5
|
+
export default class FWPromiseManager extends FWManager implements FW.PromiseManager {
|
|
9
6
|
private promiseRegistry: Map<number, FW.PromiseProxy>;
|
|
10
7
|
private uniqueId: number = 0;
|
|
11
8
|
|
|
@@ -21,7 +18,7 @@ export default class FWPromiseManager
|
|
|
21
18
|
/** 创建Promise执行器 */
|
|
22
19
|
public execute<T = any>(
|
|
23
20
|
executor: FW.PromiseExcutor<T>,
|
|
24
|
-
options: FW.PromiseExecuteOptions = {}
|
|
21
|
+
options: FW.PromiseExecuteOptions = {},
|
|
25
22
|
): FW.PromiseProxy<T> {
|
|
26
23
|
const id = this.uniqueId++;
|
|
27
24
|
const abortController = new AbortController();
|
|
@@ -34,18 +31,13 @@ export default class FWPromiseManager
|
|
|
34
31
|
return new Promise<T>((resolve, reject) => {
|
|
35
32
|
if (options.timeout && options.timeout > 0) {
|
|
36
33
|
timerSchedule = FW.Entry.timeMgr.scheduleOnce(() => {
|
|
37
|
-
const timeoutError = new Error(
|
|
38
|
-
`Promise ${id} timeout after ${options.timeout} s`
|
|
39
|
-
);
|
|
34
|
+
const timeoutError = new Error(`Promise ${id} timeout after ${options.timeout} s`);
|
|
40
35
|
if (
|
|
41
36
|
retryCount < maxRetryTimes &&
|
|
42
|
-
(!options.retryCondition ||
|
|
43
|
-
options.retryCondition(timeoutError, retryCount))
|
|
37
|
+
(!options.retryCondition || options.retryCondition(timeoutError, retryCount))
|
|
44
38
|
) {
|
|
45
39
|
retryCount++;
|
|
46
|
-
FWLog.debug(
|
|
47
|
-
`Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`
|
|
48
|
-
);
|
|
40
|
+
FWLog.debug(`Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`);
|
|
49
41
|
if (retryInterval > 0) {
|
|
50
42
|
FW.Entry.timeMgr.scheduleOnce(() => {
|
|
51
43
|
createPromise().then(resolve, reject);
|
|
@@ -61,7 +53,7 @@ export default class FWPromiseManager
|
|
|
61
53
|
}
|
|
62
54
|
|
|
63
55
|
const onAbort = () => {
|
|
64
|
-
FWLog.debug(
|
|
56
|
+
FWLog.debug('promise abort');
|
|
65
57
|
timerSchedule?.unSchedule();
|
|
66
58
|
if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
|
|
67
59
|
promiseProxy.status = FWSystemDefine.FWPromiseStatus.CANCELLED;
|
|
@@ -74,11 +66,11 @@ export default class FWPromiseManager
|
|
|
74
66
|
return;
|
|
75
67
|
}
|
|
76
68
|
|
|
77
|
-
abortController.signal.addEventListener(
|
|
69
|
+
abortController.signal.addEventListener('abort', onAbort);
|
|
78
70
|
|
|
79
71
|
const wrappedResolve = (value: T | PromiseLike<T>) => {
|
|
80
72
|
promiseProxy.status = FWSystemDefine.FWPromiseStatus.FULFILLED;
|
|
81
|
-
abortController.signal.removeEventListener(
|
|
73
|
+
abortController.signal.removeEventListener('abort', onAbort);
|
|
82
74
|
this.removePromise(id);
|
|
83
75
|
timerSchedule?.unSchedule();
|
|
84
76
|
resolve(value);
|
|
@@ -88,14 +80,10 @@ export default class FWPromiseManager
|
|
|
88
80
|
timerSchedule?.unSchedule();
|
|
89
81
|
if (
|
|
90
82
|
retryCount < maxRetryTimes &&
|
|
91
|
-
(!options.retryCondition ||
|
|
92
|
-
options.retryCondition(reason, retryCount))
|
|
83
|
+
(!options.retryCondition || options.retryCondition(reason, retryCount))
|
|
93
84
|
) {
|
|
94
85
|
retryCount++;
|
|
95
|
-
FWLog.debug(
|
|
96
|
-
`Promise ${id} failed, retrying (${retryCount}/${maxRetryTimes}):`,
|
|
97
|
-
reason
|
|
98
|
-
);
|
|
86
|
+
FWLog.debug(`Promise ${id} failed, retrying (${retryCount}/${maxRetryTimes}):`, reason);
|
|
99
87
|
if (retryInterval > 0) {
|
|
100
88
|
FW.Entry.timeMgr.scheduleOnce(() => {
|
|
101
89
|
createPromise().then(resolve, reject);
|
|
@@ -104,29 +92,18 @@ export default class FWPromiseManager
|
|
|
104
92
|
createPromise().then(resolve, reject);
|
|
105
93
|
}
|
|
106
94
|
} else {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
110
|
-
promiseProxy.status = FWSystemDefine.FWPromiseStatus.REJECTED;
|
|
111
|
-
abortController.signal.removeEventListener("abort", onAbort);
|
|
112
|
-
this.removePromise(id);
|
|
113
|
-
reject(reason);
|
|
114
|
-
}
|
|
95
|
+
abortController.signal.removeEventListener('abort', onAbort);
|
|
96
|
+
this.removePromise(id);
|
|
97
|
+
reject(reason);
|
|
115
98
|
}
|
|
116
99
|
};
|
|
117
100
|
try {
|
|
118
|
-
executor(
|
|
119
|
-
wrappedResolve,
|
|
120
|
-
wrappedReject,
|
|
121
|
-
abortController.signal,
|
|
122
|
-
options.reason
|
|
123
|
-
);
|
|
101
|
+
executor(wrappedResolve, wrappedReject, abortController.signal, options.reason);
|
|
124
102
|
} catch (error) {
|
|
125
103
|
wrappedReject(error);
|
|
126
104
|
}
|
|
127
105
|
});
|
|
128
106
|
};
|
|
129
|
-
|
|
130
107
|
const promise = createPromise();
|
|
131
108
|
const promiseProxy: FW.PromiseProxy<T> = {
|
|
132
109
|
id,
|
|
@@ -135,19 +112,18 @@ export default class FWPromiseManager
|
|
|
135
112
|
abortController,
|
|
136
113
|
abort: (reason?: any) => {
|
|
137
114
|
if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
|
|
138
|
-
FWLog.debug(reason ||
|
|
115
|
+
FWLog.debug(reason || 'promise cancelled');
|
|
139
116
|
abortController.abort(reason);
|
|
140
117
|
}
|
|
141
118
|
},
|
|
142
119
|
|
|
143
120
|
addAbortEventListener: (
|
|
144
121
|
listener: (this: AbortSignal, ev: Event) => any,
|
|
145
|
-
options?: boolean | AddEventListenerOptions
|
|
122
|
+
options?: boolean | AddEventListenerOptions,
|
|
146
123
|
) => {
|
|
147
|
-
abortController.signal.addEventListener(
|
|
124
|
+
abortController.signal.addEventListener('abort', listener, options);
|
|
148
125
|
},
|
|
149
126
|
};
|
|
150
|
-
|
|
151
127
|
this.promiseRegistry.set(id, promiseProxy);
|
|
152
128
|
return promiseProxy;
|
|
153
129
|
}
|
|
@@ -155,7 +131,7 @@ export default class FWPromiseManager
|
|
|
155
131
|
/** 批量执行Promise并等待所有完成 */
|
|
156
132
|
public all<T = any>(
|
|
157
133
|
promises: FW.PromiseProxy<T>[],
|
|
158
|
-
options: FW.PromiseExecuteOptions = {}
|
|
134
|
+
options: FW.PromiseExecuteOptions = {},
|
|
159
135
|
): FW.PromiseProxy<FW.PromiseResult<T>> {
|
|
160
136
|
const id = this.uniqueId++;
|
|
161
137
|
const abortController = new AbortController();
|
|
@@ -169,18 +145,13 @@ export default class FWPromiseManager
|
|
|
169
145
|
if (options.timeout && options.timeout > 0) {
|
|
170
146
|
timerSchedule?.unSchedule();
|
|
171
147
|
timerSchedule = FW.Entry.timeMgr.scheduleOnce(() => {
|
|
172
|
-
const timeoutError = new Error(
|
|
173
|
-
`All Promise ${id} timeout after ${options.timeout} s`
|
|
174
|
-
);
|
|
148
|
+
const timeoutError = new Error(`All Promise ${id} timeout after ${options.timeout} s`);
|
|
175
149
|
if (
|
|
176
150
|
retryCount < maxRetryTimes &&
|
|
177
|
-
(!options.retryCondition ||
|
|
178
|
-
options.retryCondition(timeoutError, retryCount))
|
|
151
|
+
(!options.retryCondition || options.retryCondition(timeoutError, retryCount))
|
|
179
152
|
) {
|
|
180
153
|
retryCount++;
|
|
181
|
-
FWLog.debug(
|
|
182
|
-
`All Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`
|
|
183
|
-
);
|
|
154
|
+
FWLog.debug(`All Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`);
|
|
184
155
|
if (retryInterval > 0) {
|
|
185
156
|
FW.Entry.timeMgr.scheduleOnce(() => {
|
|
186
157
|
createPromise().then(resolve, reject);
|
|
@@ -208,7 +179,7 @@ export default class FWPromiseManager
|
|
|
208
179
|
return;
|
|
209
180
|
}
|
|
210
181
|
|
|
211
|
-
abortController.signal.addEventListener(
|
|
182
|
+
abortController.signal.addEventListener('abort', onAbort);
|
|
212
183
|
|
|
213
184
|
const processAll = async () => {
|
|
214
185
|
const result: FW.PromiseResult<T> = {
|
|
@@ -225,8 +196,8 @@ export default class FWPromiseManager
|
|
|
225
196
|
.filter(
|
|
226
197
|
(id) =>
|
|
227
198
|
!result.success.some((s) => s.id === id) &&
|
|
228
|
-
!result.failed.some((f) => f.id === id)
|
|
229
|
-
)
|
|
199
|
+
!result.failed.some((f) => f.id === id),
|
|
200
|
+
),
|
|
230
201
|
);
|
|
231
202
|
break;
|
|
232
203
|
}
|
|
@@ -235,9 +206,7 @@ export default class FWPromiseManager
|
|
|
235
206
|
const value = await promiseProxy.promise;
|
|
236
207
|
result.success.push(value);
|
|
237
208
|
} catch (error) {
|
|
238
|
-
if (
|
|
239
|
-
promiseProxy.status === FWSystemDefine.FWPromiseStatus.CANCELLED
|
|
240
|
-
) {
|
|
209
|
+
if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.CANCELLED) {
|
|
241
210
|
result.cancelled.push(promiseProxy.id);
|
|
242
211
|
} else {
|
|
243
212
|
result.failed.push({
|
|
@@ -254,7 +223,7 @@ export default class FWPromiseManager
|
|
|
254
223
|
processAll()
|
|
255
224
|
.then((result) => {
|
|
256
225
|
promiseProxy.status = FWSystemDefine.FWPromiseStatus.FULFILLED;
|
|
257
|
-
abortController.signal.removeEventListener(
|
|
226
|
+
abortController.signal.removeEventListener('abort', onAbort);
|
|
258
227
|
this.removePromise(id);
|
|
259
228
|
timerSchedule?.unSchedule();
|
|
260
229
|
resolve(result);
|
|
@@ -263,13 +232,12 @@ export default class FWPromiseManager
|
|
|
263
232
|
timerSchedule?.unSchedule();
|
|
264
233
|
if (
|
|
265
234
|
retryCount < maxRetryTimes &&
|
|
266
|
-
(!options.retryCondition ||
|
|
267
|
-
options.retryCondition(error, retryCount))
|
|
235
|
+
(!options.retryCondition || options.retryCondition(error, retryCount))
|
|
268
236
|
) {
|
|
269
237
|
retryCount++;
|
|
270
238
|
FWLog.debug(
|
|
271
239
|
`All Promise ${id} failed, retrying (${retryCount}/${maxRetryTimes}):`,
|
|
272
|
-
error
|
|
240
|
+
error,
|
|
273
241
|
);
|
|
274
242
|
if (retryInterval > 0) {
|
|
275
243
|
FW.Entry.timeMgr.scheduleOnce(() => {
|
|
@@ -279,11 +247,9 @@ export default class FWPromiseManager
|
|
|
279
247
|
createPromise().then(resolve, reject);
|
|
280
248
|
}
|
|
281
249
|
} else {
|
|
282
|
-
if (
|
|
283
|
-
promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING
|
|
284
|
-
) {
|
|
250
|
+
if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
|
|
285
251
|
promiseProxy.status = FWSystemDefine.FWPromiseStatus.REJECTED;
|
|
286
|
-
abortController.signal.removeEventListener(
|
|
252
|
+
abortController.signal.removeEventListener('abort', onAbort);
|
|
287
253
|
this.removePromise(id);
|
|
288
254
|
reject(error);
|
|
289
255
|
}
|
|
@@ -300,15 +266,15 @@ export default class FWPromiseManager
|
|
|
300
266
|
abortController,
|
|
301
267
|
abort: (reason?: any) => {
|
|
302
268
|
if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
|
|
303
|
-
FWLog.debug(reason ||
|
|
269
|
+
FWLog.debug(reason || 'all promise cancelled');
|
|
304
270
|
abortController.abort(reason);
|
|
305
271
|
}
|
|
306
272
|
},
|
|
307
273
|
addAbortEventListener: (
|
|
308
274
|
listener: (this: AbortSignal, ev: Event) => any,
|
|
309
|
-
options?: boolean | AddEventListenerOptions
|
|
275
|
+
options?: boolean | AddEventListenerOptions,
|
|
310
276
|
) => {
|
|
311
|
-
abortController.signal.addEventListener(
|
|
277
|
+
abortController.signal.addEventListener('abort', listener, options);
|
|
312
278
|
},
|
|
313
279
|
};
|
|
314
280
|
|
|
@@ -319,10 +285,7 @@ export default class FWPromiseManager
|
|
|
319
285
|
/** 取消指定Promise */
|
|
320
286
|
public cancel(id: number, reason?: any): boolean {
|
|
321
287
|
const promiseProxy = this.promiseRegistry.get(id);
|
|
322
|
-
if (
|
|
323
|
-
promiseProxy &&
|
|
324
|
-
promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING
|
|
325
|
-
) {
|
|
288
|
+
if (promiseProxy && promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
|
|
326
289
|
promiseProxy.abort(reason);
|
|
327
290
|
return true;
|
|
328
291
|
}
|
|
@@ -373,7 +336,7 @@ export default class FWPromiseManager
|
|
|
373
336
|
/** 获取正在执行的Promise数量 */
|
|
374
337
|
public getActiveCount(): number {
|
|
375
338
|
return Array.from(this.promiseRegistry.values()).filter(
|
|
376
|
-
(p) => p.status === FWSystemDefine.FWPromiseStatus.PENDING
|
|
339
|
+
(p) => p.status === FWSystemDefine.FWPromiseStatus.PENDING,
|
|
377
340
|
).length;
|
|
378
341
|
}
|
|
379
342
|
|
package/manager/FWResManager.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import FWAssetConfig from
|
|
2
|
-
import { FWSystemConfig } from
|
|
3
|
-
import { FWSystemDefine } from
|
|
4
|
-
import FWLog from
|
|
5
|
-
import { FWLodash } from
|
|
6
|
-
import { FWAssetManager } from
|
|
7
|
-
import { FWBundleManager } from
|
|
8
|
-
import { FWManager } from
|
|
1
|
+
import FWAssetConfig from '../config/FWAssetConfig';
|
|
2
|
+
import { FWSystemConfig } from '../config/FWSystemConfig';
|
|
3
|
+
import { FWSystemDefine } from '../define/FWSystemDefine';
|
|
4
|
+
import FWLog from '../log/FWLog';
|
|
5
|
+
import { FWLodash } from '../utils/FWLodash';
|
|
6
|
+
import { FWAssetManager } from './FWAssetManager';
|
|
7
|
+
import { FWBundleManager } from './FWBundleManager';
|
|
8
|
+
import { FWManager } from './FWManager';
|
|
9
9
|
|
|
10
10
|
export class FWResManager extends FWManager implements FW.ResManager {
|
|
11
|
-
bundleMgr: FW.BundleManager;
|
|
12
|
-
assetMgr: FW.AssetManager;
|
|
11
|
+
private bundleMgr: FW.BundleManager;
|
|
12
|
+
private assetMgr: FW.AssetManager;
|
|
13
13
|
|
|
14
14
|
public initialize() {
|
|
15
15
|
this.bundleMgr = new FWBundleManager(this);
|
|
16
16
|
this.assetMgr = new FWAssetManager(this);
|
|
17
|
-
this.bundleMgr.initialize();
|
|
18
|
-
this.assetMgr.initialize();
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
/**
|
|
@@ -36,7 +34,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
36
34
|
await this.loadBundle(depend);
|
|
37
35
|
|
|
38
36
|
const config = FW.Entry.getComponent<FWAssetConfig>(
|
|
39
|
-
`${depend}${FWSystemDefine.FWBindTag.CONFIG}
|
|
37
|
+
`${depend}${FWSystemDefine.FWBindTag.CONFIG}`,
|
|
40
38
|
);
|
|
41
39
|
if (!config) continue;
|
|
42
40
|
const preLoad = config.preLoad;
|
|
@@ -72,7 +70,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
72
70
|
reject(e);
|
|
73
71
|
}
|
|
74
72
|
}, FWSystemConfig.PromiseConfig.loadBundle).promise,
|
|
75
|
-
`
|
|
73
|
+
`loadBundle -> ${bundleName}`,
|
|
76
74
|
);
|
|
77
75
|
}
|
|
78
76
|
/**
|
|
@@ -89,10 +87,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
89
87
|
return await this.assetMgr.loadSpineDataFromRemote(data);
|
|
90
88
|
}
|
|
91
89
|
|
|
92
|
-
async loadRemote<T extends cc.Asset = cc.Asset>(
|
|
93
|
-
url: string,
|
|
94
|
-
cb: (asset: any) => T
|
|
95
|
-
): Promise<T> {
|
|
90
|
+
async loadRemote<T extends cc.Asset = cc.Asset>(url: string, cb: (asset: any) => T): Promise<T> {
|
|
96
91
|
const asset = await this.assetMgr.loadRemote(url);
|
|
97
92
|
if (asset instanceof cc.Texture2D) {
|
|
98
93
|
return new cc.SpriteFrame(asset) as unknown as T;
|
|
@@ -139,9 +134,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
139
134
|
* @param assetProperty
|
|
140
135
|
* @returns
|
|
141
136
|
*/
|
|
142
|
-
async loadAsset<T extends cc.Asset>(
|
|
143
|
-
assetProperty: FW.AssetProperty
|
|
144
|
-
): Promise<T> {
|
|
137
|
+
async loadAsset<T extends cc.Asset>(assetProperty: FW.AssetProperty): Promise<T> {
|
|
145
138
|
const res = await this.assetMgr.load(assetProperty);
|
|
146
139
|
return this.process<T>(res).asset as T;
|
|
147
140
|
}
|