@ives_xxz/framework 1.5.5 → 1.5.8
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 +129 -56
- package/Framework.ts +64 -24
- package/FrameworkBase.ts +58 -26
- package/controller/FWLayerController.ts +17 -12
- package/data/FWData.ts +3 -5
- package/logic/FWLogic.ts +4 -6
- package/manager/FWLayerManager.ts +124 -69
- package/manager/FWPromiseManager.ts +69 -38
- package/manager/FWTaskManager.ts +2 -2
- package/package.json +4 -2
- package/service/FWService.ts +2 -4
- package/service/socket/FWSocket.ts +44 -33
- package/service/socket/FWSocketHandle.ts +14 -14
- package/service/socket/FWSocketSender.ts +11 -12
package/FrameworkBase.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { injectable } from
|
|
2
|
-
import { FWEventDefine } from
|
|
3
|
-
import FWLog from
|
|
4
|
-
import { FWSystemDefine } from
|
|
5
|
-
import Framework from
|
|
6
|
-
import FWLogic from
|
|
7
|
-
import FWData from
|
|
1
|
+
import { injectable } from "inversify";
|
|
2
|
+
import { FWEventDefine } from "./define/FWEventDefine";
|
|
3
|
+
import FWLog from "./log/FWLog";
|
|
4
|
+
import { FWSystemDefine } from "./define/FWSystemDefine";
|
|
5
|
+
import Framework from "./Framework";
|
|
6
|
+
import FWLogic from "./logic/FWLogic";
|
|
7
|
+
import FWData from "./data/FWData";
|
|
8
8
|
@injectable()
|
|
9
9
|
export abstract class FrameworkBase {
|
|
10
10
|
public readonly entry: FW.Entry = FW.Entry;
|
|
@@ -13,13 +13,18 @@ export abstract class FrameworkBase {
|
|
|
13
13
|
public config?: FW.Config;
|
|
14
14
|
public sender?: FW.SocketSender;
|
|
15
15
|
public handle?: FW.SocketHandle;
|
|
16
|
+
private dependenciesInjected: boolean = false;
|
|
17
|
+
private isInitialized: boolean = false;
|
|
16
18
|
protected abstract initialize?(): void;
|
|
17
19
|
protected abstract onDestroy?(): void;
|
|
18
20
|
protected onRestart?(): void;
|
|
19
|
-
|
|
20
21
|
constructor() {
|
|
21
22
|
this.initialize?.();
|
|
22
|
-
this.entry.evtMgr.register(
|
|
23
|
+
this.entry.evtMgr.register(
|
|
24
|
+
FWEventDefine.SystemEvent.SYSTEM_RESTART,
|
|
25
|
+
this.onRestart,
|
|
26
|
+
this
|
|
27
|
+
);
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
protected get moduleName(): string {
|
|
@@ -46,7 +51,12 @@ export abstract class FrameworkBase {
|
|
|
46
51
|
return this.config as T;
|
|
47
52
|
}
|
|
48
53
|
|
|
49
|
-
|
|
54
|
+
public initializeDependencies(): void {
|
|
55
|
+
if (this.dependenciesInjected || this.isInitialized) return;
|
|
56
|
+
|
|
57
|
+
this.dependenciesInjected = true;
|
|
58
|
+
this.isInitialized = true;
|
|
59
|
+
|
|
50
60
|
const bundleName = this.findBundleNameByClassName();
|
|
51
61
|
if (!bundleName) return;
|
|
52
62
|
|
|
@@ -54,36 +64,46 @@ export abstract class FrameworkBase {
|
|
|
54
64
|
|
|
55
65
|
if (tag !== FWSystemDefine.FWBindTag.LOGIC) {
|
|
56
66
|
this.logic = Framework.getComponent<FW.Logic>(
|
|
57
|
-
`${bundleName}${FWSystemDefine.FWBindTag.LOGIC}
|
|
67
|
+
`${bundleName}${FWSystemDefine.FWBindTag.LOGIC}`
|
|
58
68
|
);
|
|
59
69
|
}
|
|
60
70
|
|
|
61
71
|
if (tag !== FWSystemDefine.FWBindTag.DATA) {
|
|
62
|
-
this.data = Framework.getComponent<FW.Data>(
|
|
72
|
+
this.data = Framework.getComponent<FW.Data>(
|
|
73
|
+
`${bundleName}${FWSystemDefine.FWBindTag.DATA}`
|
|
74
|
+
);
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
if (tag !== FWSystemDefine.FWBindTag.CONFIG) {
|
|
66
78
|
this.config = Framework.getComponent<FW.Config>(
|
|
67
|
-
`${bundleName}${FWSystemDefine.FWBindTag.CONFIG}
|
|
79
|
+
`${bundleName}${FWSystemDefine.FWBindTag.CONFIG}`
|
|
68
80
|
);
|
|
69
81
|
}
|
|
70
82
|
|
|
71
83
|
if (tag !== FWSystemDefine.FWBindTag.SENDER) {
|
|
72
84
|
this.sender = Framework.getComponent<FW.SocketSender>(
|
|
73
|
-
`${bundleName}${FWSystemDefine.FWBindTag.SENDER}
|
|
85
|
+
`${bundleName}${FWSystemDefine.FWBindTag.SENDER}`
|
|
74
86
|
);
|
|
75
87
|
}
|
|
76
88
|
|
|
77
89
|
if (tag !== FWSystemDefine.FWBindTag.HANDLE) {
|
|
78
90
|
this.handle = Framework.getComponent<FW.SocketHandle>(
|
|
79
|
-
`${bundleName}${FWSystemDefine.FWBindTag.HANDLE}
|
|
91
|
+
`${bundleName}${FWSystemDefine.FWBindTag.HANDLE}`
|
|
80
92
|
);
|
|
81
93
|
}
|
|
82
94
|
|
|
83
|
-
|
|
95
|
+
// 调用子类的 initialize 方法
|
|
96
|
+
this.initialize?.();
|
|
97
|
+
|
|
98
|
+
FWLog.debug(
|
|
99
|
+
`[${this.moduleName}] Dependencies setup for bundle: ${bundleName}`
|
|
100
|
+
);
|
|
84
101
|
}
|
|
85
102
|
|
|
86
|
-
protected async invoke<T>(
|
|
103
|
+
protected async invoke<T>(
|
|
104
|
+
operation: Promise<T>,
|
|
105
|
+
operationName: string = "unknown"
|
|
106
|
+
): Promise<T> {
|
|
87
107
|
const startTime = this.getCurrentTime();
|
|
88
108
|
|
|
89
109
|
try {
|
|
@@ -97,16 +117,25 @@ export abstract class FrameworkBase {
|
|
|
97
117
|
}
|
|
98
118
|
}
|
|
99
119
|
|
|
100
|
-
private recordPerformanceMetric(
|
|
120
|
+
private recordPerformanceMetric(
|
|
121
|
+
operationName: string,
|
|
122
|
+
duration: number
|
|
123
|
+
): void {
|
|
101
124
|
if (FW.Entry.performanceMgr) {
|
|
102
|
-
FW.Entry.performanceMgr.recordOperationMetric(
|
|
125
|
+
FW.Entry.performanceMgr.recordOperationMetric(
|
|
126
|
+
this.moduleName,
|
|
127
|
+
operationName,
|
|
128
|
+
duration
|
|
129
|
+
);
|
|
103
130
|
}
|
|
104
131
|
|
|
105
132
|
const shouldWarn = duration > 1000;
|
|
106
133
|
|
|
107
134
|
if (FW.Entry.engineMgr.debug || shouldWarn) {
|
|
108
135
|
const log = shouldWarn ? FWLog.warn : FWLog.debug;
|
|
109
|
-
log(
|
|
136
|
+
log(
|
|
137
|
+
`[${this.moduleName?.toUpperCase()}] Operation ${operationName} took ${duration}ms`
|
|
138
|
+
);
|
|
110
139
|
}
|
|
111
140
|
}
|
|
112
141
|
|
|
@@ -139,7 +168,10 @@ export abstract class FrameworkBase {
|
|
|
139
168
|
return undefined;
|
|
140
169
|
}
|
|
141
170
|
|
|
142
|
-
private doesClassNameContainBundleName(
|
|
171
|
+
private doesClassNameContainBundleName(
|
|
172
|
+
className: string,
|
|
173
|
+
bundleName: string
|
|
174
|
+
): boolean {
|
|
143
175
|
const bundleNameLower = bundleName.toLowerCase();
|
|
144
176
|
const classNameLower = className.toLowerCase();
|
|
145
177
|
return classNameLower.includes(bundleNameLower);
|
|
@@ -147,13 +179,13 @@ export abstract class FrameworkBase {
|
|
|
147
179
|
|
|
148
180
|
private getClassTag(): FWSystemDefine.FWBindTag {
|
|
149
181
|
const className = this.moduleName;
|
|
150
|
-
if (className.endsWith(
|
|
151
|
-
if (className.endsWith(
|
|
152
|
-
if (className.endsWith(
|
|
182
|
+
if (className.endsWith("Logic")) return FWSystemDefine.FWBindTag.LOGIC;
|
|
183
|
+
if (className.endsWith("Data")) return FWSystemDefine.FWBindTag.DATA;
|
|
184
|
+
if (className.endsWith("Config") || className.endsWith("AssetConfig"))
|
|
153
185
|
return FWSystemDefine.FWBindTag.CONFIG;
|
|
154
|
-
if (className.endsWith(
|
|
186
|
+
if (className.endsWith("Sender") || className.endsWith("SocketSender"))
|
|
155
187
|
return FWSystemDefine.FWBindTag.SENDER;
|
|
156
|
-
if (className.endsWith(
|
|
188
|
+
if (className.endsWith("Handle") || className.endsWith("SocketHandle"))
|
|
157
189
|
return FWSystemDefine.FWBindTag.HANDLE;
|
|
158
190
|
return;
|
|
159
191
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { FWSystemDefine } from
|
|
2
|
-
import FWLayer from
|
|
3
|
-
import { FWLayerData } from
|
|
4
|
-
import FWLog from
|
|
5
|
-
import { FrameworkBase } from
|
|
6
|
-
export abstract class FWLayerController
|
|
1
|
+
import { FWSystemDefine } from "../define/FWSystemDefine";
|
|
2
|
+
import FWLayer from "../layer/FWLayer";
|
|
3
|
+
import { FWLayerData } from "../manager/FWLayerManager";
|
|
4
|
+
import FWLog from "../log/FWLog";
|
|
5
|
+
import { FrameworkBase } from "../FrameworkBase";
|
|
6
|
+
export abstract class FWLayerController
|
|
7
|
+
extends FrameworkBase
|
|
8
|
+
implements FW.LayerController
|
|
9
|
+
{
|
|
7
10
|
readonly entry: FW.Entry = FW.Entry;
|
|
8
11
|
/** layer数据 */
|
|
9
12
|
layerData: FWLayerData;
|
|
@@ -34,9 +37,7 @@ export abstract class FWLayerController extends FrameworkBase implements FW.Laye
|
|
|
34
37
|
onEnable?();
|
|
35
38
|
onDisable?();
|
|
36
39
|
onDestroy?();
|
|
37
|
-
initialize() {
|
|
38
|
-
this.dependencies();
|
|
39
|
-
}
|
|
40
|
+
initialize() {}
|
|
40
41
|
async onClose?();
|
|
41
42
|
|
|
42
43
|
async destroy() {
|
|
@@ -88,16 +89,20 @@ export abstract class FWLayerController extends FrameworkBase implements FW.Laye
|
|
|
88
89
|
referenceNode: cc.Node,
|
|
89
90
|
type?: {
|
|
90
91
|
prototype: T;
|
|
91
|
-
}
|
|
92
|
+
}
|
|
92
93
|
) {
|
|
93
94
|
return this.find(path, referenceNode)?.getComponent<T>(type);
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
getComponentsInChildren<T extends cc.Component = cc.Component>(type: {
|
|
97
|
+
getComponentsInChildren<T extends cc.Component = cc.Component>(type: {
|
|
98
|
+
prototype: T;
|
|
99
|
+
}) {
|
|
97
100
|
return this.layer.getComponentsInChildren(type);
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
getComponentInChildren<T extends cc.Component = cc.Component>(type: {
|
|
103
|
+
getComponentInChildren<T extends cc.Component = cc.Component>(type: {
|
|
104
|
+
prototype: T;
|
|
105
|
+
}) {
|
|
101
106
|
return this.layer.getComponentInChildren(type);
|
|
102
107
|
}
|
|
103
108
|
|
package/data/FWData.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { injectable } from
|
|
2
|
-
import { FrameworkBase } from
|
|
1
|
+
import { injectable } from "inversify";
|
|
2
|
+
import { FrameworkBase } from "../FrameworkBase";
|
|
3
3
|
@injectable()
|
|
4
4
|
export default class FWData extends FrameworkBase implements FW.Data {
|
|
5
|
-
public initialize()
|
|
6
|
-
this.dependencies();
|
|
7
|
-
}
|
|
5
|
+
public initialize?(): void;
|
|
8
6
|
public onDestroy?(): void;
|
|
9
7
|
}
|
package/logic/FWLogic.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { injectable } from
|
|
2
|
-
import { FrameworkBase } from
|
|
3
|
-
import { FWSystemDefine } from
|
|
1
|
+
import { injectable } from "inversify";
|
|
2
|
+
import { FrameworkBase } from "../FrameworkBase";
|
|
3
|
+
import { FWSystemDefine } from "../define/FWSystemDefine";
|
|
4
4
|
@injectable()
|
|
5
5
|
export default class FWLogic extends FrameworkBase implements FW.Logic {
|
|
6
|
-
public initialize()
|
|
7
|
-
this.dependencies();
|
|
8
|
-
}
|
|
6
|
+
public initialize?(): void;
|
|
9
7
|
public onDestroy?(): void;
|
|
10
8
|
}
|