@ives_xxz/framework 1.6.3 → 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 CHANGED
@@ -6,18 +6,13 @@ declare namespace FW {
6
6
  prototype: T;
7
7
  };
8
8
 
9
- type ServiceIdentifierData<TInstance = unknown> =
10
- | string
11
- | symbol
12
- | Newable<TInstance>
13
- | Function;
14
-
15
- type CommonNewable<
16
- TInstance = unknown,
17
- TArgs extends unknown[] = any[]
18
- > = Newable<TInstance, TArgs>;
19
- type CommonServiceIdentifier<TInstance = unknown> =
20
- ServiceIdentifierData<TInstance>;
9
+ type ServiceIdentifierData<TInstance = unknown> = string | symbol | Newable<TInstance> | Function;
10
+
11
+ type CommonNewable<TInstance = unknown, TArgs extends unknown[] = any[]> = Newable<
12
+ TInstance,
13
+ TArgs
14
+ >;
15
+ type CommonServiceIdentifier<TInstance = unknown> = ServiceIdentifierData<TInstance>;
21
16
 
22
17
  type ServiceIdentifier<T = unknown> = CommonServiceIdentifier<T>;
23
18
  /**
@@ -63,13 +58,13 @@ declare namespace FW {
63
58
  resolve: (value: T | PromiseLike<T>) => void,
64
59
  reject: (reason?: any) => void,
65
60
  signal?: AbortSignal,
66
- reason?: any
61
+ reason?: any,
67
62
  ) => void = PromiseExcutor,
68
- options: PromiseExecuteOptions = {}
63
+ options: PromiseExecuteOptions = {},
69
64
  ): PromiseProxy<T>;
70
65
  all<T = any>(
71
66
  promises: FW.PromiseProxy<T>[],
72
- options: FW.PromiseExecuteOptions = {}
67
+ options: FW.PromiseExecuteOptions = {},
73
68
  ): FW.PromiseProxy<FW.PromiseResult<T>>;
74
69
  };
75
70
 
@@ -84,22 +79,18 @@ declare namespace FW {
84
79
  registerLanguagePackageEnum(
85
80
  bundleName: string,
86
81
  language: any,
87
- getter: (key: string, language?: string) => string
82
+ getter: (key: string, language?: string) => string,
88
83
  ): void;
89
84
  getSupportedLanguages(): string[];
90
85
  setSupportedLanguages(languages: string[]): void;
91
86
  getBundles(): string[];
92
87
  getLanguage(): string;
93
88
  getLanguageIndex(): number;
94
- getLanguagePackageValue(
95
- bundleName: string,
96
- key: string,
97
- language?: string
98
- ): string;
89
+ getLanguagePackageValue(bundleName: string, key: string, language?: string): string;
99
90
  getLanguagePackageEnumKeys(bundleName: string): string[];
100
91
  getLanguagePackageEnumValues(bundleName: string): string[];
101
92
  getLanguagePackageEnum<K extends keyof ILanguageBundleAccessor>(
102
- bundleName: K
93
+ bundleName: K,
103
94
  ): ILanguageBundleAccessor[K];
104
95
  initializeLanguage(language: string);
105
96
  };
@@ -159,32 +150,32 @@ declare namespace FW {
159
150
  createObjectPool<T extends FWObject = FWObject>(
160
151
  node: cc.Node,
161
152
  parent: cc.Node,
162
- tag?: string
153
+ tag?: string,
163
154
  ): Promise<ObjectPool<T>>;
164
155
  createObjectPool<T extends FWObject = FWObject>(
165
156
  prefab: cc.Prefab,
166
157
  parent: cc.Node,
167
- tag?: string
158
+ tag?: string,
168
159
  ): Promise<ObjectPool<T>>;
169
160
  createObjectPool<T extends FWObject = FWObject>(
170
161
  assetProperty: FW.AssetProperty,
171
162
  parent: cc.Node,
172
- tag?: string
163
+ tag?: string,
173
164
  ): Promise<ObjectPool<T>>;
174
165
  createObjectPool<T extends FWObject = FWObject>(
175
166
  node: cc.Node,
176
167
  parent: cc.Node,
177
- type?: number
168
+ type?: number,
178
169
  ): Promise<ObjectPool<T>>;
179
170
  createObjectPool<T extends FWObject = FWObject>(
180
171
  prefab: cc.Prefab,
181
172
  parent: cc.Node,
182
- type?: number
173
+ type?: number,
183
174
  ): Promise<ObjectPool<T>>;
184
175
  createObjectPool<T extends FWObject = FWObject>(
185
176
  assetProperty: FW.AssetProperty,
186
177
  parent: cc.Node,
187
- type?: number
178
+ type?: number,
188
179
  ): Promise<ObjectPool<T>>;
189
180
  /** 获取已经创建的对象池 */
190
181
  getObjectPool(tag: string): ObjectPool;
@@ -217,7 +208,7 @@ declare namespace FW {
217
208
  address: string,
218
209
  sender: SocketSender,
219
210
  handle: SocketHandle,
220
- config: SocketConfig
211
+ config: SocketConfig,
221
212
  ): Promise<Socket>;
222
213
  /**
223
214
  * 获取socket
@@ -313,7 +304,7 @@ declare namespace FW {
313
304
  tag: string,
314
305
  sender: SocketSender,
315
306
  handle: SocketHandle,
316
- config: SocketConfig
307
+ config: SocketConfig,
317
308
  ): SocketPromiseProxy;
318
309
  };
319
310
 
@@ -348,7 +339,7 @@ declare namespace FW {
348
339
  args7?: FW.EventManagerArgs,
349
340
  args8?: FW.EventManagerArgs,
350
341
  args9?: FW.EventManagerArgs,
351
- args10?: FW.EventManagerArgs
342
+ args10?: FW.EventManagerArgs,
352
343
  );
353
344
  /**
354
345
  * 比较目标
@@ -409,35 +400,19 @@ declare namespace FW {
409
400
  /**
410
401
  * 一次性调度器
411
402
  */
412
- scheduleOnce(
413
- cb?: () => void,
414
- time?: number,
415
- tag?: string
416
- ): FW.TimerSchedule;
403
+ scheduleOnce(cb?: () => void, time?: number, tag?: string): FW.TimerSchedule;
417
404
  /**
418
405
  * 一次性调度器
419
406
  */
420
- scheduleOnce(
421
- time?: number,
422
- cb?: () => void,
423
- tag?: string
424
- ): FW.TimerSchedule;
407
+ scheduleOnce(time?: number, cb?: () => void, tag?: string): FW.TimerSchedule;
425
408
  /**
426
409
  * 一次性调度器
427
410
  */
428
- scheduleOnce(
429
- time?: number,
430
- cb?: () => void,
431
- target?: any
432
- ): FW.TimerSchedule;
411
+ scheduleOnce(time?: number, cb?: () => void, target?: any): FW.TimerSchedule;
433
412
  /**
434
413
  * 一次性调度器
435
414
  */
436
- scheduleOnce(
437
- cb?: () => void,
438
- time?: number,
439
- target?: any
440
- ): FW.TimerSchedule;
415
+ scheduleOnce(cb?: () => void, time?: number, target?: any): FW.TimerSchedule;
441
416
  /**
442
417
  * 自定义调度器
443
418
  * */
@@ -446,7 +421,7 @@ declare namespace FW {
446
421
  time?: number,
447
422
  repeat?: number,
448
423
  target?: TargetType,
449
- tag?: string
424
+ tag?: string,
450
425
  ): TimerSchedule;
451
426
  /** 暂停调度器 */
452
427
  pauseSchedule(tag: string): void;
@@ -497,13 +472,13 @@ declare namespace FW {
497
472
  args7?: EventManagerArgs,
498
473
  args8?: EventManagerArgs,
499
474
  args9?: EventManagerArgs,
500
- args10?: EventManagerArgs
475
+ args10?: EventManagerArgs,
501
476
  ) => void,
502
477
  target: TargetType,
503
478
  options?: {
504
479
  priority?: FWSystemDefine.FWPriorityOrder;
505
480
  intercept?: boolean;
506
- }
481
+ },
507
482
  );
508
483
 
509
484
  registerOnce(
@@ -518,13 +493,13 @@ declare namespace FW {
518
493
  args7?: EventManagerArgs,
519
494
  args8?: EventManagerArgs,
520
495
  args9?: EventManagerArgs,
521
- args10?: EventManagerArgs
496
+ args10?: EventManagerArgs,
522
497
  ) => void,
523
498
  target: TargetType,
524
499
  options?: {
525
500
  priority?: number;
526
501
  intercept?: boolean;
527
- }
502
+ },
528
503
  ): void;
529
504
 
530
505
  /**
@@ -558,7 +533,7 @@ declare namespace FW {
558
533
  args7?: FW.EventManagerArgs,
559
534
  args8?: FW.EventManagerArgs,
560
535
  args9?: FW.EventManagerArgs,
561
- args10?: FW.EventManagerArgs
536
+ args10?: FW.EventManagerArgs,
562
537
  ): void;
563
538
  /**
564
539
  * 注销事件
@@ -704,23 +679,19 @@ declare namespace FW {
704
679
  * @param data
705
680
  */
706
681
  openAsync<Ctr extends FWLayerController = FWLayerController>(
707
- data: LayerOpenArgs<Ctr>
682
+ data: LayerOpenArgs<Ctr>,
708
683
  ): Promise<Ctr>;
709
684
 
710
685
  /**
711
686
  * 同步打开layer
712
687
  * @param data
713
688
  */
714
- openSync<Ctr extends FWLayerController = FWLayerController>(
715
- data: LayerOpenArgs<Ctr>
716
- ): Ctr;
689
+ openSync<Ctr extends FWLayerController = FWLayerController>(data: LayerOpenArgs<Ctr>): Ctr;
717
690
  /**
718
691
  * 显示常驻layer
719
692
  * @param layer
720
693
  */
721
- displayLayer<Ctr extends FWLayerController = FWLayerController>(
722
- ctr: Ctr
723
- ): Ctr;
694
+ displayLayer<Ctr extends FWLayerController = FWLayerController>(ctr: Ctr): Ctr;
724
695
  /**
725
696
  * 隐藏常驻layer
726
697
  * @param layer
@@ -730,9 +701,7 @@ declare namespace FW {
730
701
  * 关闭layer
731
702
  * @param layer
732
703
  */
733
- close<Ctr extends FWLayerController = FWLayerController>(
734
- ctr: Ctr
735
- ): FWLayerController;
704
+ close<Ctr extends FWLayerController = FWLayerController>(ctr: Ctr): FWLayerController;
736
705
 
737
706
  /**
738
707
  * 从栈关闭
@@ -801,8 +770,6 @@ declare namespace FW {
801
770
  };
802
771
 
803
772
  type ResManager = {
804
- assetMgr: AssetManager;
805
- bundleMgr: BundleManager;
806
773
  initialize(): void;
807
774
  onDestroy(): void;
808
775
 
@@ -840,10 +807,7 @@ declare namespace FW {
840
807
  * @param url
841
808
  * @param cb
842
809
  */
843
- loadRemote<T extends cc.Asset = cc.Asset>(
844
- url: string,
845
- cb?: (asset: cc.Asset) => T
846
- ): Promise<T>;
810
+ loadRemote<T extends cc.Asset = cc.Asset>(url: string, cb?: (asset: cc.Asset) => T): Promise<T>;
847
811
  /**
848
812
  * 从远程加载spine动画
849
813
  * @param data
@@ -859,18 +823,13 @@ declare namespace FW {
859
823
  * 加载资源返回数据
860
824
  * @param assetProperty
861
825
  */
862
- loadAssetData<T extends cc.Asset>(
863
- assetProperty: AssetProperty
864
- ): Promise<AssetData>;
826
+ loadAssetData<T extends cc.Asset>(assetProperty: AssetProperty): Promise<AssetData>;
865
827
 
866
828
  /**
867
829
  * 加载资源
868
830
  * @param assetProperty
869
831
  */
870
- loadAsset<T extends cc.Asset>(
871
- assetProperty: AssetProperty,
872
- cb?: () => void
873
- ): Promise<T>;
832
+ loadAsset<T extends cc.Asset>(assetProperty: AssetProperty, cb?: () => void): Promise<T>;
874
833
 
875
834
  /**
876
835
  * 获取资源
@@ -1018,10 +977,7 @@ declare namespace FW {
1018
977
  * @param url
1019
978
  * @param cb
1020
979
  */
1021
- loadRemote<T extends cc.Asset = cc.Asset>(
1022
- url: string,
1023
- cb?: (asset: cc.Asset) => T
1024
- ): Promise<T>;
980
+ loadRemote<T extends cc.Asset = cc.Asset>(url: string, cb?: (asset: cc.Asset) => T): Promise<T>;
1025
981
  /**
1026
982
  * 从远程加载spine动画
1027
983
  * @param data
@@ -1137,7 +1093,7 @@ declare namespace FW {
1137
1093
  referenceNode: cc.Node,
1138
1094
  type?: {
1139
1095
  prototype: T;
1140
- }
1096
+ },
1141
1097
  ): T;
1142
1098
  registerEvent(args: RegisterArgs): void;
1143
1099
  unRegisterEvent(args: RegisterArgs);
@@ -1314,7 +1270,7 @@ declare namespace FW {
1314
1270
  */
1315
1271
  register(
1316
1272
  state: FW.StateMachineRegisterArgs | FW.StateMachineRegisterArgs[],
1317
- stateMachineName?: string
1273
+ stateMachineName?: string,
1318
1274
  );
1319
1275
  /**
1320
1276
  * 注销指定状态机的某个状态
@@ -1370,22 +1326,22 @@ declare namespace FW {
1370
1326
  progress: Function;
1371
1327
  easing: Function | String;
1372
1328
  onUpdate: Function;
1373
- }>
1329
+ }>,
1374
1330
  >(
1375
1331
  duration: number,
1376
1332
  props: ConstructorType<T>,
1377
- opts?: OPTS
1333
+ opts?: OPTS,
1378
1334
  ): FW.Tween;
1379
1335
  by<
1380
1336
  OPTS extends Partial<{
1381
1337
  progress: Function;
1382
1338
  easing: Function | String;
1383
1339
  onUpdate: Function;
1384
- }>
1340
+ }>,
1385
1341
  >(
1386
1342
  duration: number,
1387
1343
  props: ConstructorType<T>,
1388
- opts?: OPTS
1344
+ opts?: OPTS,
1389
1345
  ): FW.Tween;
1390
1346
  set(props: ConstructorType<T>): FW.Tween;
1391
1347
  };
@@ -1630,11 +1586,7 @@ declare namespace FW {
1630
1586
  * @param volume
1631
1587
  * @param loop
1632
1588
  */
1633
- playMusic(
1634
- assetProperty: AssetProperty,
1635
- volume?: number,
1636
- loop?: boolean
1637
- ): void;
1589
+ playMusic(assetProperty: AssetProperty, volume?: number, loop?: boolean): void;
1638
1590
  /**
1639
1591
  * 停止背景音乐
1640
1592
  */
@@ -1663,36 +1615,21 @@ declare namespace FW {
1663
1615
  * @param volume
1664
1616
  * @param loop
1665
1617
  */
1666
- play(
1667
- path: string,
1668
- cb?: (id: number) => void,
1669
- volume?: number,
1670
- loop?: boolean
1671
- );
1618
+ play(path: string, cb?: (id: number) => void, volume?: number, loop?: boolean);
1672
1619
  /**
1673
1620
  * 播放音效
1674
1621
  * @param audio
1675
1622
  * @param volume
1676
1623
  * @param loop
1677
1624
  */
1678
- play(
1679
- audio: cc.AudioClip,
1680
- cb?: (id: number) => void,
1681
- volume?: number,
1682
- loop?: boolean
1683
- );
1625
+ play(audio: cc.AudioClip, cb?: (id: number) => void, volume?: number, loop?: boolean);
1684
1626
  /**
1685
1627
  * 播放音效
1686
1628
  * @param assetProperty
1687
1629
  * @param volume
1688
1630
  * @param loop
1689
1631
  */
1690
- play(
1691
- assetProperty: AssetProperty,
1692
- cb?: (id: number) => void,
1693
- volume?: number,
1694
- loop?: boolean
1695
- );
1632
+ play(assetProperty: AssetProperty, cb?: (id: number) => void, volume?: number, loop?: boolean);
1696
1633
  /**
1697
1634
  * 暂停所有
1698
1635
  */
@@ -1713,11 +1650,7 @@ declare namespace FW {
1713
1650
  };
1714
1651
 
1715
1652
  type PerformanceManager = {
1716
- recordOperationMetric(
1717
- manager: string,
1718
- operation: string,
1719
- duration: number
1720
- ): void;
1653
+ recordOperationMetric(manager: string, operation: string, duration: number): void;
1721
1654
  getModuleReport(manager: string): PerformanceReport;
1722
1655
  getAllReports(): Map<string, FW.PerformanceReport>;
1723
1656
  };
@@ -2016,7 +1949,7 @@ declare namespace FW {
2016
1949
  abort?: (reason?: any) => void;
2017
1950
  addAbortEventListener?: (
2018
1951
  listener: (this: AbortSignal, ev: Event) => any,
2019
- options?: boolean | AddEventListenerOptions
1952
+ options?: boolean | AddEventListenerOptions,
2020
1953
  ) => void;
2021
1954
  };
2022
1955
 
@@ -2024,7 +1957,7 @@ declare namespace FW {
2024
1957
  resolve: (value: T | PromiseLike<T>) => void,
2025
1958
  reject: (reason?: any) => void,
2026
1959
  signal: AbortSignal,
2027
- reason?: any
1960
+ reason?: any,
2028
1961
  ) => void;
2029
1962
 
2030
1963
  type PromiseExecuteOptions = {
@@ -2035,10 +1968,7 @@ declare namespace FW {
2035
1968
  retryCondition?: (error: any, retryCount: number) => boolean;
2036
1969
  };
2037
1970
 
2038
- type Promise = (
2039
- resolve: (value: any) => void,
2040
- reject: (reason?: any) => void
2041
- ) => void;
1971
+ type Promise = (resolve: (value: any) => void, reject: (reason?: any) => void) => void;
2042
1972
 
2043
1973
  type PromiseResult<T = any> = {
2044
1974
  success: PromiseProxy<T>[];
@@ -2046,7 +1976,7 @@ declare namespace FW {
2046
1976
  cancelled: number[];
2047
1977
  };
2048
1978
 
2049
- type PromiseStatus = "pending" | "fulfilled" | "rejected" | "cancelled";
1979
+ type PromiseStatus = 'pending' | 'fulfilled' | 'rejected' | 'cancelled';
2050
1980
 
2051
1981
  /**
2052
1982
  * 性能管理器配置
@@ -11,13 +11,13 @@ export namespace FWSystemConfig {
11
11
 
12
12
  export const PromiseConfig = {
13
13
  loadAsset: {
14
- retryCount: 3,
15
- retryInterval: 5,
14
+ retryCount: 0,
15
+ retryInterval: 0,
16
16
  timeout: 10,
17
17
  },
18
18
  loadBundle: {
19
- retryCount: 3,
20
- retryInterval: 5,
19
+ retryCount: 0,
20
+ retryInterval: 0,
21
21
  timeout: 10,
22
22
  },
23
23
  http: {
@@ -1,6 +1,6 @@
1
- import { FWSystemConfig } from "../config/FWSystemConfig";
2
- import FWLog from "../log/FWLog";
3
- import { FWManager } from "./FWManager";
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 ? ".bin" : ".txt";
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["textureNames"] = [`${img}.png`];
64
- asset["_uuid"] = ske;
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("从远程加载spine动画资源失败!");
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
- url,
84
- { cacheEnabled: true, maxRetryCount: 3 },
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 || "preload failed!");
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 await this.invoke(
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["_uuid"];
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["_uuid"];
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 "../define/FWSystemDefine";
2
- import FWLog from "../log/FWLog";
3
- import { FWManager } from "./FWManager";
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("promise abort");
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("abort", onAbort);
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("abort", onAbort);
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
- if (
108
- promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING
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 || "promise cancelled");
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("abort", listener, options);
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("abort", onAbort);
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("abort", onAbort);
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("abort", onAbort);
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 || "all promise cancelled");
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("abort", listener, options);
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
 
@@ -1,21 +1,19 @@
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";
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
- `loadBundleDepend -> ${bundleName}`
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
  }
@@ -1,6 +1,6 @@
1
- import { searchChild } from "../expand/FWDecorator";
2
- import FWLog from "../log/FWLog";
3
- import { FWManager } from "./FWManager";
1
+ import { searchChild } from '../expand/FWDecorator';
2
+ import FWLog from '../log/FWLog';
3
+ import { FWManager } from './FWManager';
4
4
 
5
5
  export default class FWUiManager extends FWManager implements FW.UiManager {
6
6
  private eventMap: Map<
@@ -113,7 +113,7 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
113
113
 
114
114
  register(args: FW.RegisterArgs) {
115
115
  if (!args.target) {
116
- FWLog.error("注册事件失败,目标为空!");
116
+ FWLog.error('注册事件失败,目标为空!');
117
117
  return;
118
118
  }
119
119
 
@@ -131,11 +131,7 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
131
131
 
132
132
  if (!evt.enable) return;
133
133
 
134
- /** 检测触发间隔 */
135
- if (
136
- Date.now() - evt.lastResponseTimestamp <
137
- evt.responseInterval
138
- ) {
134
+ if (Date.now() - evt.lastResponseTimestamp < evt.responseInterval) {
139
135
  return;
140
136
  }
141
137
 
@@ -143,9 +139,9 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
143
139
  if (button && !button.interactable) return;
144
140
 
145
141
  evt.lastResponseTimestamp = Date.now();
146
- evt.cb?.bind(args.target)?.(e, c);
142
+ evt.cb?.bind(args.target)?.(e, c, evt.data);
147
143
  },
148
- args.target
144
+ args.target,
149
145
  );
150
146
  this.eventMap.set(this.uniqueId, {
151
147
  uniqueId: this.uniqueId,
@@ -168,12 +164,9 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
168
164
  args7?: FW.EventManagerArgs,
169
165
  args8?: FW.EventManagerArgs,
170
166
  args9?: FW.EventManagerArgs,
171
- args10?: FW.EventManagerArgs
167
+ args10?: FW.EventManagerArgs,
172
168
  ) => {
173
- if (
174
- Date.now() - evt.lastResponseTimestamp <
175
- (evt.responseInterval || 0)
176
- ) {
169
+ if (Date.now() - evt.lastResponseTimestamp < (evt.responseInterval || 0)) {
177
170
  return;
178
171
  }
179
172
  evt.lastResponseTimestamp = Date.now();
@@ -187,10 +180,10 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
187
180
  args7,
188
181
  args8,
189
182
  args9,
190
- args10
183
+ args10,
191
184
  );
192
185
  },
193
- args.target
186
+ args.target,
194
187
  );
195
188
 
196
189
  this.eventMap.set(this.uniqueId, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": ["123456"],
@@ -1,7 +1,7 @@
1
- import { FWSystemConfig } from "../../config/FWSystemConfig";
2
- import { FWSystemDefine } from "../../define/FWSystemDefine";
3
- import FWLog from "../../log/FWLog";
4
- import FWService from "../FWService";
1
+ import { FWSystemConfig } from '../../config/FWSystemConfig';
2
+ import { FWSystemDefine } from '../../define/FWSystemDefine';
3
+ import FWLog from '../../log/FWLog';
4
+ import FWService from '../FWService';
5
5
 
6
6
  export default class FWHttp extends FWService {
7
7
  public initialize() {}
@@ -12,30 +12,18 @@ export default class FWHttp extends FWService {
12
12
  url: string,
13
13
  params?: string,
14
14
  cb?: (response: string) => void,
15
- tag?: string
15
+ tag?: string,
16
16
  ): Promise<string> {
17
- return this.process(
18
- url,
19
- params,
20
- cb,
21
- tag,
22
- FWSystemDefine.FWHttpRequestType.GET
23
- );
17
+ return this.process(url, params, cb, tag, FWSystemDefine.FWHttpRequestType.GET);
24
18
  }
25
19
 
26
20
  protected async postMessage(
27
21
  url: string,
28
22
  params?: string,
29
23
  cb?: (response: string) => void,
30
- tag?: string
24
+ tag?: string,
31
25
  ): Promise<string> {
32
- return this.process(
33
- url,
34
- params,
35
- cb,
36
- tag,
37
- FWSystemDefine.FWHttpRequestType.POST
38
- );
26
+ return this.process(url, params, cb, tag, FWSystemDefine.FWHttpRequestType.POST);
39
27
  }
40
28
 
41
29
  private async process(
@@ -43,56 +31,48 @@ export default class FWHttp extends FWService {
43
31
  params: string,
44
32
  cb: (response: any) => void,
45
33
  tag: string,
46
- type: FWSystemDefine.FWHttpRequestType
34
+ type: FWSystemDefine.FWHttpRequestType,
47
35
  ): Promise<string> {
48
36
  let xhr: XMLHttpRequest;
49
37
 
50
- const promiseProxy: FW.PromiseProxy<string> =
51
- FW.Entry.promiseMgr.execute<string>(
52
- (resolve, reject, signal, reason) => {
53
- xhr = new XMLHttpRequest();
38
+ const promiseProxy: FW.PromiseProxy<string> = FW.Entry.promiseMgr.execute<string>(
39
+ (resolve, reject, signal, reason) => {
40
+ xhr = new XMLHttpRequest();
54
41
 
55
- xhr.onreadystatechange = () => {
56
- if (xhr.readyState == 4 && xhr.status === 200) {
57
- cb?.(xhr.response);
58
- resolve(xhr.response);
59
- }
60
- };
42
+ xhr.onreadystatechange = () => {
43
+ if (xhr.readyState == 4 && xhr.status === 200) {
44
+ cb?.(xhr.response);
45
+ resolve(xhr.response);
46
+ }
47
+ };
61
48
 
62
- xhr.onerror = (err: any) => {
63
- FWLog.error(err);
64
- this.onError?.(err);
65
- reject(`http request error:${err}`);
66
- };
49
+ xhr.onerror = (err: any) => {
50
+ FWLog.error(err);
51
+ this.onError?.(err);
52
+ reject(`http request error:${err}`);
53
+ };
67
54
 
68
- xhr.ontimeout = () => {
69
- this.onTimeout?.();
70
- reject(`http request timeout!`);
71
- };
55
+ xhr.ontimeout = () => {
56
+ this.onTimeout?.();
57
+ reject(`http request timeout!`);
58
+ };
72
59
 
73
- xhr.open(type, url, true);
74
- xhr.send(params);
60
+ xhr.open(type, url, true);
61
+ xhr.send(params);
62
+ },
63
+ {
64
+ ...FWSystemConfig.PromiseConfig.http,
65
+ retryCondition(error, retryCount) {
66
+ return error || xhr.readyState != 4 || (xhr.status !== 200 && retryCount < 3);
75
67
  },
76
- {
77
- ...FWSystemConfig.PromiseConfig.http,
78
- retryCondition(error, retryCount) {
79
- return (
80
- error ||
81
- xhr.readyState != 4 ||
82
- (xhr.status !== 200 && retryCount < 3)
83
- );
84
- },
85
- }
86
- );
68
+ },
69
+ );
87
70
 
88
71
  promiseProxy.addAbortEventListener(() => {
89
72
  xhr.abort();
90
73
  });
91
74
 
92
- return await this.invoke(
93
- promiseProxy.promise,
94
- tag ? `http request ->${tag}` : ""
95
- );
75
+ return await this.invoke(promiseProxy.promise, tag ? `http request ->${tag}` : '');
96
76
  }
97
77
 
98
78
  onError?(err: any);