dzkcc-mflow 0.0.28 → 0.0.30

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 CHANGED
@@ -186,7 +186,12 @@ userModel.name; // ✅ 有完整的代码补全
186
186
 
187
187
  **编辑器菜单**:**mflow-tools -> generate-types**
188
188
 
189
- 📖 **查看文档**: [类型自动推断](./docs/TYPE_INFERENCE.md) | [类型生成工具](./docs/TYPE_GENERATION.md)
189
+ > ⚠️ **如果 getManager/getModel 没有类型提示**?
190
+ >
191
+ > 需要创建类型映射文件,使用编辑器的 **mflow-tools -> Generate decorator mapping/生成装饰器映射** 自动生成,
192
+ > 或查看 [类型提示问题解决方案](./docs/TYPE_INFERENCE_FIX.md)
193
+
194
+ 📖 **查看文档**: [类型自动推断](./docs/TYPE_INFERENCE.md) | [类型生成工具](./docs/TYPE_GENERATION.md) | [类型提示问题解决](./docs/TYPE_INFERENCE_FIX.md)
190
195
 
191
196
  ### 9. 开发工具
192
197
 
@@ -279,6 +284,7 @@ mf.reddot.setCount('main/bag', 5);
279
284
  | [红点系统](./docs/REDDOT_SYSTEM.md) | 红点提示管理 |
280
285
  | [类型自动推断](./docs/TYPE_INFERENCE.md) | 类型映射和自动推断 |
281
286
  | [类型生成工具](./docs/TYPE_GENERATION.md) | 自动生成类型映射文件 |
287
+ | [类型提示问题解决](./docs/TYPE_INFERENCE_FIX.md) | 解决无类型提示问题 ⭐ |
282
288
  | [开发工具](./docs/DEV_TOOLS.md) | 编辑器插件使用 |
283
289
  | [完整示例](./docs/COMPLETE_EXAMPLE.md) | 塔防游戏示例 |
284
290
  | [最佳实践](./docs/BEST_PRACTICES.md) | 设计原则和规范 |
@@ -1,15 +1,58 @@
1
+ /**
2
+ * Model 类型映射接口(由业务层扩展)
3
+ */
4
+ export interface ModelTypeMap extends Record<string, any> {
5
+ }
6
+ /**
7
+ * Manager 类型映射接口(由业务层扩展)
8
+ */
9
+ export interface ManagerTypeMap extends Record<string, any> {
10
+ }
11
+ /**
12
+ * View 类型映射接口(由业务层扩展)
13
+ */
14
+ export interface ViewTypeMap extends Record<string, any> {
15
+ }
16
+ /**
17
+ * ModelNames 接口(由业务层扩展)
18
+ */
19
+ export interface ModelNamesType extends Record<string, symbol> {
20
+ }
21
+ /**
22
+ * ManagerNames 接口(由业务层扩展)
23
+ */
24
+ export interface ManagerNamesType extends Record<string, symbol> {
25
+ }
26
+ /**
27
+ * View 名称接口(用于类型推断,通过生成的 d.ts 文件扩展)
28
+ * */
29
+ export interface ViewNamesType extends Record<string, symbol> {
30
+ }
31
+ /**
32
+ * 从 symbol 推断对应的字符串 key
33
+ */
34
+ type GetKeyFromSymbol<S extends symbol, Names extends Record<string, symbol>> = {
35
+ [K in keyof Names]: Names[K] extends S ? K : never;
36
+ }[keyof Names];
37
+ /**
38
+ * 从 Model Symbol 推断类型
39
+ */
40
+ export type InferModelType<S extends symbol> = GetKeyFromSymbol<S, ModelNamesType> extends keyof ModelTypeMap ? ModelTypeMap[GetKeyFromSymbol<S, ModelNamesType>] : IModel;
41
+ /**
42
+ * 从 Manager Symbol 推断类型
43
+ */
44
+ export type InferManagerType<S extends symbol> = GetKeyFromSymbol<S, ManagerNamesType> extends keyof ManagerTypeMap ? ManagerTypeMap[GetKeyFromSymbol<S, ManagerNamesType>] : IManager;
1
45
  /**
2
46
  * 核心接口 - 管理 Model 和 Manager 的生命周期
3
47
  *
4
- * 注意:返回类型由具体实现类(AbstractCore)决定,
5
- * 实现类会使用类型推断将 symbol 映射到具体的 Model/Manager 类型
48
+ * 支持通过 Symbol 自动推断返回类型
6
49
  */
7
50
  export interface ICore {
8
51
  /** 注册 Model - 通过 Symbol 自动实例化 */
9
52
  regModel(modelSymbol: symbol): void;
10
53
  /**
11
54
  * 获取 Model(支持类型自动推断)
12
- * @param modelSymbol Model 的 Symbol。返回 any,由实现类提供具体类型
55
+ * @param modelSymbol Model 的 Symbol,使用 ModelNames.XXX
13
56
  * @returns Model 实例,类型会根据 symbol 自动推断为具体的 Model 类型
14
57
  * @example
15
58
  * ```typescript
@@ -17,12 +60,12 @@ export interface ICore {
17
60
  * const userModel = core.getModel(ModelNames.User);
18
61
  * ```
19
62
  */
20
- getModel<S extends symbol>(modelSymbol: S): any;
63
+ getModel<S extends symbol>(modelSymbol: S): InferModelType<S>;
21
64
  /** 注册 Manager - 通过 Symbol 自动实例化 */
22
65
  regManager(managerSymbol: symbol): void;
23
66
  /**
24
67
  * 获取 Manager(支持类型自动推断)
25
- * @param managerSymbol Manager 的 Symbol。返回 any,由实现类提供具体类型
68
+ * @param managerSymbol Manager 的 Symbol,使用 ManagerNames.XXX
26
69
  * @returns Manager 实例,类型会根据 symbol 自动推断为具体的 Manager 类型
27
70
  * @example
28
71
  * ```typescript
@@ -30,7 +73,7 @@ export interface ICore {
30
73
  * const gameManager = core.getManager(ManagerNames.Game);
31
74
  * ```
32
75
  */
33
- getManager<S extends symbol>(managerSymbol: S): any;
76
+ getManager<S extends symbol>(managerSymbol: S): InferManagerType<S>;
34
77
  }
35
78
  /**
36
79
  * Model 基接口 - 数据模型
@@ -225,3 +268,4 @@ export interface IRedDotManager extends IManager {
225
268
  /** 移除红点监听 */
226
269
  off(path: string, listener: Function): void;
227
270
  }
271
+ export {};
@@ -1,20 +1,4 @@
1
- import { ICore, IManager, IModel } from "./Api";
2
- import { ModelTypeMap, ManagerTypeMap, ModelNames, ManagerNames } from "./Decorators";
3
- /**
4
- * 从 symbol 推断对应的字符串 key
5
- * @example ModelNames.User -> 'User'
6
- */
7
- type GetKeyFromSymbol<S extends symbol, Names extends Record<string, symbol>> = {
8
- [K in keyof Names]: Names[K] extends S ? K : never;
9
- }[keyof Names];
10
- /**
11
- * 从 Model Symbol 推断类型
12
- */
13
- type InferModelType<S extends symbol> = GetKeyFromSymbol<S, typeof ModelNames> extends keyof ModelTypeMap ? ModelTypeMap[GetKeyFromSymbol<S, typeof ModelNames>] : IModel;
14
- /**
15
- * 从 Manager Symbol 推断类型
16
- */
17
- type InferManagerType<S extends symbol> = GetKeyFromSymbol<S, typeof ManagerNames> extends keyof ManagerTypeMap ? ManagerTypeMap[GetKeyFromSymbol<S, typeof ManagerNames>] : IManager;
1
+ import { ICore, IManager, InferModelType, InferManagerType } from "./Api";
18
2
  export declare abstract class AbstractCore<T extends AbstractCore<T>> implements ICore {
19
3
  private readonly container;
20
4
  constructor();
@@ -60,4 +44,3 @@ export declare abstract class AbstractManager implements IManager {
60
44
  */
61
45
  protected getManager<S extends symbol>(managerSymbol: S): InferManagerType<S>;
62
46
  }
63
- export {};
@@ -1,46 +1,11 @@
1
- import { ICore } from "./Api";
1
+ import { ICore, ModelNamesType, ManagerNamesType, ViewNamesType } from "./Api";
2
2
  import 'reflect-metadata';
3
- /** Model 名称接口(用于类型推断,通过生成的 d.ts 文件扩展) */
4
- export interface ModelNamesType extends Record<string, symbol> {
5
- }
6
- /** Manager 名称接口(用于类型推断,通过生成的 d.ts 文件扩展) */
7
- export interface ManagerNamesType extends Record<string, symbol> {
8
- }
9
- /** View 名称接口(用于类型推断,通过生成的 d.ts 文件扩展) */
10
- export interface ViewNamesType extends Record<string, symbol> {
11
- }
12
3
  /** Model 名称到 Symbol 的映射,用于代码补全和类型推断 */
13
4
  export declare const ModelNames: ModelNamesType;
14
5
  /** Manager 名称到 Symbol 的映射,用于代码补全和类型推断 */
15
6
  export declare const ManagerNames: ManagerNamesType;
16
7
  /** View 名称到 Symbol 的映射,用于代码补全和类型推断 */
17
8
  export declare const ViewNames: ViewNamesType;
18
- /**
19
- * Symbol 到类型的映射接口,用于类型推断
20
- * 业务层通过 declare module 扩展此接口来注册类型
21
- * @example
22
- * ```typescript
23
- * declare module 'dzkcc-mflow/core' {
24
- * interface ModelTypeMap {
25
- * 'User': UserModel; // 使用字符串字面量作为 key
26
- * }
27
- * }
28
- * ```
29
- */
30
- export interface ModelTypeMap extends Record<string, any> {
31
- }
32
- /**
33
- * Symbol 到类型的映射接口,用于类型推断
34
- * 业务层通过 declare module 扩展此接口来注册类型
35
- */
36
- export interface ManagerTypeMap extends Record<string, any> {
37
- }
38
- /**
39
- * Symbol 到类型的映射接口,用于类型推断
40
- * 业务层通过 declare module 扩展此接口来注册类型
41
- */
42
- export interface ViewTypeMap extends Record<string, any> {
43
- }
44
9
  /**
45
10
  * Model 装饰器,用于注册 Model 到全局注册表
46
11
  * @param name 可选的 Model 名称,如果不提供则使用类名
@@ -1,5 +1,8 @@
1
1
  import 'reflect-metadata';
2
2
 
3
+ // ============================================================================
4
+ // Symbol 注册系统 - Names 对象(提供代码补全和类型推断)
5
+ // ============================================================================
3
6
  /** Model 名称到 Symbol 的映射,用于代码补全和类型推断 */
4
7
  const ModelNames = {};
5
8
  /** Manager 名称到 Symbol 的映射,用于代码补全和类型推断 */
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dzkcc-mflow",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "description": "A modular design and process management framework developed for the cocos engine, suitable for decoupling and dependency injection.",
5
5
  "author": "duanzhk",
6
6
  "license": "MIT",