@ives_xxz/framework 1.6.5 → 2.0.0

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.
Files changed (58) hide show
  1. package/Framework.ts +9 -13
  2. package/FrameworkAutoInitialize.ts +58 -0
  3. package/{CC.d.ts.meta → FrameworkAutoInitialize.ts.meta} +1 -1
  4. package/FrameworkBase.ts +24 -23
  5. package/animation/FWSkeleton.ts +5 -6
  6. package/component/FWVirtualViewComponent.ts +42 -45
  7. package/config/FWAssetConfig.ts +2 -2
  8. package/controller/FWLayerController.ts +3 -7
  9. package/data/FWData.ts +2 -3
  10. package/define/FWEventDefine.ts +24 -21
  11. package/define/FWSystemDefine.ts +127 -132
  12. package/define/FWSystemDefine.ts.meta +1 -1
  13. package/entry/FWEntry.ts +2 -3
  14. package/expand/FWDecorator.ts +56 -114
  15. package/expand/FWRollingViewNesting.ts +3 -5
  16. package/item/FWVirtualListItem.ts +1 -1
  17. package/language/FWLanguage.ts +15 -19
  18. package/layer/FWLayer.ts +1 -1
  19. package/log/FWLog.ts +30 -35
  20. package/logic/FWLogic.ts +2 -4
  21. package/machine/FWStateMachine.ts +1 -2
  22. package/manager/FWAnimationManager.ts +6 -8
  23. package/manager/FWAssetManager.ts +22 -23
  24. package/manager/FWAudioManager.ts +30 -52
  25. package/manager/FWBundleManager.ts +2 -4
  26. package/manager/FWComponentManager.ts +0 -1
  27. package/manager/FWEngineManager.ts +10 -14
  28. package/manager/FWEventManager.ts +4 -7
  29. package/manager/FWHotUpdateManager.ts +32 -33
  30. package/manager/FWLanguageManager.ts +1 -2
  31. package/manager/FWLayerManager.ts +88 -138
  32. package/manager/FWManager.ts +1 -3
  33. package/manager/FWObjectManager.ts +7 -9
  34. package/manager/FWPerformanceManager.ts +2 -3
  35. package/manager/FWPromiseManager.ts +29 -28
  36. package/manager/FWResManager.ts +1 -3
  37. package/manager/FWSocketManager.ts +2 -5
  38. package/manager/FWStateManager.ts +2 -4
  39. package/manager/FWTimeManager.ts +14 -15
  40. package/manager/FWUiManager.ts +3 -4
  41. package/package.json +1 -1
  42. package/{register → registry}/FWRegistry.ts +8 -8
  43. package/service/http/FWHttp.ts +5 -7
  44. package/service/socket/FWSocket.ts +28 -43
  45. package/service/socket/FWSocketHandle.ts +3 -6
  46. package/service/socket/FWSocketSender.ts +5 -9
  47. package/types/Creator.d.ts.meta +6 -0
  48. package/{FW.d.ts → types/FW.d.ts} +407 -153
  49. package/types/Global.d.ts +21 -0
  50. package/{render/FWAssembler.ts.meta → types/Global.d.ts.meta} +1 -1
  51. package/types.meta +13 -0
  52. package/utils/FWObjectPool.ts +5 -7
  53. package/utils/FWTask.ts +18 -22
  54. package/render/FWAssembler.ts +0 -11
  55. /package/{register → registry}/FWRegistry.ts.meta +0 -0
  56. /package/{register.meta → registry.meta} +0 -0
  57. /package/{CC.d.ts → types/Creator.d.ts} +0 -0
  58. /package/{FW.d.ts.meta → types/FW.d.ts.meta} +0 -0
@@ -1,5 +1,3 @@
1
- import { FWSystemDefine } from '../define/FWSystemDefine';
2
- import FWLog from '../log/FWLog';
3
1
  import { FWManager } from './FWManager';
4
2
 
5
3
  export default class FWPromiseManager extends FWManager implements FW.PromiseManager {
@@ -37,7 +35,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
37
35
  (!options.retryCondition || options.retryCondition(timeoutError, retryCount))
38
36
  ) {
39
37
  retryCount++;
40
- FWLog.debug(`Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`);
38
+ FW.Log.debug(`Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`);
41
39
  if (retryInterval > 0) {
42
40
  FW.Entry.timeMgr.scheduleOnce(() => {
43
41
  createPromise().then(resolve, reject);
@@ -53,10 +51,10 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
53
51
  }
54
52
 
55
53
  const onAbort = () => {
56
- FWLog.debug('promise abort');
54
+ FW.Log.debug('promise abort');
57
55
  timerSchedule?.unSchedule();
58
- if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
59
- promiseProxy.status = FWSystemDefine.FWPromiseStatus.CANCELLED;
56
+ if (promiseProxy.status === FW.SystemDefine.FWPromiseStatus.PENDING) {
57
+ promiseProxy.status = FW.SystemDefine.FWPromiseStatus.CANCELLED;
60
58
  this.removePromise(id);
61
59
  }
62
60
  };
@@ -69,7 +67,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
69
67
  abortController.signal.addEventListener('abort', onAbort);
70
68
 
71
69
  const wrappedResolve = (value: T | PromiseLike<T>) => {
72
- promiseProxy.status = FWSystemDefine.FWPromiseStatus.FULFILLED;
70
+ promiseProxy.status = FW.SystemDefine.FWPromiseStatus.FULFILLED;
73
71
  abortController.signal.removeEventListener('abort', onAbort);
74
72
  this.removePromise(id);
75
73
  timerSchedule?.unSchedule();
@@ -83,7 +81,10 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
83
81
  (!options.retryCondition || options.retryCondition(reason, retryCount))
84
82
  ) {
85
83
  retryCount++;
86
- FWLog.debug(`Promise ${id} failed, retrying (${retryCount}/${maxRetryTimes}):`, reason);
84
+ FW.Log.debug(
85
+ `Promise ${id} failed, retrying (${retryCount}/${maxRetryTimes}):`,
86
+ reason,
87
+ );
87
88
  if (retryInterval > 0) {
88
89
  FW.Entry.timeMgr.scheduleOnce(() => {
89
90
  createPromise().then(resolve, reject);
@@ -108,11 +109,11 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
108
109
  const promiseProxy: FW.PromiseProxy<T> = {
109
110
  id,
110
111
  promise,
111
- status: FWSystemDefine.FWPromiseStatus.PENDING,
112
+ status: FW.SystemDefine.FWPromiseStatus.PENDING,
112
113
  abortController,
113
114
  abort: (reason?: any) => {
114
- if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
115
- FWLog.debug(reason || 'promise cancelled');
115
+ if (promiseProxy.status === FW.SystemDefine.FWPromiseStatus.PENDING) {
116
+ FW.Log.debug(reason || 'promise cancelled');
116
117
  abortController.abort(reason);
117
118
  }
118
119
  },
@@ -151,7 +152,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
151
152
  (!options.retryCondition || options.retryCondition(timeoutError, retryCount))
152
153
  ) {
153
154
  retryCount++;
154
- FWLog.debug(`All Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`);
155
+ FW.Log.debug(`All Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`);
155
156
  if (retryInterval > 0) {
156
157
  FW.Entry.timeMgr.scheduleOnce(() => {
157
158
  createPromise().then(resolve, reject);
@@ -168,8 +169,8 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
168
169
 
169
170
  const onAbort = () => {
170
171
  timerSchedule?.unSchedule();
171
- if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
172
- promiseProxy.status = FWSystemDefine.FWPromiseStatus.CANCELLED;
172
+ if (promiseProxy.status === FW.SystemDefine.FWPromiseStatus.PENDING) {
173
+ promiseProxy.status = FW.SystemDefine.FWPromiseStatus.CANCELLED;
173
174
  this.removePromise(id);
174
175
  }
175
176
  };
@@ -206,7 +207,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
206
207
  const value = await promiseProxy.promise;
207
208
  result.success.push(value);
208
209
  } catch (error) {
209
- if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.CANCELLED) {
210
+ if (promiseProxy.status === FW.SystemDefine.FWPromiseStatus.CANCELLED) {
210
211
  result.cancelled.push(promiseProxy.id);
211
212
  } else {
212
213
  result.failed.push({
@@ -222,7 +223,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
222
223
 
223
224
  processAll()
224
225
  .then((result) => {
225
- promiseProxy.status = FWSystemDefine.FWPromiseStatus.FULFILLED;
226
+ promiseProxy.status = FW.SystemDefine.FWPromiseStatus.FULFILLED;
226
227
  abortController.signal.removeEventListener('abort', onAbort);
227
228
  this.removePromise(id);
228
229
  timerSchedule?.unSchedule();
@@ -235,7 +236,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
235
236
  (!options.retryCondition || options.retryCondition(error, retryCount))
236
237
  ) {
237
238
  retryCount++;
238
- FWLog.debug(
239
+ FW.Log.debug(
239
240
  `All Promise ${id} failed, retrying (${retryCount}/${maxRetryTimes}):`,
240
241
  error,
241
242
  );
@@ -247,8 +248,8 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
247
248
  createPromise().then(resolve, reject);
248
249
  }
249
250
  } else {
250
- if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
251
- promiseProxy.status = FWSystemDefine.FWPromiseStatus.REJECTED;
251
+ if (promiseProxy.status === FW.SystemDefine.FWPromiseStatus.PENDING) {
252
+ promiseProxy.status = FW.SystemDefine.FWPromiseStatus.REJECTED;
252
253
  abortController.signal.removeEventListener('abort', onAbort);
253
254
  this.removePromise(id);
254
255
  reject(error);
@@ -262,11 +263,11 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
262
263
  const promiseProxy: FW.PromiseProxy<FW.PromiseResult<T>> = {
263
264
  id,
264
265
  promise,
265
- status: FWSystemDefine.FWPromiseStatus.PENDING,
266
+ status: FW.SystemDefine.FWPromiseStatus.PENDING,
266
267
  abortController,
267
268
  abort: (reason?: any) => {
268
- if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
269
- FWLog.debug(reason || 'all promise cancelled');
269
+ if (promiseProxy.status === FW.SystemDefine.FWPromiseStatus.PENDING) {
270
+ FW.Log.debug(reason || 'all promise cancelled');
270
271
  abortController.abort(reason);
271
272
  }
272
273
  },
@@ -285,7 +286,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
285
286
  /** 取消指定Promise */
286
287
  public cancel(id: number, reason?: any): boolean {
287
288
  const promiseProxy = this.promiseRegistry.get(id);
288
- if (promiseProxy && promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
289
+ if (promiseProxy && promiseProxy.status === FW.SystemDefine.FWPromiseStatus.PENDING) {
289
290
  promiseProxy.abort(reason);
290
291
  return true;
291
292
  }
@@ -314,14 +315,14 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
314
315
  }
315
316
 
316
317
  /** 获取Promise状态 */
317
- public getStatus(id: number): FWSystemDefine.FWPromiseStatus | null {
318
+ public getStatus(id: number): FW.SystemDefine.FWPromiseStatus | null {
318
319
  const promiseProxy = this.promiseRegistry.get(id);
319
320
  return promiseProxy ? promiseProxy.status : null;
320
321
  }
321
322
 
322
323
  /** 获取所有Promise状态 */
323
- public getAllStatus(): Map<number, FWSystemDefine.FWPromiseStatus> {
324
- const statusMap = new Map<number, FWSystemDefine.FWPromiseStatus>();
324
+ public getAllStatus(): Map<number, FW.SystemDefine.FWPromiseStatus> {
325
+ const statusMap = new Map<number, FW.SystemDefine.FWPromiseStatus>();
325
326
  this.promiseRegistry.forEach((promiseProxy, id) => {
326
327
  statusMap.set(id, promiseProxy.status);
327
328
  });
@@ -336,7 +337,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
336
337
  /** 获取正在执行的Promise数量 */
337
338
  public getActiveCount(): number {
338
339
  return Array.from(this.promiseRegistry.values()).filter(
339
- (p) => p.status === FWSystemDefine.FWPromiseStatus.PENDING,
340
+ (p) => p.status === FW.SystemDefine.FWPromiseStatus.PENDING,
340
341
  ).length;
341
342
  }
342
343
 
@@ -345,7 +346,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
345
346
  const completedIds: number[] = [];
346
347
 
347
348
  this.promiseRegistry.forEach((promiseProxy, id) => {
348
- if (promiseProxy.status !== FWSystemDefine.FWPromiseStatus.PENDING) {
349
+ if (promiseProxy.status !== FW.SystemDefine.FWPromiseStatus.PENDING) {
349
350
  completedIds.push(id);
350
351
  }
351
352
  });
@@ -1,7 +1,5 @@
1
1
  import FWAssetConfig from '../config/FWAssetConfig';
2
2
  import { FWSystemConfig } from '../config/FWSystemConfig';
3
- import { FWSystemDefine } from '../define/FWSystemDefine';
4
- import FWLog from '../log/FWLog';
5
3
  import { FWLodash } from '../utils/FWLodash';
6
4
  import { FWAssetManager } from './FWAssetManager';
7
5
  import { FWBundleManager } from './FWBundleManager';
@@ -34,7 +32,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
34
32
  await this.loadBundle(depend);
35
33
 
36
34
  const config = FW.Entry.getComponent<FWAssetConfig>(
37
- `${depend}${FWSystemDefine.FWBindTag.CONFIG}`,
35
+ `${depend}${FW.SystemDefine.FWBindTag.CONFIG}`,
38
36
  );
39
37
  if (!config) continue;
40
38
  const preLoad = config.preLoad;
@@ -1,7 +1,4 @@
1
- import FWLog from '../log/FWLog';
2
1
  import FWSocket from '../service/socket/FWSocket';
3
- import FWSocketHandle from '../service/socket/FWSocketHandle';
4
- import FWSocketSender from '../service/socket/FWSocketSender';
5
2
  import { FWManager } from './FWManager';
6
3
 
7
4
  /**
@@ -13,7 +10,7 @@ export default class FWSocketManager extends FWManager implements FW.SocketManag
13
10
  public initialize(): void {
14
11
  this.socketMap = new Map<string, FW.Socket>();
15
12
  }
16
- public onDestroy(): void { }
13
+ public onDestroy(): void {}
17
14
 
18
15
  /**
19
16
  * 创建一个socket
@@ -82,7 +79,7 @@ export default class FWSocketManager extends FWManager implements FW.SocketManag
82
79
  * @returns
83
80
  */
84
81
  closeSocket(fs: FWSocket) {
85
- FWLog.debug('主动关闭socket!');
82
+ FW.Log.debug('主动关闭socket!');
86
83
  const tag = fs.getTag();
87
84
  fs.socket.close();
88
85
  fs.socket = null;
@@ -1,6 +1,4 @@
1
1
  import { FWManager } from './FWManager';
2
- import Framework from '../Framework';
3
- import FWLog from '../log/FWLog';
4
2
  import FWStateMachine from '../machine/FWStateMachine';
5
3
 
6
4
  export class FWStateManager extends FWManager implements FW.StateManager {
@@ -23,7 +21,7 @@ export class FWStateManager extends FWManager implements FW.StateManager {
23
21
  stateMachineName = stateMachineName || FW.Entry.bundleName;
24
22
 
25
23
  if (!this.stateMap.has(stateMachineName)) {
26
- FWLog.warn('stateMachine is not register!');
24
+ FW.Log.warn('stateMachine is not register!');
27
25
  return;
28
26
  }
29
27
  const machine = this.stateMap.get(stateMachineName);
@@ -42,7 +40,7 @@ export class FWStateManager extends FWManager implements FW.StateManager {
42
40
  unRegister(stateType: number, stateMachineName?: string) {
43
41
  stateMachineName = stateMachineName || FW.Entry.bundleName;
44
42
  if (!this.stateMap.has(stateMachineName)) {
45
- FWLog.warn('stateMachine is not register!');
43
+ FW.Log.warn('stateMachine is not register!');
46
44
  return;
47
45
  }
48
46
  this.stateMap.get(stateMachineName).unRegister(stateType);
@@ -1,5 +1,4 @@
1
- import FWLog from "../log/FWLog";
2
- import { FWManager } from "./FWManager";
1
+ import { FWManager } from './FWManager';
3
2
 
4
3
  class FWTimer implements FW.Timer {
5
4
  constructor() {
@@ -70,13 +69,13 @@ export class FWTimeManager extends FWManager implements FW.TimeManager {
70
69
  time?: number,
71
70
  repeat?: number,
72
71
  target?: FW.TargetType,
73
- tag?: string
72
+ tag?: string,
74
73
  ): FW.TimerSchedule {
75
74
  const timer = new FWTimer();
76
75
 
77
76
  timer.internal = time || 0;
78
77
  timer.repeat = repeat || 0;
79
- timer.tag = tag || "";
78
+ timer.tag = tag || '';
80
79
  timer.target = target || FW.Entry.scene;
81
80
  timer.cb = cb;
82
81
  timer.id = this.uniqueId++;
@@ -135,11 +134,11 @@ export class FWTimeManager extends FWManager implements FW.TimeManager {
135
134
  let target: any;
136
135
 
137
136
  for (const arg of arguments) {
138
- if (typeof arg === "function") {
137
+ if (typeof arg === 'function') {
139
138
  cb = arg;
140
- } else if (typeof arg === "number") {
139
+ } else if (typeof arg === 'number') {
141
140
  time = arg;
142
- } else if (typeof arg === "string") {
141
+ } else if (typeof arg === 'string') {
143
142
  tag = arg;
144
143
  } else if (arg) {
145
144
  target = arg;
@@ -193,9 +192,9 @@ export class FWTimeManager extends FWManager implements FW.TimeManager {
193
192
  const args = arguments;
194
193
  if (!args || args?.length == 0) return;
195
194
 
196
- if (typeof args[0] == "string") {
195
+ if (typeof args[0] == 'string') {
197
196
  this.removeTimerFromTag(args[0]);
198
- } else if (typeof args[0] == "number") {
197
+ } else if (typeof args[0] == 'number') {
199
198
  this.removeTimerFromId(args[0]);
200
199
  } else {
201
200
  this.removeTimerFromTarget(args[0]);
@@ -224,9 +223,9 @@ export class FWTimeManager extends FWManager implements FW.TimeManager {
224
223
  pauseSchedule() {
225
224
  const args = arguments;
226
225
  if (!args || args?.length == 0) return;
227
- if (typeof args[0] == "string") {
226
+ if (typeof args[0] == 'string') {
228
227
  this.pauseTimerFromTag(args[0], true);
229
- } else if (typeof args[0] == "number") {
228
+ } else if (typeof args[0] == 'number') {
230
229
  this.pauseTimerFromId(args[0], true);
231
230
  } else {
232
231
  this.pauseTimerFromTarget(args[0], true);
@@ -254,9 +253,9 @@ export class FWTimeManager extends FWManager implements FW.TimeManager {
254
253
  resumeSchedule() {
255
254
  const args = arguments;
256
255
  if (!args || args?.length == 0) return;
257
- if (typeof args[0] == "string") {
256
+ if (typeof args[0] == 'string') {
258
257
  this.pauseTimerFromTag(args[0], false);
259
- } else if (typeof args[0] == "number") {
258
+ } else if (typeof args[0] == 'number') {
260
259
  this.pauseTimerFromId(args[0], false);
261
260
  } else {
262
261
  this.pauseTimerFromTarget(args[0], false);
@@ -297,7 +296,7 @@ export class FWTimeManager extends FWManager implements FW.TimeManager {
297
296
  var target: FW.TargetType;
298
297
  var tag: string;
299
298
  if (args.length == 2) {
300
- if (typeof args[1] == "string") {
299
+ if (typeof args[1] == 'string') {
301
300
  tag = args[1];
302
301
  } else {
303
302
  target = args[1];
@@ -311,7 +310,7 @@ export class FWTimeManager extends FWManager implements FW.TimeManager {
311
310
  timer.cb = cb;
312
311
  timer.executeTime = 0;
313
312
  timer.internal = 0;
314
- timer.tag = tag || "";
313
+ timer.tag = tag || '';
315
314
  timer.target = target || undefined;
316
315
  timer.pause = false;
317
316
  timer.repeat = cc.macro.REPEAT_FOREVER;
@@ -1,5 +1,4 @@
1
1
  import { searchChild } from '../expand/FWDecorator';
2
- import FWLog from '../log/FWLog';
3
2
  import { FWManager } from './FWManager';
4
3
 
5
4
  export default class FWUiManager extends FWManager implements FW.UiManager {
@@ -71,14 +70,14 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
71
70
 
72
71
  find(path: string, rootNode: cc.Node): cc.Node | null {
73
72
  if (!cc.isValid(rootNode)) {
74
- FWLog.error(`查找节点失败: ${path}, 根节点无效`);
73
+ FW.Log.error(`查找节点失败: ${path}, 根节点无效`);
75
74
  return null;
76
75
  }
77
76
 
78
77
  const node = searchChild(rootNode, path);
79
78
 
80
79
  if (!cc.isValid(node)) {
81
- FWLog.warn(`未找到节点: ${path}`);
80
+ FW.Log.warn(`未找到节点: ${path}`);
82
81
  return null;
83
82
  }
84
83
 
@@ -113,7 +112,7 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
113
112
 
114
113
  register(args: FW.RegisterArgs) {
115
114
  if (!args.target) {
116
- FWLog.error('注册事件失败,目标为空!');
115
+ FW.Log.error('注册事件失败,目标为空!');
117
116
  return;
118
117
  }
119
118
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "1.6.5",
3
+ "version": "2.0.0",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": ["123456"],
@@ -1,7 +1,7 @@
1
1
  import { injectable } from 'inversify';
2
2
 
3
3
  @injectable()
4
- export default abstract class FWRegistry implements FW.Registry {
4
+ export abstract class FWRegistry implements FW.Registry {
5
5
  /**
6
6
  * bundle名字
7
7
  */
@@ -9,15 +9,15 @@ export default abstract class FWRegistry implements FW.Registry {
9
9
  /**
10
10
  * 是否自动释放
11
11
  */
12
- protected readonly autoRelease?: boolean;
12
+ readonly autoRelease?: boolean;
13
13
  /**
14
14
  * 场景名字
15
15
  */
16
- protected readonly sceneName?: string;
16
+ readonly sceneName?: string;
17
17
  /**
18
18
  * 依赖
19
19
  */
20
- protected readonly depend?: string[];
20
+ readonly depend?: string[];
21
21
  /**
22
22
  * 逻辑
23
23
  */
@@ -29,15 +29,15 @@ export default abstract class FWRegistry implements FW.Registry {
29
29
  /**
30
30
  * 资源配置
31
31
  */
32
- readonly config?: FW.Newable<FW.Config>;
32
+ readonly config?: FW.Newable<FW.AssetConfig>;
33
33
  /**
34
34
  * socket发送者
35
35
  */
36
- readonly sender?: FW.Newable<FW.SocketSender>;
36
+ readonly sender?: FW.Newable<FW.Sender>;
37
37
  /**
38
38
  * socket处理者
39
39
  */
40
- readonly handle?: FW.Newable<FW.SocketHandle>;
40
+ readonly handle?: FW.Newable<FW.Handle>;
41
41
 
42
42
  register(): void {
43
43
  this.bundleEnabled(true);
@@ -46,7 +46,7 @@ export default abstract class FWRegistry implements FW.Registry {
46
46
  this.bundleEnabled(false);
47
47
  }
48
48
 
49
- private bundleEnabled(enable?: boolean) {
49
+ bundleEnabled(enable?: boolean) {
50
50
  const frameworkInvoke = enable ? FW.Framework.register : FW.Framework.unRegister;
51
51
  const entryInvoke = enable ? FW.Entry.register : FW.Entry.unRegister;
52
52
  frameworkInvoke.bind(FW.Framework)({
@@ -1,6 +1,4 @@
1
1
  import { FWSystemConfig } from '../../config/FWSystemConfig';
2
- import { FWSystemDefine } from '../../define/FWSystemDefine';
3
- import FWLog from '../../log/FWLog';
4
2
  import FWService from '../FWService';
5
3
 
6
4
  export default class FWHttp extends FWService {
@@ -14,7 +12,7 @@ export default class FWHttp extends FWService {
14
12
  cb?: (response: string) => void,
15
13
  tag?: string,
16
14
  ): Promise<string> {
17
- return this.process(url, params, cb, tag, FWSystemDefine.FWHttpRequestType.GET);
15
+ return this.process(url, params, cb, tag, FW.SystemDefine.FWHttpRequestType.GET);
18
16
  }
19
17
 
20
18
  protected async postMessage(
@@ -23,7 +21,7 @@ export default class FWHttp extends FWService {
23
21
  cb?: (response: string) => void,
24
22
  tag?: string,
25
23
  ): Promise<string> {
26
- return this.process(url, params, cb, tag, FWSystemDefine.FWHttpRequestType.POST);
24
+ return this.process(url, params, cb, tag, FW.SystemDefine.FWHttpRequestType.POST);
27
25
  }
28
26
 
29
27
  private async process(
@@ -31,7 +29,7 @@ export default class FWHttp extends FWService {
31
29
  params: string,
32
30
  cb: (response: any) => void,
33
31
  tag: string,
34
- type: FWSystemDefine.FWHttpRequestType,
32
+ type: FW.SystemDefine.FWHttpRequestType,
35
33
  ): Promise<string> {
36
34
  let xhr: XMLHttpRequest;
37
35
 
@@ -47,7 +45,7 @@ export default class FWHttp extends FWService {
47
45
  };
48
46
 
49
47
  xhr.onerror = (err: any) => {
50
- FWLog.error(err);
48
+ FW.Log.error(err);
51
49
  this.onError?.(err);
52
50
  reject(`http request error:${err}`);
53
51
  };
@@ -57,7 +55,7 @@ export default class FWHttp extends FWService {
57
55
  reject(`http request timeout!`);
58
56
  };
59
57
 
60
- xhr.open(type, url, true);
58
+ xhr.open(type as string, url, true);
61
59
  xhr.send(params);
62
60
  },
63
61
  {
@@ -1,6 +1,5 @@
1
- import { FWSystemConfig } from "../../config/FWSystemConfig";
2
- import FWLog from "../../log/FWLog";
3
- import FWService from "../FWService";
1
+ import { FWSystemConfig } from '../../config/FWSystemConfig';
2
+ import FWService from '../FWService';
4
3
 
5
4
  /**
6
5
  * TODO 犹豫socket没有改版暂时已老的cmd字符串映射方式做,后期优化
@@ -65,7 +64,7 @@ export default class FWSocket extends FWService implements FW.Socket {
65
64
  tag: string,
66
65
  socketSender: FW.SocketSender,
67
66
  socketHandle: FW.SocketHandle,
68
- config: FW.SocketConfig
67
+ config: FW.SocketConfig,
69
68
  ): FW.SocketPromiseProxy {
70
69
  try {
71
70
  FW.Entry.timeMgr.unSchedule(this);
@@ -109,14 +108,10 @@ export default class FWSocket extends FWService implements FW.Socket {
109
108
  this.heartInternal = config?.heartInternal || defaultConfig.heartInternal;
110
109
  this.heartTimeout = config?.heartTimeout || defaultConfig.heartTimeout;
111
110
  this.heartWeakTime = config?.heartWeakTime || defaultConfig.heartWeakTime;
112
- this.maxReconnectTimes =
113
- config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
114
- this.reconnectInternal =
115
- config?.reconnectInternal || defaultConfig.reconnectInternal;
116
- this.protocolSymbol =
117
- config?.protocolSymbol || defaultConfig.protocolSymbol;
118
- this.protocolPollingTime =
119
- config?.protocolPollingTime || defaultConfig.protocolPollingTime;
111
+ this.maxReconnectTimes = config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
112
+ this.reconnectInternal = config?.reconnectInternal || defaultConfig.reconnectInternal;
113
+ this.protocolSymbol = config?.protocolSymbol || defaultConfig.protocolSymbol;
114
+ this.protocolPollingTime = config?.protocolPollingTime || defaultConfig.protocolPollingTime;
120
115
 
121
116
  this.promiseProxy = {
122
117
  promise: undefined,
@@ -130,7 +125,7 @@ export default class FWSocket extends FWService implements FW.Socket {
130
125
 
131
126
  return this.promiseProxy;
132
127
  } catch (e) {
133
- FWLog.error("创建socket失败:", e);
128
+ FW.Log.error('创建socket失败:', e);
134
129
  }
135
130
  }
136
131
  /**
@@ -195,8 +190,8 @@ export default class FWSocket extends FWService implements FW.Socket {
195
190
  reconnect(force?: boolean) {
196
191
  if (force) this.reconnectTimes = 0;
197
192
 
198
- FWLog.debug(
199
- `socket reconnect : reconnectTimes->${this.reconnectTimes},maxReconnectTimes->${this.maxReconnectTimes}`
193
+ FW.Log.debug(
194
+ `socket reconnect : reconnectTimes->${this.reconnectTimes},maxReconnectTimes->${this.maxReconnectTimes}`,
200
195
  );
201
196
  if (++this.reconnectTimes >= this.maxReconnectTimes) {
202
197
  this.socketHandle?.onTimeout?.();
@@ -207,22 +202,16 @@ export default class FWSocket extends FWService implements FW.Socket {
207
202
  this.socket?.close();
208
203
  this.socket = null;
209
204
 
210
- this.createSocket(
211
- this.address,
212
- this.tag,
213
- this.socketSender,
214
- this.socketHandle,
215
- {
216
- heartInternal: this.heartInternal,
217
- heartTimeout: this.heartTimeout,
218
- heartWeakTime: this.heartWeakTime,
219
- maxReconnectTimes: this.maxReconnectTimes,
220
- reconnectInternal: this.reconnectInternal,
221
- protocolSymbol: this.protocolSymbol,
222
- protocolPollingTime: this.protocolPollingTime,
223
- certificate: this.certificate,
224
- }
225
- );
205
+ this.createSocket(this.address, this.tag, this.socketSender, this.socketHandle, {
206
+ heartInternal: this.heartInternal,
207
+ heartTimeout: this.heartTimeout,
208
+ heartWeakTime: this.heartWeakTime,
209
+ maxReconnectTimes: this.maxReconnectTimes,
210
+ reconnectInternal: this.reconnectInternal,
211
+ protocolSymbol: this.protocolSymbol,
212
+ protocolPollingTime: this.protocolPollingTime,
213
+ certificate: this.certificate,
214
+ });
226
215
  }
227
216
 
228
217
  async send(msg: string) {
@@ -232,8 +221,7 @@ export default class FWSocket extends FWService implements FW.Socket {
232
221
  const protocolKey = this.socketSender.getProtocolKey?.(msg);
233
222
  if (protocolKey) {
234
223
  const symbol = Symbol(protocolKey);
235
- const registry =
236
- this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
224
+ const registry = this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
237
225
  const protocolPolling: FW.ProtocolPolling = {
238
226
  msg: msg,
239
227
  schedule: FW.Entry.timeMgr.schedule(
@@ -242,7 +230,7 @@ export default class FWSocket extends FWService implements FW.Socket {
242
230
  },
243
231
  this.protocolPollingTime,
244
232
  cc.macro.REPEAT_FOREVER,
245
- this
233
+ this,
246
234
  ),
247
235
  };
248
236
  this.protocolRegistry.set(protocolKey, registry.add(symbol));
@@ -254,7 +242,7 @@ export default class FWSocket extends FWService implements FW.Socket {
254
242
 
255
243
  /** 连接打开 */
256
244
  private onSocketOpen() {
257
- FWLog.debug("on open!");
245
+ FW.Log.debug('on open!');
258
246
  FW.Entry.timeMgr.unSchedule(this);
259
247
  this.reconnectTimes = 0;
260
248
  this.sendHeartTimestamp = 0;
@@ -279,7 +267,7 @@ export default class FWSocket extends FWService implements FW.Socket {
279
267
  },
280
268
  this.heartInternal / 1000,
281
269
  cc.macro.REPEAT_FOREVER,
282
- this
270
+ this,
283
271
  );
284
272
  }
285
273
 
@@ -298,20 +286,17 @@ export default class FWSocket extends FWService implements FW.Socket {
298
286
 
299
287
  /** socket关闭 */
300
288
  private onSocketClose() {
301
- FWLog.debug("on close!");
289
+ FW.Log.debug('on close!');
302
290
  this.socketHandle?.onClose?.();
303
291
  FW.Entry.timeMgr.scheduleOnce(
304
292
  () => {
305
- if (
306
- this.getReadyState() == WebSocket.CLOSING ||
307
- this.getReadyState() == WebSocket.CLOSED
308
- ) {
309
- FWLog.debug("on close!");
293
+ if (this.getReadyState() == WebSocket.CLOSING || this.getReadyState() == WebSocket.CLOSED) {
294
+ FW.Log.debug('on close!');
310
295
  this.reconnect();
311
296
  }
312
297
  },
313
298
  this.reconnectInternal,
314
- this
299
+ this,
315
300
  );
316
301
  }
317
302
 
@@ -1,10 +1,7 @@
1
- import { injectable } from "inversify";
2
- import { FrameworkBase } from "../../FrameworkBase";
1
+ import { injectable } from 'inversify';
2
+ import { FrameworkBase } from '../../FrameworkBase';
3
3
  @injectable()
4
- export default abstract class FWSocketHandle
5
- extends FrameworkBase
6
- implements FW.SocketHandle
7
- {
4
+ export abstract class FWSocketHandle extends FrameworkBase {
8
5
  initialize?();
9
6
  onDestroy?();
10
7
  onWeakNetWork?(): void;
@@ -1,15 +1,11 @@
1
- import { injectable } from "inversify";
2
- import FWLog from "../../log/FWLog";
3
- import { FrameworkBase } from "../../FrameworkBase";
1
+ import { injectable } from 'inversify';
2
+ import { FrameworkBase } from '../../FrameworkBase';
4
3
  @injectable()
5
- export default abstract class FWSocketSender
6
- extends FrameworkBase
7
- implements FW.SocketSender
8
- {
4
+ export abstract class FWSocketSender extends FrameworkBase {
9
5
  initialize?();
10
6
  onDestroy?();
11
- abstract sendHeart();
12
- abstract onHeart?(msg: any): Promise<boolean>;
7
+ sendHeart?();
8
+ onHeart?(msg: any): Promise<boolean>;
13
9
  abstract onBeforeSendingMessage?(msg: any): Promise<FW.SocketMessage>;
14
10
  abstract getProtocolKey?(msg: any): string;
15
11
  send(msg: any) {