@kkarum/framework 2.3.19 → 2.3.20
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 +24 -0
- package/docs/CODEX_GUIDE.md +68 -0
- package/docs/FRAMEWORK_USAGE.md +53 -18
- package/docs/UI_DEVELOPMENT_GUIDE.md +35 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Framework
|
|
2
2
|
|
|
3
|
+
## AI 工具使用约定
|
|
4
|
+
|
|
5
|
+
Codex / AI 工具生成本项目业务代码时必须遵守:
|
|
6
|
+
|
|
7
|
+
- 获取 `AssetProperty` 使用点访问:`FW.Entry.getComponent(ShopAssetConfig).preLoad.prefab.ShopLayer`,不要使用 `["ShopLayer"]`。
|
|
8
|
+
- `LayerController` 不查找节点或组件;节点/组件引用定义在对应 `FW.Layer` 中,节点用 `FWPropertyNode`,组件用 `FWPropertyComponent`,变量名与节点名一致。
|
|
9
|
+
- 默认不要在业务层调用 `invoke()`,除非用户明确要求。
|
|
10
|
+
- 新增业务 bundle 必须提供 `FW.Registry` 注册表,并在文件末尾调用 `FW.Framework.addRegistry()`;`bundleName` 和 `addRegistry()` 的 key 必须一致,统一使用小写 bundle 名。
|
|
11
|
+
|
|
12
|
+
Registry 示例:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { RegisterAssetConfig } from "../config/RegisterAssetConfig";
|
|
16
|
+
import { RegisterLogic } from "../logic/RegisterLogic";
|
|
17
|
+
|
|
18
|
+
export class RegisterRegistry extends FW.Registry {
|
|
19
|
+
bundleName = "register";
|
|
20
|
+
logic: FW.Newable<FW.Logic> = RegisterLogic;
|
|
21
|
+
config: FW.Newable<FW.AssetConfig> = RegisterAssetConfig;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
FW.Framework.addRegistry("register", RegisterRegistry);
|
|
25
|
+
```
|
|
26
|
+
|
|
3
27
|
`assets/framework` 是面向 Cocos Creator 2.x 的自写业务框架,核心目标是把业务模块、UI Layer、资源、事件、网络、定时器、对象池和异步流程统一到 `FW` 全局命名空间下管理。
|
|
4
28
|
|
|
5
29
|
本 README 只做快速总览。详细开发规范请阅读 `assets/framework/docs/` 下的文档。
|
package/docs/CODEX_GUIDE.md
CHANGED
|
@@ -1,5 +1,73 @@
|
|
|
1
1
|
# Codex Guide
|
|
2
2
|
|
|
3
|
+
## AI 生成代码强制规则
|
|
4
|
+
|
|
5
|
+
以下规则优先级高于本文档中的旧示例。Codex 或其他 AI 工具为本项目生成业务代码时必须遵守:
|
|
6
|
+
|
|
7
|
+
1. 获取 `AssetProperty` 必须使用点访问,不要使用字符串下标访问。
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// 推荐
|
|
11
|
+
return FW.Entry.getComponent(ShopAssetConfig).preLoad.prefab.ShopLayer;
|
|
12
|
+
|
|
13
|
+
// 禁止
|
|
14
|
+
return FW.Entry.getComponent(ShopAssetConfig).preLoad.prefab["ShopLayer"];
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
2. `LayerController` 不要查找节点或组件,不要调用 `find()` / `findComponent()` 做 UI 引用缓存。
|
|
18
|
+
UI 节点和组件引用必须定义在对应 `FW.Layer` 组件中,并使用 `FWPropertyNode` / `FWPropertyComponent` 装饰器。变量名默认必须与节点名一致。
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
@ccclass
|
|
22
|
+
export class ShopLayer extends FW.Layer {
|
|
23
|
+
@FWPropertyNode()
|
|
24
|
+
BtnClose: cc.Node = null;
|
|
25
|
+
|
|
26
|
+
@FWPropertyComponent(cc.Label)
|
|
27
|
+
TitleLabel: cc.Label = null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class ShopLayerController extends FW.LayerController {
|
|
31
|
+
private bindEvents() {
|
|
32
|
+
const layer = this.layer as ShopLayer;
|
|
33
|
+
this.cc(layer.BtnClose, this.onCloseClick);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
3. 业务层默认不要调用 `invoke()`。除非用户明确要求统一性能记录、错误包装或可恢复异步流程,否则直接 `await` 业务方法、网络方法或资源方法。
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
// 推荐
|
|
42
|
+
await FW.Entry.getComponent(ShopLogic).buyGoods(goodsId);
|
|
43
|
+
|
|
44
|
+
// 仅在用户明确要求时使用
|
|
45
|
+
await this.invoke(FW.Entry.getComponent(ShopLogic).buyGoods(goodsId), "buyGoods");
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
4. 新增业务 bundle 必须提供 `FW.Registry` 注册表,并在文件末尾调用 `FW.Framework.addRegistry()`。`bundleName` 与 `addRegistry()` 的 bundle key 必须完全一致,统一使用小写 bundle 名。
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { RegisterAssetConfig } from "../config/RegisterAssetConfig";
|
|
52
|
+
import { RegisterLogic } from "../logic/RegisterLogic";
|
|
53
|
+
|
|
54
|
+
export class RegisterRegistry extends FW.Registry {
|
|
55
|
+
bundleName = "register";
|
|
56
|
+
logic: FW.Newable<FW.Logic> = RegisterLogic;
|
|
57
|
+
config: FW.Newable<FW.AssetConfig> = RegisterAssetConfig;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
FW.Framework.addRegistry("register", RegisterRegistry);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
规则:
|
|
64
|
+
|
|
65
|
+
- `Registry` 类名使用业务名 + `Registry`,例如 `RegisterRegistry`。
|
|
66
|
+
- `bundleName` 使用小写业务 bundle 名,例如 `"register"`。
|
|
67
|
+
- `logic/data/config/sender/handle` 字段必须显式声明为对应 `FW.Newable<...>` 类型。
|
|
68
|
+
- `FW.Framework.addRegistry("register", RegisterRegistry)` 必须与 `bundleName` 完全一致。
|
|
69
|
+
- 只声明实际存在的业务组件,不要为了占位声明空的 Data/Sender/Handle。
|
|
70
|
+
|
|
3
71
|
本文档是 Codex 在本项目中新增、修改业务功能时必须优先参考的工作规范。
|
|
4
72
|
|
|
5
73
|
## 首要约束
|
package/docs/FRAMEWORK_USAGE.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# Framework Usage
|
|
2
2
|
|
|
3
|
+
## AI 工具使用约定
|
|
4
|
+
|
|
5
|
+
Codex / AI 工具生成业务代码时必须遵守:
|
|
6
|
+
|
|
7
|
+
- `AssetConfig` 资源读取使用点访问,例如 `preLoad.prefab.ShopLayer`;不要使用 `preLoad.prefab["ShopLayer"]`。
|
|
8
|
+
- `LayerController` 不负责查找节点和组件。节点使用 `FWPropertyNode`、组件使用 `FWPropertyComponent`,统一定义在对应 `FW.Layer` 组件中,变量名与节点名一致。
|
|
9
|
+
- `invoke()` 默认不在业务层使用。只有用户明确要求性能记录、错误包装或特殊异步治理时才调用。
|
|
10
|
+
- 新增业务 bundle 必须提供 `FW.Registry` 注册表,并在文件末尾调用 `FW.Framework.addRegistry()`。`bundleName` 与 `addRegistry()` 的 bundle key 必须完全一致,统一使用小写 bundle 名。
|
|
11
|
+
|
|
12
|
+
示例:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
@ccclass
|
|
16
|
+
export class ShopLayer extends FW.Layer {
|
|
17
|
+
@FWPropertyNode()
|
|
18
|
+
BtnClose: cc.Node = null;
|
|
19
|
+
|
|
20
|
+
@FWPropertyComponent(cc.Label)
|
|
21
|
+
TitleLabel: cc.Label = null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class ShopLayerController extends FW.LayerController {
|
|
25
|
+
get layerAssetProperty(): FW.AssetProperty {
|
|
26
|
+
return FW.Entry.getComponent(ShopAssetConfig).preLoad.prefab.ShopLayer;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
onInit() {
|
|
30
|
+
const layer = this.layer as ShopLayer;
|
|
31
|
+
this.cc(layer.BtnClose, this.onCloseClick);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
3
36
|
本文档给出业务开发时的实际用法和推荐流程。
|
|
4
37
|
|
|
5
38
|
## 基本规则
|
|
@@ -30,22 +63,26 @@ assets/<bundle>/
|
|
|
30
63
|
注册类示例:
|
|
31
64
|
|
|
32
65
|
```ts
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
readonly sceneName = "ShopScene";
|
|
41
|
-
readonly depend = ["common"];
|
|
42
|
-
readonly autoRelease = true;
|
|
43
|
-
readonly logic = ShopLogic;
|
|
44
|
-
readonly data = ShopData;
|
|
45
|
-
readonly config = ShopAssetConfig;
|
|
66
|
+
import { RegisterAssetConfig } from "../config/RegisterAssetConfig";
|
|
67
|
+
import { RegisterLogic } from "../logic/RegisterLogic";
|
|
68
|
+
|
|
69
|
+
export class RegisterRegistry extends FW.Registry {
|
|
70
|
+
bundleName = "register";
|
|
71
|
+
logic: FW.Newable<FW.Logic> = RegisterLogic;
|
|
72
|
+
config: FW.Newable<FW.AssetConfig> = RegisterAssetConfig;
|
|
46
73
|
}
|
|
74
|
+
|
|
75
|
+
FW.Framework.addRegistry("register", RegisterRegistry);
|
|
47
76
|
```
|
|
48
77
|
|
|
78
|
+
注册规则:
|
|
79
|
+
|
|
80
|
+
- `Registry` 类名使用业务名 + `Registry`,例如 `RegisterRegistry`。
|
|
81
|
+
- `bundleName` 使用小写业务 bundle 名,例如 `"register"`。
|
|
82
|
+
- `FW.Framework.addRegistry("register", RegisterRegistry)` 必须与 `bundleName` 完全一致。
|
|
83
|
+
- `logic/data/config/sender/handle` 字段必须显式声明为对应 `FW.Newable<...>` 类型。
|
|
84
|
+
- 只声明实际存在的业务组件,不要为了占位声明空的 Data/Sender/Handle。
|
|
85
|
+
|
|
49
86
|
业务组件命名必须包含 bundle 名,并以 `Logic/Data/Config/Sender/Handle` 结尾。`FrameworkBase.initializeDependencies()` 会按类名推断 bundle 和组件类型。
|
|
50
87
|
|
|
51
88
|
## Logic
|
|
@@ -59,17 +96,15 @@ export class ShopLogic extends FW.Logic {
|
|
|
59
96
|
}
|
|
60
97
|
|
|
61
98
|
async refreshGoods() {
|
|
62
|
-
return this.
|
|
63
|
-
this.getSender<ShopSender>().sendGetGoods(),
|
|
64
|
-
"refreshGoods",
|
|
65
|
-
);
|
|
99
|
+
return this.getSender<ShopSender>().sendGetGoods();
|
|
66
100
|
}
|
|
67
101
|
}
|
|
68
102
|
```
|
|
69
103
|
|
|
70
104
|
规范:
|
|
71
105
|
|
|
72
|
-
-
|
|
106
|
+
- 默认直接 `await` 或 `return` 异步业务方法,不使用 `this.invoke()`。
|
|
107
|
+
- 只有用户明确要求性能记录、错误包装或特殊异步治理时才使用 `this.invoke()`。
|
|
73
108
|
- 业务数据写入 `this.getData<ShopData>()`。
|
|
74
109
|
- UI 通知用 `FW.Entry.evtMgr.dispatch()`。
|
|
75
110
|
- 不直接加载 prefab 打开 UI,应调用 `FW.Entry.layerMgr`。
|
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# UI Development Guide
|
|
2
2
|
|
|
3
|
+
## AI 生成 UI 代码规则
|
|
4
|
+
|
|
5
|
+
以下规则用于约束 Codex / AI 工具生成 UI 相关代码,并覆盖本文档中的旧示例:
|
|
6
|
+
|
|
7
|
+
- `LayerController` 中不要查找节点或组件,不要使用 `find()` / `findComponent()` 缓存 UI 引用。
|
|
8
|
+
- 节点引用写在对应 `FW.Layer` 组件中,使用 `@FWPropertyNode()`,变量名与节点名一致。
|
|
9
|
+
- 组件引用写在对应 `FW.Layer` 组件中,使用 `@FWPropertyComponent(ComponentClass)`,变量名与节点名一致。
|
|
10
|
+
- `layerAssetProperty` 返回资源时使用点访问:`preLoad.prefab.ShopLayer`,不要写 `preLoad.prefab["ShopLayer"]`。
|
|
11
|
+
- 默认不要在 Controller 或业务层调用 `invoke()`,除非用户明确要求。
|
|
12
|
+
|
|
13
|
+
推荐结构:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
@ccclass
|
|
17
|
+
export class ShopLayer extends FW.Layer {
|
|
18
|
+
@FWPropertyNode()
|
|
19
|
+
BtnClose: cc.Node = null;
|
|
20
|
+
|
|
21
|
+
@FWPropertyComponent(cc.Label)
|
|
22
|
+
TitleLabel: cc.Label = null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class ShopLayerController extends FW.LayerController {
|
|
26
|
+
get layerAssetProperty(): FW.AssetProperty {
|
|
27
|
+
return FW.Entry.getComponent(ShopAssetConfig).preLoad.prefab.ShopLayer;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onInit() {
|
|
31
|
+
const layer = this.layer as ShopLayer;
|
|
32
|
+
this.cc(layer.BtnClose, this.onCloseClick);
|
|
33
|
+
layer.TitleLabel.string = "Shop";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
3
38
|
本文档定义基于本框架开发 UI 的标准做法。
|
|
4
39
|
|
|
5
40
|
## UI 类型
|