@ives_xxz/framework 1.3.9 → 1.4.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.
- package/FW.d.ts +15 -7
- package/Framework.ts +50 -4
- package/entry/FWEntry.ts +5 -3
- package/manager/FWBundleManager.ts +6 -0
- package/package.json +1 -1
- package/register/FWRegistry.ts +68 -0
- package/register/FWRegistry.ts.meta +10 -0
- package/register.meta +13 -0
- package/service/socket/FWSocketSender.ts +1 -1
package/FW.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ declare namespace FW {
|
|
|
40
40
|
getComponents<T>(serviceIdentifier?: FW.ServiceIdentifier<T>): T[];
|
|
41
41
|
launchScene(bundleName: string): void;
|
|
42
42
|
register(data: RegisterBundle): void;
|
|
43
|
+
unRegister(data: RegisterBundle): void;
|
|
43
44
|
getSceneName(bundleName: string): string;
|
|
44
45
|
getDepend(bundleName: string): string[];
|
|
45
46
|
update(dt: number): void;
|
|
@@ -47,6 +48,13 @@ declare namespace FW {
|
|
|
47
48
|
onDestroy(): void;
|
|
48
49
|
};
|
|
49
50
|
|
|
51
|
+
type Registry = {
|
|
52
|
+
/** 注册 */
|
|
53
|
+
register(): void;
|
|
54
|
+
/** 注销 */
|
|
55
|
+
unRegister(): void;
|
|
56
|
+
};
|
|
57
|
+
|
|
50
58
|
type LanguageManager = {
|
|
51
59
|
registerLanguagePackageEnum(
|
|
52
60
|
bundleName: string,
|
|
@@ -88,7 +96,7 @@ declare namespace FW {
|
|
|
88
96
|
/** 获取协议Key值 */
|
|
89
97
|
getProtocolKey?(msg: any): string;
|
|
90
98
|
/** 消息发送前回调函数*/
|
|
91
|
-
onBeforeSendingMessage?(msg: any):
|
|
99
|
+
onBeforeSendingMessage?(msg: any): Promise<FW.SocketMessage>;
|
|
92
100
|
/** 是否是心跳消息 */
|
|
93
101
|
onHeart?(msg: any): Promise<boolean>;
|
|
94
102
|
};
|
|
@@ -170,9 +178,9 @@ declare namespace FW {
|
|
|
170
178
|
};
|
|
171
179
|
|
|
172
180
|
type SocketMessage = {
|
|
173
|
-
data:any;
|
|
174
|
-
error:boolean;
|
|
175
|
-
}
|
|
181
|
+
data: any;
|
|
182
|
+
error: boolean;
|
|
183
|
+
};
|
|
176
184
|
|
|
177
185
|
type SocketManager = {
|
|
178
186
|
createSocket(
|
|
@@ -1180,9 +1188,9 @@ declare namespace FW {
|
|
|
1180
1188
|
};
|
|
1181
1189
|
|
|
1182
1190
|
type SocketMessage = {
|
|
1183
|
-
data:any;
|
|
1184
|
-
error:boolean;
|
|
1185
|
-
}
|
|
1191
|
+
data: any;
|
|
1192
|
+
error: boolean;
|
|
1193
|
+
};
|
|
1186
1194
|
|
|
1187
1195
|
type AnimationManager = {
|
|
1188
1196
|
initialize(): void;
|
package/Framework.ts
CHANGED
|
@@ -2,20 +2,21 @@ import 'reflect-metadata';
|
|
|
2
2
|
import { Container, interfaces } from 'inversify';
|
|
3
3
|
import { FWSystemDefine } from './define/FWSystemDefine';
|
|
4
4
|
import FWLog from './log/FWLog';
|
|
5
|
-
import { FWEventDefine } from './define/FWEventDefine';
|
|
6
5
|
|
|
7
6
|
class Framework {
|
|
8
7
|
private container: Container;
|
|
8
|
+
private registry: Map<string, new () => FW.Registry>;
|
|
9
9
|
private static instance: Framework;
|
|
10
|
-
private constructor() {
|
|
10
|
+
private constructor() {}
|
|
11
|
+
|
|
12
|
+
initialize() {
|
|
11
13
|
this.container = new Container({
|
|
12
14
|
defaultScope: 'Singleton',
|
|
13
15
|
autoBindInjectable: true,
|
|
14
16
|
});
|
|
17
|
+
this.registry = new Map<string, new () => FW.Registry>();
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
initialize() {}
|
|
18
|
-
|
|
19
20
|
public static getInstance() {
|
|
20
21
|
if (!this.instance) {
|
|
21
22
|
this.instance = new Framework();
|
|
@@ -89,6 +90,51 @@ class Framework {
|
|
|
89
90
|
return instances;
|
|
90
91
|
}
|
|
91
92
|
|
|
93
|
+
/**
|
|
94
|
+
* 是否已经注册注册表
|
|
95
|
+
* @param bundleName
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
hasRegistry(bundleName: string) {
|
|
99
|
+
return this.registry.has(bundleName);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 添加进注册表
|
|
104
|
+
* @param bundleName
|
|
105
|
+
* @param registry
|
|
106
|
+
*/
|
|
107
|
+
addRegistry(bundleName: string, registry: new () => FW.Registry) {
|
|
108
|
+
this.registry.set(bundleName, registry);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 获取注册表
|
|
113
|
+
* @param bundleName
|
|
114
|
+
*/
|
|
115
|
+
getRegistry(bundleName: string): FW.Registry {
|
|
116
|
+
return this.container.get(this.registry.get(bundleName));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 创建注册表
|
|
121
|
+
*/
|
|
122
|
+
createRegistry(bundleName: string): FW.Registry {
|
|
123
|
+
if (!this.registry.has(bundleName)) return;
|
|
124
|
+
this.container.bind(this.registry.get(bundleName)).toSelf().inSingletonScope();
|
|
125
|
+
return this.getRegistry(bundleName);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 销毁注册表
|
|
130
|
+
* @param bundleName
|
|
131
|
+
*/
|
|
132
|
+
destroyRegistry(bundleName: string) {
|
|
133
|
+
if (this.registry.has(bundleName)) return;
|
|
134
|
+
this.registry.delete(bundleName);
|
|
135
|
+
this.container.unbind(this.registry.get(bundleName));
|
|
136
|
+
}
|
|
137
|
+
|
|
92
138
|
/**
|
|
93
139
|
* 注册数据
|
|
94
140
|
* @param data
|
package/entry/FWEntry.ts
CHANGED
|
@@ -147,17 +147,19 @@ export default class FWEntry implements FW.Entry {
|
|
|
147
147
|
releaseBundle(bundleName: string) {
|
|
148
148
|
this.resMgr.releaseBundle(bundleName);
|
|
149
149
|
const depend = this.getDepend(bundleName);
|
|
150
|
-
for(const d of depend){
|
|
150
|
+
for (const d of depend) {
|
|
151
151
|
this.resMgr.releaseBundle(d);
|
|
152
|
-
this.evtMgr.dispatch(`${FWEventDefine.SystemEvent.BUNDLE_RELEASE}-${d}`);
|
|
153
152
|
}
|
|
154
|
-
this.evtMgr.dispatch(`${FWEventDefine.SystemEvent.BUNDLE_RELEASE}-${bundleName}`);
|
|
155
153
|
}
|
|
156
154
|
|
|
157
155
|
register(data: FW.RegisterBundle) {
|
|
158
156
|
this.map.set(data.bundleName, data);
|
|
159
157
|
}
|
|
160
158
|
|
|
159
|
+
unRegister(data: FW.RegisterBundle): void {
|
|
160
|
+
this.map.has(data?.bundleName) && this.map.delete(data?.bundleName);
|
|
161
|
+
}
|
|
162
|
+
|
|
161
163
|
bundleAutoRelease(bundleName: string) {
|
|
162
164
|
const autoRelease = this.map.get(bundleName)?.autoRelease;
|
|
163
165
|
return autoRelease === undefined ? true : autoRelease;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FWManager } from './FWManager';
|
|
2
2
|
import FWLog from '../log/FWLog';
|
|
3
|
+
import Framework from '../Framework';
|
|
3
4
|
|
|
4
5
|
export class FWBundleManager extends FWManager implements FW.BundleManager {
|
|
5
6
|
bundleMap: Map<string, cc.AssetManager.Bundle>;
|
|
@@ -47,6 +48,9 @@ export class FWBundleManager extends FWManager implements FW.BundleManager {
|
|
|
47
48
|
reject(err);
|
|
48
49
|
}
|
|
49
50
|
this.bundleMap.set(bundleName, bundle);
|
|
51
|
+
|
|
52
|
+
Framework.createRegistry(bundleName)?.register();
|
|
53
|
+
|
|
50
54
|
resolve(bundle);
|
|
51
55
|
},
|
|
52
56
|
);
|
|
@@ -74,6 +78,8 @@ export class FWBundleManager extends FWManager implements FW.BundleManager {
|
|
|
74
78
|
}
|
|
75
79
|
cc.assetManager.removeBundle(this.bundleMap.get(bundleName));
|
|
76
80
|
this.bundleMap.delete(bundleName);
|
|
81
|
+
Framework.getRegistry(bundleName)?.unRegister();
|
|
82
|
+
Framework.destroyRegistry(bundleName);
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
/**
|
package/package.json
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { injectable } from 'inversify';
|
|
2
|
+
import Framework from '../Framework';
|
|
3
|
+
|
|
4
|
+
@injectable()
|
|
5
|
+
export default abstract class FWRegistry implements FW.Registry {
|
|
6
|
+
/**
|
|
7
|
+
* bundle名字
|
|
8
|
+
*/
|
|
9
|
+
abstract readonly bundleName: string;
|
|
10
|
+
/**
|
|
11
|
+
* 是否自动释放
|
|
12
|
+
*/
|
|
13
|
+
protected readonly autoRelease?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 场景名字
|
|
16
|
+
*/
|
|
17
|
+
protected readonly sceneName?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 依赖
|
|
20
|
+
*/
|
|
21
|
+
protected readonly depend?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* 逻辑
|
|
24
|
+
*/
|
|
25
|
+
readonly logic?: FW.Newable<FW.Logic>;
|
|
26
|
+
/**
|
|
27
|
+
* 数据
|
|
28
|
+
*/
|
|
29
|
+
readonly data?: FW.Newable<FW.Data>;
|
|
30
|
+
/**
|
|
31
|
+
* 资源配置
|
|
32
|
+
*/
|
|
33
|
+
readonly config?: FW.Newable<FW.Config>;
|
|
34
|
+
/**
|
|
35
|
+
* socket发送者
|
|
36
|
+
*/
|
|
37
|
+
readonly sender?: FW.Newable<FW.SocketSender>;
|
|
38
|
+
/**
|
|
39
|
+
* socket处理者
|
|
40
|
+
*/
|
|
41
|
+
readonly handle?: FW.Newable<FW.SocketHandle>;
|
|
42
|
+
|
|
43
|
+
register(): void {
|
|
44
|
+
this.bundleEnabled(true);
|
|
45
|
+
}
|
|
46
|
+
unRegister(): void {
|
|
47
|
+
this.bundleEnabled(false);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private bundleEnabled(enable?: boolean) {
|
|
51
|
+
const frameworkInvoke = enable ? Framework.register : Framework.unRegister;
|
|
52
|
+
const entryInvoke = enable ? FW.Entry.register : FW.Entry.unRegister;
|
|
53
|
+
frameworkInvoke.bind(Framework)({
|
|
54
|
+
bundleName: this.bundleName,
|
|
55
|
+
logic: this.logic,
|
|
56
|
+
data: this.data,
|
|
57
|
+
config: this.config,
|
|
58
|
+
sender: this.sender,
|
|
59
|
+
handle: this.handle,
|
|
60
|
+
});
|
|
61
|
+
entryInvoke.bind(FW.Entry)({
|
|
62
|
+
bundleName: this.bundleName,
|
|
63
|
+
sceneName: this.sceneName,
|
|
64
|
+
autoRelease: this.autoRelease,
|
|
65
|
+
depend: this.depend,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
package/register.meta
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ver": "1.1.3",
|
|
3
|
+
"uuid": "f339a6ec-8f57-4d08-beb3-9527709af63d",
|
|
4
|
+
"importer": "folder",
|
|
5
|
+
"isBundle": false,
|
|
6
|
+
"bundleName": "",
|
|
7
|
+
"priority": 1,
|
|
8
|
+
"compressionType": {},
|
|
9
|
+
"optimizeHotUpdate": {},
|
|
10
|
+
"inlineSpriteFrames": {},
|
|
11
|
+
"isRemoteBundle": {},
|
|
12
|
+
"subMetas": {}
|
|
13
|
+
}
|
|
@@ -10,7 +10,7 @@ export default class FWSocketSender implements FW.SocketSender {
|
|
|
10
10
|
onDestroy?();
|
|
11
11
|
sendHeart?();
|
|
12
12
|
onHeart?(msg: any): Promise<boolean>;
|
|
13
|
-
onBeforeSendingMessage?(msg: any):
|
|
13
|
+
onBeforeSendingMessage?(msg: any): Promise<FW.SocketMessage>;
|
|
14
14
|
getProtocolKey?(msg: any): string;
|
|
15
15
|
|
|
16
16
|
send(msg: any) {
|