dzkcc-mflow 0.0.35 → 0.0.37
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/README.md +2 -2
- package/dist/core/Api.d.ts +22 -45
- package/dist/core/Core.d.ts +15 -19
- package/dist/core/Core.js +41 -36
- package/dist/core/Decorators.d.ts +2 -37
- package/dist/core/Decorators.js +6 -68
- package/dist/core/index.js +1 -1
- package/dist/libs/BaseView.d.ts +8 -11
- package/dist/libs/BaseView.js +10 -12
- package/dist/libs/CocosCore.js +0 -4
- package/dist/libs/UIManager.d.ts +3 -4
- package/dist/libs/UIManager.js +11 -7
- package/dist/mflow-tools.zip +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -168,7 +168,7 @@ mf.reddot.on('main/bag', (totalCount) => {
|
|
|
168
168
|
|
|
169
169
|
```typescript
|
|
170
170
|
// 只需要一次性配置类型映射
|
|
171
|
-
// types/
|
|
171
|
+
// types/api-type-hints.d.ts
|
|
172
172
|
declare module 'dzkcc-mflow/core' {
|
|
173
173
|
interface ModelTypeMap {
|
|
174
174
|
[ModelNames.User]: UserModel;
|
|
@@ -184,7 +184,7 @@ userModel.name; // ✅ 有完整的代码补全
|
|
|
184
184
|
|
|
185
185
|
框架提供了自动类型生成工具,在 Cocos Creator 编辑器中使用:
|
|
186
186
|
|
|
187
|
-
**编辑器菜单**:**mflow-tools ->
|
|
187
|
+
**编辑器菜单**:**mflow-tools -> Generate API type hints/生成API类型提示**
|
|
188
188
|
|
|
189
189
|
> ⚠️ **如果 getManager/getModel 没有类型提示**?
|
|
190
190
|
>
|
package/dist/core/Api.d.ts
CHANGED
|
@@ -1,64 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* ```typescript
|
|
5
|
-
* // 在 .d.ts 文件中扩展
|
|
6
|
-
* interface ModelNamesType {
|
|
7
|
-
* readonly User: 'User';
|
|
8
|
-
* }
|
|
9
|
-
* ```
|
|
2
|
+
* 全局类型声明 - 由业务层通过 .d.ts 扩展
|
|
3
|
+
* 用于泛型约束的类型推断
|
|
10
4
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* interface ManagerNamesType {
|
|
19
|
-
* readonly Home: 'Home';
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export interface ManagerNamesType extends Record<string, string> {
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* ViewNames 接口(由业务层扩展以提供代码补全和类型推断)
|
|
27
|
-
*/
|
|
28
|
-
export interface ViewNamesType extends Record<string, string> {
|
|
5
|
+
declare global {
|
|
6
|
+
interface ModelRegistry {
|
|
7
|
+
}
|
|
8
|
+
interface ManagerRegistry {
|
|
9
|
+
}
|
|
10
|
+
interface UIRegistry {
|
|
11
|
+
}
|
|
29
12
|
}
|
|
30
13
|
/**
|
|
31
14
|
* 核心接口 - 管理 Model 和 Manager 的生命周期
|
|
32
15
|
*
|
|
33
|
-
*
|
|
16
|
+
* 类型推断由业务层的全局类型声明提供
|
|
34
17
|
*/
|
|
35
18
|
export interface ICore {
|
|
36
|
-
/** 注册 Model - 通过 Key 自动实例化 */
|
|
37
|
-
regModel<T extends keyof ModelNamesType>(modelKey: T): void;
|
|
38
19
|
/**
|
|
39
20
|
* 获取 Model 实例
|
|
40
|
-
* @param
|
|
41
|
-
* @returns Model
|
|
21
|
+
* @param modelClass Model 类构造函数
|
|
22
|
+
* @returns Model 实例(类型由泛型参数推断)
|
|
42
23
|
* @example
|
|
43
24
|
* ```typescript
|
|
44
|
-
*
|
|
45
|
-
* const userModel = core.getModel(ModelNames.User);
|
|
25
|
+
* const userModel = core.getModel(UserModel);
|
|
46
26
|
* ```
|
|
47
27
|
*/
|
|
48
|
-
getModel<T extends keyof
|
|
49
|
-
/** 注册 Manager - 通过 Key 自动实例化 */
|
|
50
|
-
regManager<T extends keyof ManagerNamesType>(managerKey: T): void;
|
|
28
|
+
getModel<T extends keyof ModelRegistry>(modelClass: T): InstanceType<ModelRegistry[T]>;
|
|
51
29
|
/**
|
|
52
30
|
* 获取 Manager 实例
|
|
53
|
-
* @param
|
|
54
|
-
* @returns Manager
|
|
31
|
+
* @param managerClass Manager 类构造函数
|
|
32
|
+
* @returns Manager 实例(类型由泛型参数推断)
|
|
55
33
|
* @example
|
|
56
34
|
* ```typescript
|
|
57
|
-
*
|
|
58
|
-
* const gameManager = core.getManager(ManagerNames.Game);
|
|
35
|
+
* const gameManager = core.getManager(GameManager);
|
|
59
36
|
* ```
|
|
60
37
|
*/
|
|
61
|
-
getManager<T extends keyof
|
|
38
|
+
getManager<T extends keyof ManagerRegistry>(managerClass: T): InstanceType<ManagerRegistry[T]>;
|
|
62
39
|
}
|
|
63
40
|
/**
|
|
64
41
|
* Model 基接口 - 数据模型
|
|
@@ -92,15 +69,15 @@ export interface IView {
|
|
|
92
69
|
/**
|
|
93
70
|
* UI 管理器接口 - 管理视图的打开、关闭和栈操作
|
|
94
71
|
*
|
|
95
|
-
* 注意:open 和 openAndPush
|
|
72
|
+
* 注意:open 和 openAndPush 的返回类型由全局类型声明提供
|
|
96
73
|
*/
|
|
97
74
|
export interface IUIManager {
|
|
98
75
|
/** 打开视图 */
|
|
99
|
-
open<T extends keyof
|
|
76
|
+
open<T extends keyof UIRegistry>(viewClass: T, args?: any): Promise<InstanceType<UIRegistry[T]>>;
|
|
100
77
|
/** 关闭视图 */
|
|
101
|
-
close<T extends keyof
|
|
78
|
+
close<T extends keyof UIRegistry>(viewClass: T): void;
|
|
102
79
|
/** 打开视图并入栈 */
|
|
103
|
-
openAndPush<T extends keyof
|
|
80
|
+
openAndPush<T extends keyof UIRegistry>(viewClass: T, group: string, args?: any): Promise<InstanceType<UIRegistry[T]>>;
|
|
104
81
|
/** 关闭栈顶视图并弹出 */
|
|
105
82
|
closeAndPop(group: string, destroy?: boolean): void;
|
|
106
83
|
/** 获取栈顶视图 */
|
package/dist/core/Core.d.ts
CHANGED
|
@@ -1,46 +1,42 @@
|
|
|
1
|
-
import { ICore, IManager
|
|
1
|
+
import { ICore, IManager } from "./Api";
|
|
2
2
|
export declare abstract class AbstractCore<T extends AbstractCore<T>> implements ICore {
|
|
3
3
|
private readonly container;
|
|
4
4
|
constructor();
|
|
5
5
|
protected abstract initialize(): void;
|
|
6
|
-
regModel<T extends keyof ModelNamesType>(modelKey: T): void;
|
|
7
6
|
/**
|
|
8
7
|
* 获取 Model 实例
|
|
9
|
-
* @param
|
|
10
|
-
* @returns Model
|
|
8
|
+
* @param modelClass Model 类构造函数
|
|
9
|
+
* @returns Model 实例(类型由泛型参数推断)
|
|
11
10
|
* @example
|
|
12
11
|
* ```typescript
|
|
13
|
-
*
|
|
14
|
-
* const userModel = core.getModel(ModelNames.User);
|
|
12
|
+
* const userModel = core.getModel(UserModel);
|
|
15
13
|
* ```
|
|
16
14
|
*/
|
|
17
|
-
getModel<T extends keyof
|
|
18
|
-
regManager<T extends keyof ManagerNamesType>(managerKey: T): void;
|
|
15
|
+
getModel<T extends keyof ModelRegistry>(modelClass: T): InstanceType<ModelRegistry[T]>;
|
|
19
16
|
/**
|
|
20
17
|
* 获取 Manager 实例
|
|
21
|
-
* @param
|
|
22
|
-
* @returns Manager
|
|
18
|
+
* @param managerClass Manager 类构造函数
|
|
19
|
+
* @returns Manager 实例(类型由泛型参数推断)
|
|
23
20
|
* @example
|
|
24
21
|
* ```typescript
|
|
25
|
-
*
|
|
26
|
-
* const gameManager = core.getManager(ManagerNames.Game);
|
|
22
|
+
* const gameManager = core.getManager(GameManager);
|
|
27
23
|
* ```
|
|
28
24
|
*/
|
|
29
|
-
getManager<T extends keyof
|
|
25
|
+
getManager<T extends keyof ManagerRegistry>(managerClass: T): InstanceType<ManagerRegistry[T]>;
|
|
30
26
|
}
|
|
31
27
|
export declare abstract class AbstractManager implements IManager {
|
|
32
28
|
abstract initialize(): void;
|
|
33
29
|
dispose(): void;
|
|
34
30
|
/**
|
|
35
31
|
* 获取 Model 实例
|
|
36
|
-
* @param
|
|
37
|
-
* @returns Model
|
|
32
|
+
* @param modelClass Model 类构造函数
|
|
33
|
+
* @returns Model 实例(类型由泛型参数推断)
|
|
38
34
|
*/
|
|
39
|
-
protected getModel<T extends keyof
|
|
35
|
+
protected getModel<T extends keyof ModelRegistry>(modelClass: T): InstanceType<ModelRegistry[T]>;
|
|
40
36
|
/**
|
|
41
37
|
* 获取 Manager 实例
|
|
42
|
-
* @param
|
|
43
|
-
* @returns Manager
|
|
38
|
+
* @param managerClass Manager 类构造函数
|
|
39
|
+
* @returns Manager 实例(类型由泛型参数推断)
|
|
44
40
|
*/
|
|
45
|
-
protected getManager<T extends keyof
|
|
41
|
+
protected getManager<T extends keyof ManagerRegistry>(managerClass: T): InstanceType<ManagerRegistry[T]>;
|
|
46
42
|
}
|
package/dist/core/Core.js
CHANGED
|
@@ -14,53 +14,58 @@ class Container {
|
|
|
14
14
|
throw new Error(`${key} not registered!`);
|
|
15
15
|
return ins;
|
|
16
16
|
}
|
|
17
|
+
has(key) {
|
|
18
|
+
return this.key2ins.has(key);
|
|
19
|
+
}
|
|
17
20
|
}
|
|
18
21
|
class AbstractCore {
|
|
19
22
|
constructor() {
|
|
20
23
|
this.container = new Container();
|
|
21
24
|
this.initialize();
|
|
22
25
|
}
|
|
23
|
-
// 注册与获取模型
|
|
24
|
-
regModel(modelKey) {
|
|
25
|
-
const modelKeyStr = modelKey;
|
|
26
|
-
const ModelClass = getModelClass(modelKeyStr);
|
|
27
|
-
const model = new ModelClass();
|
|
28
|
-
this.container.reg(modelKeyStr, model);
|
|
29
|
-
model.initialize();
|
|
30
|
-
}
|
|
31
26
|
/**
|
|
32
27
|
* 获取 Model 实例
|
|
33
|
-
* @param
|
|
34
|
-
* @returns Model
|
|
28
|
+
* @param modelClass Model 类构造函数
|
|
29
|
+
* @returns Model 实例(类型由泛型参数推断)
|
|
35
30
|
* @example
|
|
36
31
|
* ```typescript
|
|
37
|
-
*
|
|
38
|
-
* const userModel = core.getModel(ModelNames.User);
|
|
32
|
+
* const userModel = core.getModel(UserModel);
|
|
39
33
|
* ```
|
|
40
34
|
*/
|
|
41
|
-
getModel(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
getModel(modelClass) {
|
|
36
|
+
const className = modelClass.name;
|
|
37
|
+
// 如果已存在实例,直接返回
|
|
38
|
+
if (this.container.has(className)) {
|
|
39
|
+
return this.container.get(className);
|
|
40
|
+
}
|
|
41
|
+
// 创建新实例
|
|
42
|
+
const ModelClass = getModelClass(className);
|
|
43
|
+
const instance = new ModelClass();
|
|
44
|
+
this.container.reg(className, instance);
|
|
45
|
+
instance.initialize();
|
|
46
|
+
return instance;
|
|
51
47
|
}
|
|
52
48
|
/**
|
|
53
49
|
* 获取 Manager 实例
|
|
54
|
-
* @param
|
|
55
|
-
* @returns Manager
|
|
50
|
+
* @param managerClass Manager 类构造函数
|
|
51
|
+
* @returns Manager 实例(类型由泛型参数推断)
|
|
56
52
|
* @example
|
|
57
53
|
* ```typescript
|
|
58
|
-
*
|
|
59
|
-
* const gameManager = core.getManager(ManagerNames.Game);
|
|
54
|
+
* const gameManager = core.getManager(GameManager);
|
|
60
55
|
* ```
|
|
61
56
|
*/
|
|
62
|
-
getManager(
|
|
63
|
-
|
|
57
|
+
getManager(managerClass) {
|
|
58
|
+
const className = managerClass.name;
|
|
59
|
+
// 如果已存在实例,直接返回
|
|
60
|
+
if (this.container.has(className)) {
|
|
61
|
+
return this.container.get(className);
|
|
62
|
+
}
|
|
63
|
+
// 创建新实例
|
|
64
|
+
const ManagerClass = getManagerClass(className);
|
|
65
|
+
const instance = new ManagerClass();
|
|
66
|
+
this.container.reg(className, instance);
|
|
67
|
+
instance.initialize();
|
|
68
|
+
return instance;
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
class AbstractManager {
|
|
@@ -68,21 +73,21 @@ class AbstractManager {
|
|
|
68
73
|
}
|
|
69
74
|
/**
|
|
70
75
|
* 获取 Model 实例
|
|
71
|
-
* @param
|
|
72
|
-
* @returns Model
|
|
76
|
+
* @param modelClass Model 类构造函数
|
|
77
|
+
* @returns Model 实例(类型由泛型参数推断)
|
|
73
78
|
*/
|
|
74
|
-
getModel(
|
|
79
|
+
getModel(modelClass) {
|
|
75
80
|
// 保持框架独立性,不与具体应用入口(app类)耦合
|
|
76
81
|
// 框架高内聚,使用ServiceLocator获取core
|
|
77
|
-
return ServiceLocator.getService('core').getModel(
|
|
82
|
+
return ServiceLocator.getService('core').getModel(modelClass);
|
|
78
83
|
}
|
|
79
84
|
/**
|
|
80
85
|
* 获取 Manager 实例
|
|
81
|
-
* @param
|
|
82
|
-
* @returns Manager
|
|
86
|
+
* @param managerClass Manager 类构造函数
|
|
87
|
+
* @returns Manager 实例(类型由泛型参数推断)
|
|
83
88
|
*/
|
|
84
|
-
getManager(
|
|
85
|
-
return ServiceLocator.getService('core').getManager(
|
|
89
|
+
getManager(managerClass) {
|
|
90
|
+
return ServiceLocator.getService('core').getManager(managerClass);
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import { ICore, ModelNamesType, ManagerNamesType, ViewNamesType } from "./Api";
|
|
2
|
-
/** Model 名称常量对象,用于代码补全和类型推断 */
|
|
3
|
-
export declare const ModelNames: ModelNamesType;
|
|
4
|
-
/** Manager 名称常量对象,用于代码补全和类型推断 */
|
|
5
|
-
export declare const ManagerNames: ManagerNamesType;
|
|
6
|
-
/** View 名称常量对象,用于代码补全和类型推断 */
|
|
7
|
-
export declare const ViewNames: ViewNamesType;
|
|
8
1
|
/**
|
|
9
2
|
* Model 装饰器,用于注册 Model 到全局注册表
|
|
10
3
|
* @param name 可选的 Model 名称,如果不提供则使用类名
|
|
@@ -16,7 +9,7 @@ export declare const ViewNames: ViewNamesType;
|
|
|
16
9
|
* }
|
|
17
10
|
*
|
|
18
11
|
* // 使用
|
|
19
|
-
* const user = mf.core.getModel(
|
|
12
|
+
* const user = mf.core.getModel(UserModel);
|
|
20
13
|
* ```
|
|
21
14
|
*/
|
|
22
15
|
export declare function model(name?: string): (ctor: Function) => void;
|
|
@@ -32,13 +25,6 @@ export declare function getRegisteredModelNames(): string[];
|
|
|
32
25
|
* @throws 如果 Model 未注册则抛出错误
|
|
33
26
|
*/
|
|
34
27
|
export declare function getModelClass<T>(modelKey: string): new () => T;
|
|
35
|
-
/**
|
|
36
|
-
* 通过类构造函数获取 Model 的 Key
|
|
37
|
-
* @param ctor Model 类构造函数
|
|
38
|
-
* @returns Model 的 Key
|
|
39
|
-
* @internal 内部使用
|
|
40
|
-
*/
|
|
41
|
-
export declare function getModelKey(ctor: Function): string | undefined;
|
|
42
28
|
/**
|
|
43
29
|
* Manager 装饰器,用于注册 Manager 到全局注册表
|
|
44
30
|
* @param name 可选的 Manager 名称,如果不提供则使用类名
|
|
@@ -63,13 +49,6 @@ export declare function getRegisteredManagerNames(): string[];
|
|
|
63
49
|
* @throws 如果 Manager 未注册则抛出错误
|
|
64
50
|
*/
|
|
65
51
|
export declare function getManagerClass<T>(managerKey: string): new () => T;
|
|
66
|
-
/**
|
|
67
|
-
* 通过类构造函数获取 Manager 的 Key
|
|
68
|
-
* @param ctor Manager 类构造函数
|
|
69
|
-
* @returns Manager 的 Key
|
|
70
|
-
* @internal 内部使用
|
|
71
|
-
*/
|
|
72
|
-
export declare function getManagerKey(ctor: Function): string | undefined;
|
|
73
52
|
/**
|
|
74
53
|
* View 装饰器,用于注册 View 到全局注册表
|
|
75
54
|
* @param name 可选的 View 名称,如果不提供则使用类名
|
|
@@ -84,7 +63,7 @@ export declare function getManagerKey(ctor: Function): string | undefined;
|
|
|
84
63
|
* }
|
|
85
64
|
*
|
|
86
65
|
* // 使用
|
|
87
|
-
* await mf.ui.open(
|
|
66
|
+
* await mf.ui.open(HomeView);
|
|
88
67
|
* ```
|
|
89
68
|
*/
|
|
90
69
|
export declare function view(name?: string): (ctor: Function) => void;
|
|
@@ -100,17 +79,3 @@ export declare function getRegisteredViewNames(): string[];
|
|
|
100
79
|
* @throws 如果 View 未注册则抛出错误
|
|
101
80
|
*/
|
|
102
81
|
export declare function getViewClass<T>(viewKey: string): new () => T;
|
|
103
|
-
/**
|
|
104
|
-
* 自动注册所有使用装饰器标记的 Model 和 Manager
|
|
105
|
-
* @param core Core 实例
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* // 导入所有 Model 和 Manager
|
|
109
|
-
* import '@/models/UserModel';
|
|
110
|
-
* import '@/managers/GameManager';
|
|
111
|
-
*
|
|
112
|
-
* // 自动注册
|
|
113
|
-
* autoRegister(mf.core);
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
export declare function autoRegister(core: ICore): void;
|
package/dist/core/Decorators.js
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
// ============================================================================
|
|
2
|
-
// Key 注册系统 - Names 对象(提供代码补全和类型推断)
|
|
3
|
-
// ============================================================================
|
|
4
|
-
/** Model 名称常量对象,用于代码补全和类型推断 */
|
|
5
|
-
const ModelNames = {};
|
|
6
|
-
/** Manager 名称常量对象,用于代码补全和类型推断 */
|
|
7
|
-
const ManagerNames = {};
|
|
8
|
-
/** View 名称常量对象,用于代码补全和类型推断 */
|
|
9
|
-
const ViewNames = {};
|
|
10
|
-
// ============================================================================
|
|
11
2
|
// 内部注册表
|
|
12
3
|
// ============================================================================
|
|
13
4
|
// Model 注册表
|
|
14
5
|
const modelRegistry = new Map(); // Key → 类
|
|
15
|
-
const ctorToModelKey = new Map(); // 类 → Key
|
|
16
6
|
// Manager 注册表
|
|
17
7
|
const managerRegistry = new Map(); // Key → 类
|
|
18
|
-
const ctorToManagerKey = new Map(); // 类 → Key
|
|
19
8
|
// View 注册表
|
|
20
9
|
const viewRegistry = new Map(); // Key → 类
|
|
21
10
|
// ============================================================================
|
|
@@ -32,7 +21,7 @@ const viewRegistry = new Map(); // Key → 类
|
|
|
32
21
|
* }
|
|
33
22
|
*
|
|
34
23
|
* // 使用
|
|
35
|
-
* const user = mf.core.getModel(
|
|
24
|
+
* const user = mf.core.getModel(UserModel);
|
|
36
25
|
* ```
|
|
37
26
|
*/
|
|
38
27
|
function model(name) {
|
|
@@ -40,8 +29,6 @@ function model(name) {
|
|
|
40
29
|
const modelName = name || ctor.name;
|
|
41
30
|
// 注册到映射表
|
|
42
31
|
modelRegistry.set(modelName, ctor);
|
|
43
|
-
ctorToModelKey.set(ctor, modelName);
|
|
44
|
-
ModelNames[modelName] = modelName;
|
|
45
32
|
console.log(`Model registered: ${modelName}`);
|
|
46
33
|
};
|
|
47
34
|
}
|
|
@@ -50,7 +37,7 @@ function model(name) {
|
|
|
50
37
|
* @returns Model 名称数组
|
|
51
38
|
*/
|
|
52
39
|
function getRegisteredModelNames() {
|
|
53
|
-
return
|
|
40
|
+
return Array.from(modelRegistry.keys());
|
|
54
41
|
}
|
|
55
42
|
/**
|
|
56
43
|
* 通过 Key 获取 Model 类构造函数
|
|
@@ -65,15 +52,6 @@ function getModelClass(modelKey) {
|
|
|
65
52
|
}
|
|
66
53
|
return modelClass;
|
|
67
54
|
}
|
|
68
|
-
/**
|
|
69
|
-
* 通过类构造函数获取 Model 的 Key
|
|
70
|
-
* @param ctor Model 类构造函数
|
|
71
|
-
* @returns Model 的 Key
|
|
72
|
-
* @internal 内部使用
|
|
73
|
-
*/
|
|
74
|
-
function getModelKey(ctor) {
|
|
75
|
-
return ctorToModelKey.get(ctor);
|
|
76
|
-
}
|
|
77
55
|
// ============================================================================
|
|
78
56
|
// Manager 装饰器
|
|
79
57
|
// ============================================================================
|
|
@@ -93,8 +71,6 @@ function manager(name) {
|
|
|
93
71
|
const managerName = name || ctor.name;
|
|
94
72
|
// 注册到映射表
|
|
95
73
|
managerRegistry.set(managerName, ctor);
|
|
96
|
-
ctorToManagerKey.set(ctor, managerName);
|
|
97
|
-
ManagerNames[managerName] = managerName;
|
|
98
74
|
console.log(`Manager registered: ${managerName}`);
|
|
99
75
|
};
|
|
100
76
|
}
|
|
@@ -103,7 +79,7 @@ function manager(name) {
|
|
|
103
79
|
* @returns Manager 名称数组
|
|
104
80
|
*/
|
|
105
81
|
function getRegisteredManagerNames() {
|
|
106
|
-
return
|
|
82
|
+
return Array.from(managerRegistry.keys());
|
|
107
83
|
}
|
|
108
84
|
/**
|
|
109
85
|
* 通过 Key 获取 Manager 类构造函数
|
|
@@ -118,15 +94,6 @@ function getManagerClass(managerKey) {
|
|
|
118
94
|
}
|
|
119
95
|
return managerClass;
|
|
120
96
|
}
|
|
121
|
-
/**
|
|
122
|
-
* 通过类构造函数获取 Manager 的 Key
|
|
123
|
-
* @param ctor Manager 类构造函数
|
|
124
|
-
* @returns Manager 的 Key
|
|
125
|
-
* @internal 内部使用
|
|
126
|
-
*/
|
|
127
|
-
function getManagerKey(ctor) {
|
|
128
|
-
return ctorToManagerKey.get(ctor);
|
|
129
|
-
}
|
|
130
97
|
// ============================================================================
|
|
131
98
|
// View 装饰器
|
|
132
99
|
// ============================================================================
|
|
@@ -144,7 +111,7 @@ function getManagerKey(ctor) {
|
|
|
144
111
|
* }
|
|
145
112
|
*
|
|
146
113
|
* // 使用
|
|
147
|
-
* await mf.ui.open(
|
|
114
|
+
* await mf.ui.open(HomeView);
|
|
148
115
|
* ```
|
|
149
116
|
*/
|
|
150
117
|
function view(name) {
|
|
@@ -152,7 +119,6 @@ function view(name) {
|
|
|
152
119
|
const viewName = name || ctor.name;
|
|
153
120
|
// 注册到映射表
|
|
154
121
|
viewRegistry.set(viewName, ctor);
|
|
155
|
-
ViewNames[viewName] = viewName;
|
|
156
122
|
console.log(`View registered: ${viewName}`);
|
|
157
123
|
};
|
|
158
124
|
}
|
|
@@ -161,7 +127,7 @@ function view(name) {
|
|
|
161
127
|
* @returns View 名称数组
|
|
162
128
|
*/
|
|
163
129
|
function getRegisteredViewNames() {
|
|
164
|
-
return
|
|
130
|
+
return Array.from(viewRegistry.keys());
|
|
165
131
|
}
|
|
166
132
|
/**
|
|
167
133
|
* 通过 Key 获取 View 类构造函数
|
|
@@ -175,34 +141,6 @@ function getViewClass(viewKey) {
|
|
|
175
141
|
throw new Error(`View not registered: ${viewKey}`);
|
|
176
142
|
}
|
|
177
143
|
return viewClass;
|
|
178
|
-
}
|
|
179
|
-
// ============================================================================
|
|
180
|
-
// 自动注册
|
|
181
|
-
// ============================================================================
|
|
182
|
-
/**
|
|
183
|
-
* 自动注册所有使用装饰器标记的 Model 和 Manager
|
|
184
|
-
* @param core Core 实例
|
|
185
|
-
* @example
|
|
186
|
-
* ```typescript
|
|
187
|
-
* // 导入所有 Model 和 Manager
|
|
188
|
-
* import '@/models/UserModel';
|
|
189
|
-
* import '@/managers/GameManager';
|
|
190
|
-
*
|
|
191
|
-
* // 自动注册
|
|
192
|
-
* autoRegister(mf.core);
|
|
193
|
-
* ```
|
|
194
|
-
*/
|
|
195
|
-
function autoRegister(core) {
|
|
196
|
-
// 注册所有 Model
|
|
197
|
-
ctorToModelKey.forEach((modelKey, ctor) => {
|
|
198
|
-
console.log(`${ctor.name} initialize`);
|
|
199
|
-
core.regModel(modelKey);
|
|
200
|
-
});
|
|
201
|
-
// 注册所有 Manager
|
|
202
|
-
ctorToManagerKey.forEach((managerKey, ctor) => {
|
|
203
|
-
console.log(`${ctor.name} initialize`);
|
|
204
|
-
core.regManager(managerKey);
|
|
205
|
-
});
|
|
206
144
|
}
|
|
207
145
|
|
|
208
|
-
export {
|
|
146
|
+
export { getManagerClass, getModelClass, getRegisteredManagerNames, getRegisteredModelNames, getRegisteredViewNames, getViewClass, manager, model, view };
|
package/dist/core/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { AbstractCore, AbstractManager } from './Core.js';
|
|
2
|
-
export {
|
|
2
|
+
export { getManagerClass, getModelClass, getRegisteredManagerNames, getRegisteredModelNames, getRegisteredViewNames, getViewClass, manager, model, view } from './Decorators.js';
|
|
3
3
|
export { ServiceLocator } from './ServiceLocator.js';
|
package/dist/libs/BaseView.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Component } from 'cc';
|
|
2
2
|
import { IView, IEventManager, ICocosResManager } from '../core';
|
|
3
|
-
import { ModelNamesType, ManagerNamesType } from '../core';
|
|
4
3
|
export declare abstract class BaseView extends Component implements IView {
|
|
5
4
|
/** @internal */
|
|
6
5
|
private readonly __isIView__;
|
|
@@ -19,24 +18,22 @@ export declare abstract class BaseView extends Component implements IView {
|
|
|
19
18
|
protected onDestroy(): void;
|
|
20
19
|
/**
|
|
21
20
|
* 获取 Model 实例
|
|
22
|
-
* @param
|
|
23
|
-
* @returns Model
|
|
21
|
+
* @param modelClass Model 类构造函数
|
|
22
|
+
* @returns Model 实例(类型由泛型参数推断)
|
|
24
23
|
* @example
|
|
25
24
|
* ```typescript
|
|
26
|
-
*
|
|
27
|
-
* const userModel = this.getModel(ModelNames.User);
|
|
25
|
+
* const userModel = this.getModel(UserModel);
|
|
28
26
|
* ```
|
|
29
27
|
*/
|
|
30
|
-
protected getModel<T extends keyof
|
|
28
|
+
protected getModel<T extends keyof ModelRegistry>(modelClass: T): InstanceType<ModelRegistry[T]>;
|
|
31
29
|
/**
|
|
32
30
|
* 获取 Manager 实例
|
|
33
|
-
* @param
|
|
34
|
-
* @returns Manager
|
|
31
|
+
* @param managerClass Manager 类构造函数
|
|
32
|
+
* @returns Manager 实例(类型由泛型参数推断)
|
|
35
33
|
* @example
|
|
36
34
|
* ```typescript
|
|
37
|
-
*
|
|
38
|
-
* const gameManager = this.getManager(ManagerNames.Game);
|
|
35
|
+
* const gameManager = this.getManager(GameManager);
|
|
39
36
|
* ```
|
|
40
37
|
*/
|
|
41
|
-
protected getManager<T extends keyof
|
|
38
|
+
protected getManager<T extends keyof ManagerRegistry>(managerClass: T): InstanceType<ManagerRegistry[T]>;
|
|
42
39
|
}
|
package/dist/libs/BaseView.js
CHANGED
|
@@ -71,29 +71,27 @@ class BaseView extends Component {
|
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* 获取 Model 实例
|
|
74
|
-
* @param
|
|
75
|
-
* @returns Model
|
|
74
|
+
* @param modelClass Model 类构造函数
|
|
75
|
+
* @returns Model 实例(类型由泛型参数推断)
|
|
76
76
|
* @example
|
|
77
77
|
* ```typescript
|
|
78
|
-
*
|
|
79
|
-
* const userModel = this.getModel(ModelNames.User);
|
|
78
|
+
* const userModel = this.getModel(UserModel);
|
|
80
79
|
* ```
|
|
81
80
|
*/
|
|
82
|
-
getModel(
|
|
83
|
-
return mf.core.getModel(
|
|
81
|
+
getModel(modelClass) {
|
|
82
|
+
return mf.core.getModel(modelClass);
|
|
84
83
|
}
|
|
85
84
|
/**
|
|
86
85
|
* 获取 Manager 实例
|
|
87
|
-
* @param
|
|
88
|
-
* @returns Manager
|
|
86
|
+
* @param managerClass Manager 类构造函数
|
|
87
|
+
* @returns Manager 实例(类型由泛型参数推断)
|
|
89
88
|
* @example
|
|
90
89
|
* ```typescript
|
|
91
|
-
*
|
|
92
|
-
* const gameManager = this.getManager(ManagerNames.Game);
|
|
90
|
+
* const gameManager = this.getManager(GameManager);
|
|
93
91
|
* ```
|
|
94
92
|
*/
|
|
95
|
-
getManager(
|
|
96
|
-
return mf.core.getManager(
|
|
93
|
+
getManager(managerClass) {
|
|
94
|
+
return mf.core.getManager(managerClass);
|
|
97
95
|
}
|
|
98
96
|
}
|
|
99
97
|
|
package/dist/libs/CocosCore.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Component } from 'cc';
|
|
2
2
|
import { AbstractCore } from '../core/Core.js';
|
|
3
|
-
import { autoRegister } from '../core/Decorators.js';
|
|
4
3
|
import { ServiceLocator } from '../core/ServiceLocator.js';
|
|
5
4
|
import { UIManager } from './UIManager.js';
|
|
6
5
|
import { ResLoader } from './ResLoader.js';
|
|
@@ -20,9 +19,6 @@ class Core extends AbstractCore {
|
|
|
20
19
|
ServiceLocator.regService('HttpManager', new HttpManager());
|
|
21
20
|
ServiceLocator.regService('WebSocketManager', new WebSocketManager());
|
|
22
21
|
ServiceLocator.regService('RedDotManager', new RedDotManager());
|
|
23
|
-
// 注册业务模块(通过装饰器自动注册)
|
|
24
|
-
// 推迟到构造函数执行完毕
|
|
25
|
-
queueMicrotask(() => autoRegister(this));
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
24
|
class CocosCore extends Component {
|
package/dist/libs/UIManager.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Component } from "cc";
|
|
2
2
|
import { IUIManager, IView } from "../core";
|
|
3
|
-
import { ViewNamesType } from "../core";
|
|
4
3
|
type ICocosView = IView & Component;
|
|
5
4
|
declare abstract class CcocosUIManager implements IUIManager {
|
|
6
5
|
getTopView(): IView | undefined;
|
|
7
|
-
open<T extends keyof
|
|
8
|
-
close<T extends keyof
|
|
9
|
-
openAndPush<T extends keyof
|
|
6
|
+
open<T extends keyof UIRegistry>(viewClass: T, args?: any): Promise<InstanceType<UIRegistry[T]>>;
|
|
7
|
+
close<T extends keyof UIRegistry>(viewClass: T): void;
|
|
8
|
+
openAndPush<T extends keyof UIRegistry>(viewClass: T, group: string, args?: any): Promise<InstanceType<UIRegistry[T]>>;
|
|
10
9
|
closeAndPop(group: string, destroy?: boolean): void;
|
|
11
10
|
clearStack(group: string, destroy?: boolean): void;
|
|
12
11
|
protected abstract internalOpen(viewKey: string, args?: any): Promise<ICocosView>;
|
package/dist/libs/UIManager.js
CHANGED
|
@@ -60,14 +60,17 @@ class CcocosUIManager {
|
|
|
60
60
|
getTopView() {
|
|
61
61
|
return this.internalGetTopView();
|
|
62
62
|
}
|
|
63
|
-
open(
|
|
64
|
-
|
|
63
|
+
open(viewClass, args) {
|
|
64
|
+
const className = viewClass.name;
|
|
65
|
+
return this.internalOpen(className, args);
|
|
65
66
|
}
|
|
66
|
-
close(
|
|
67
|
-
|
|
67
|
+
close(viewClass) {
|
|
68
|
+
const className = viewClass.name;
|
|
69
|
+
this.internalClose(className);
|
|
68
70
|
}
|
|
69
|
-
openAndPush(
|
|
70
|
-
|
|
71
|
+
openAndPush(viewClass, group, args) {
|
|
72
|
+
const className = viewClass.name;
|
|
73
|
+
return this.internalOpenAndPush(className, group, args);
|
|
71
74
|
}
|
|
72
75
|
closeAndPop(group, destroy) {
|
|
73
76
|
this.internalCloseAndPop(group, destroy);
|
|
@@ -88,7 +91,8 @@ class UIManager extends CcocosUIManager {
|
|
|
88
91
|
this.closeAndPop(view.__group__, false);
|
|
89
92
|
}
|
|
90
93
|
else {
|
|
91
|
-
|
|
94
|
+
// 对于直接关闭视图,我们需要通过内部方法处理
|
|
95
|
+
this.internalClose(view, false);
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
});
|
package/dist/mflow-tools.zip
CHANGED
|
Binary file
|
package/package.json
CHANGED