@kkarum/framework 2.3.17

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.
Files changed (171) hide show
  1. package/Framework.ts +337 -0
  2. package/Framework.ts.meta +10 -0
  3. package/FrameworkBase.ts +207 -0
  4. package/FrameworkBase.ts.meta +10 -0
  5. package/FrameworkInitialize.ts +79 -0
  6. package/FrameworkInitialize.ts.meta +10 -0
  7. package/README.md +93 -0
  8. package/README.md.meta +6 -0
  9. package/animation/FWAnimation.ts +13 -0
  10. package/animation/FWAnimation.ts.meta +10 -0
  11. package/animation/FWSkeleton.ts +174 -0
  12. package/animation/FWSkeleton.ts.meta +10 -0
  13. package/animation/FWTween.ts +60 -0
  14. package/animation/FWTween.ts.meta +10 -0
  15. package/animation.meta +13 -0
  16. package/component/FWVirtuaScrollViewComponent.ts +56 -0
  17. package/component/FWVirtuaScrollViewComponent.ts.meta +10 -0
  18. package/component/FWVirtualViewComponent.ts +2212 -0
  19. package/component/FWVirtualViewComponent.ts.meta +10 -0
  20. package/component.meta +13 -0
  21. package/config/FWAssetConfig.ts +7 -0
  22. package/config/FWAssetConfig.ts.meta +10 -0
  23. package/config/FWSystemConfig.ts +29 -0
  24. package/config/FWSystemConfig.ts.meta +10 -0
  25. package/config.meta +13 -0
  26. package/controller/FWLayerController.ts +178 -0
  27. package/controller/FWLayerController.ts.meta +10 -0
  28. package/controller.meta +13 -0
  29. package/data/FWData.ts +6 -0
  30. package/data/FWData.ts.meta +10 -0
  31. package/data.meta +13 -0
  32. package/define/FWEventDefine.ts +28 -0
  33. package/define/FWEventDefine.ts.meta +10 -0
  34. package/define/FWSystemDefine.ts +154 -0
  35. package/define/FWSystemDefine.ts.meta +10 -0
  36. package/define.meta +13 -0
  37. package/entry/FWEntry.ts +219 -0
  38. package/entry/FWEntry.ts.meta +10 -0
  39. package/entry.meta +13 -0
  40. package/expand/FWCocosExpand.ts +73 -0
  41. package/expand/FWCocosExpand.ts.meta +10 -0
  42. package/expand/FWDecorator.ts +366 -0
  43. package/expand/FWDecorator.ts.meta +10 -0
  44. package/expand/FWNodeExpand.ts +147 -0
  45. package/expand/FWNodeExpand.ts.meta +10 -0
  46. package/expand/FWRollingViewNesting.ts +195 -0
  47. package/expand/FWRollingViewNesting.ts.meta +10 -0
  48. package/expand/FWTweenExpand.ts +44 -0
  49. package/expand/FWTweenExpand.ts.meta +10 -0
  50. package/expand.meta +13 -0
  51. package/item/FWVirtualListItem.ts +141 -0
  52. package/item/FWVirtualListItem.ts.meta +10 -0
  53. package/item.meta +13 -0
  54. package/language/FWLanguage.ts +71 -0
  55. package/language/FWLanguage.ts.meta +10 -0
  56. package/language/FWLanguageLabelLocalize.ts +144 -0
  57. package/language/FWLanguageLabelLocalize.ts.meta +10 -0
  58. package/language/FWLanguageSkeletonLocalize.ts +106 -0
  59. package/language/FWLanguageSkeletonLocalize.ts.meta +10 -0
  60. package/language/FWLanguageSpriteLocalize.ts +81 -0
  61. package/language/FWLanguageSpriteLocalize.ts.meta +10 -0
  62. package/language.meta +13 -0
  63. package/layer/FWLayer.ts +14 -0
  64. package/layer/FWLayer.ts.meta +10 -0
  65. package/layer.meta +13 -0
  66. package/log/FWLog.ts +135 -0
  67. package/log/FWLog.ts.meta +10 -0
  68. package/log.meta +13 -0
  69. package/logic/FWLogic.ts +6 -0
  70. package/logic/FWLogic.ts.meta +10 -0
  71. package/logic.meta +13 -0
  72. package/machine/FWAnimationMachine.ts +28 -0
  73. package/machine/FWAnimationMachine.ts.meta +10 -0
  74. package/machine/FWStateMachine.ts +74 -0
  75. package/machine/FWStateMachine.ts.meta +10 -0
  76. package/machine.meta +13 -0
  77. package/manager/FWAnimationManager.ts +89 -0
  78. package/manager/FWAnimationManager.ts.meta +10 -0
  79. package/manager/FWAssetManager.ts +451 -0
  80. package/manager/FWAssetManager.ts.meta +10 -0
  81. package/manager/FWAudioManager.ts +339 -0
  82. package/manager/FWAudioManager.ts.meta +10 -0
  83. package/manager/FWBundleManager.ts +97 -0
  84. package/manager/FWBundleManager.ts.meta +10 -0
  85. package/manager/FWComponentManager.ts +24 -0
  86. package/manager/FWComponentManager.ts.meta +10 -0
  87. package/manager/FWEngineManager.ts +74 -0
  88. package/manager/FWEngineManager.ts.meta +10 -0
  89. package/manager/FWEventManager.ts +361 -0
  90. package/manager/FWEventManager.ts.meta +10 -0
  91. package/manager/FWHotUpdateManager.ts +344 -0
  92. package/manager/FWHotUpdateManager.ts.meta +10 -0
  93. package/manager/FWLanguageManager.ts +114 -0
  94. package/manager/FWLanguageManager.ts.meta +10 -0
  95. package/manager/FWLayerManager.ts +862 -0
  96. package/manager/FWLayerManager.ts.meta +10 -0
  97. package/manager/FWManager.ts +9 -0
  98. package/manager/FWManager.ts.meta +10 -0
  99. package/manager/FWObjectManager.ts +161 -0
  100. package/manager/FWObjectManager.ts.meta +10 -0
  101. package/manager/FWPerformanceManager.ts +198 -0
  102. package/manager/FWPerformanceManager.ts.meta +10 -0
  103. package/manager/FWPromiseManager.ts +504 -0
  104. package/manager/FWPromiseManager.ts.meta +10 -0
  105. package/manager/FWResManager.ts +299 -0
  106. package/manager/FWResManager.ts.meta +10 -0
  107. package/manager/FWSocketManager.ts +93 -0
  108. package/manager/FWSocketManager.ts.meta +10 -0
  109. package/manager/FWStateManager.ts +100 -0
  110. package/manager/FWStateManager.ts.meta +10 -0
  111. package/manager/FWTaskManager.ts +41 -0
  112. package/manager/FWTaskManager.ts.meta +10 -0
  113. package/manager/FWTimeManager.ts +442 -0
  114. package/manager/FWTimeManager.ts.meta +10 -0
  115. package/manager/FWUiManager.ts +217 -0
  116. package/manager/FWUiManager.ts.meta +10 -0
  117. package/manager.meta +13 -0
  118. package/package.json +11 -0
  119. package/package.json.meta +6 -0
  120. package/registry/FWRegistry.ts +62 -0
  121. package/registry/FWRegistry.ts.meta +10 -0
  122. package/registry.meta +13 -0
  123. package/render/FWRenderAssembler.ts +620 -0
  124. package/render/FWRenderAssembler.ts.meta +10 -0
  125. package/render.meta +13 -0
  126. package/scene/FWScene.ts +23 -0
  127. package/scene/FWScene.ts.meta +10 -0
  128. package/scene.meta +13 -0
  129. package/service/FWService.ts +11 -0
  130. package/service/FWService.ts.meta +10 -0
  131. package/service/http/FWHttp.ts +103 -0
  132. package/service/http/FWHttp.ts.meta +10 -0
  133. package/service/http.meta +13 -0
  134. package/service/socket/FWSocket.ts +367 -0
  135. package/service/socket/FWSocket.ts.meta +10 -0
  136. package/service/socket/FWSocketHandle.ts +16 -0
  137. package/service/socket/FWSocketHandle.ts.meta +10 -0
  138. package/service/socket/FWSocketSender.ts +14 -0
  139. package/service/socket/FWSocketSender.ts.meta +10 -0
  140. package/service/socket/mock/FWSocketMock.ts +202 -0
  141. package/service/socket/mock/FWSocketMock.ts.meta +10 -0
  142. package/service/socket/mock.meta +13 -0
  143. package/service/socket.meta +13 -0
  144. package/service.meta +13 -0
  145. package/state/FWState.ts +8 -0
  146. package/state/FWState.ts.meta +10 -0
  147. package/state.meta +13 -0
  148. package/types/Creator.d.ts +121 -0
  149. package/types/Creator.d.ts.meta +6 -0
  150. package/types/FW.d.ts +3016 -0
  151. package/types/FW.d.ts.meta +6 -0
  152. package/types/Global.d.ts +22 -0
  153. package/types/Global.d.ts.meta +10 -0
  154. package/types.meta +13 -0
  155. package/utils/FWLodash.ts +105 -0
  156. package/utils/FWLodash.ts.meta +10 -0
  157. package/utils/FWMask.ts +222 -0
  158. package/utils/FWMask.ts.meta +10 -0
  159. package/utils/FWObject.ts +27 -0
  160. package/utils/FWObject.ts.meta +10 -0
  161. package/utils/FWObjectPool.ts +177 -0
  162. package/utils/FWObjectPool.ts.meta +10 -0
  163. package/utils/FWQueue.ts +55 -0
  164. package/utils/FWQueue.ts.meta +10 -0
  165. package/utils/FWResLoader.ts +139 -0
  166. package/utils/FWResLoader.ts.meta +10 -0
  167. package/utils/FWTask.ts +227 -0
  168. package/utils/FWTask.ts.meta +10 -0
  169. package/utils/FWUtils.ts +15 -0
  170. package/utils/FWUtils.ts.meta +10 -0
  171. package/utils.meta +13 -0
@@ -0,0 +1,219 @@
1
+ import FWUiManager from '../manager/FWUiManager';
2
+ import FWAnimationManager from '../manager/FWAnimationManager';
3
+ import FWAudioManager from '../manager/FWAudioManager';
4
+ import FWComponentManager from '../manager/FWComponentManager';
5
+ import FWEventManager from '../manager/FWEventManager';
6
+ import FWLanguageManager from '../manager/FWLanguageManager';
7
+ import { FWLayerManager } from '../manager/FWLayerManager';
8
+ import FWObjectManager from '../manager/FWObjectManager';
9
+ import { FWResManager } from '../manager/FWResManager';
10
+ import FWSocketManager from '../manager/FWSocketManager';
11
+ import { FWStateManager } from '../manager/FWStateManager';
12
+ import { FWTimeManager } from '../manager/FWTimeManager';
13
+ import { FWSocketAutoProcessPause } from '../expand/FWDecorator';
14
+ import FWTaskManager from '../manager/FWTaskManager';
15
+ import FWEngineManager from '../manager/FWEngineManager';
16
+ import FWHotUpdateManager from '../manager/FWHotUpdateManager';
17
+ import FWPromiseManager from '../manager/FWPromiseManager';
18
+ import { FWPerformanceManager } from '../manager/FWPerformanceManager';
19
+ import FWUtils from '../utils/FWUtils';
20
+
21
+ /**
22
+ * 入口脚本
23
+ */
24
+ export class FWEntry implements FW.Entry {
25
+ map: Map<string, FW.RegisterBundle> = new Map<string, FW.RegisterBundle>();
26
+ /**
27
+ * 事件管理器
28
+ */
29
+ timeMgr: FW.TimeManager;
30
+ /**
31
+ * 层级管理器
32
+ */
33
+ layerMgr: FW.LayerManager;
34
+ /**
35
+ * 资源管理器
36
+ */
37
+ resMgr: FW.ResManager;
38
+ /**
39
+ * 动画管理器
40
+ */
41
+ animationMgr: FW.AnimationManager;
42
+ /**
43
+ * 状态管理器
44
+ */
45
+ stateMgr: FW.StateManager;
46
+ /**
47
+ * 音效管理器
48
+ */
49
+ audioMgr: FW.AudioManager;
50
+ /**
51
+ * socket管理器
52
+ */
53
+ socketMgr: FW.SocketManager;
54
+ /**
55
+ * 对象管理器
56
+ */
57
+ objectMgr: FW.ObjectManager;
58
+ /**
59
+ * 事件管理器
60
+ */
61
+ evtMgr: FW.EventManager;
62
+ /**
63
+ * UI管理器
64
+ */
65
+ uiMgr: FW.UiManager;
66
+ /**
67
+ * 任务管理器
68
+ */
69
+ taskMgr: FW.TaskManager;
70
+ /**
71
+ * 组件管理器
72
+ */
73
+ componentMgr: FWComponentManager;
74
+ /**
75
+ * 多语言管理器
76
+ */
77
+ languageMgr: FW.LanguageManager;
78
+ /**
79
+ * 引擎管理器
80
+ */
81
+ engineMgr: FW.EngineManager;
82
+ /**
83
+ * 热更新管理器
84
+ */
85
+ hotUpdateMgr: FW.HotUpdateManager;
86
+ /**
87
+ * promise管理器
88
+ */
89
+ promiseMgr: FW.PromiseManager;
90
+ /**
91
+ * 性能管理器
92
+ */
93
+ performanceMgr: FW.PerformanceManager;
94
+
95
+ utils: FW.Utils;
96
+ /**
97
+ * 当前Scene
98
+ */
99
+ scene: FW.Scene;
100
+ /**
101
+ * bundle名字
102
+ */
103
+ bundleName: string;
104
+ /**
105
+ * 初始化
106
+ * */
107
+ initialize() {
108
+ this.evtMgr = new FWEventManager();
109
+ this.timeMgr = new FWTimeManager();
110
+ this.engineMgr = new FWEngineManager();
111
+ this.taskMgr = new FWTaskManager();
112
+ this.resMgr = new FWResManager();
113
+ this.layerMgr = new FWLayerManager();
114
+ this.uiMgr = new FWUiManager();
115
+ this.animationMgr = new FWAnimationManager();
116
+ this.stateMgr = new FWStateManager();
117
+ this.audioMgr = new FWAudioManager();
118
+ this.objectMgr = new FWObjectManager();
119
+ this.socketMgr = new FWSocketManager();
120
+ this.componentMgr = new FWComponentManager();
121
+ this.languageMgr = new FWLanguageManager();
122
+ this.hotUpdateMgr = new FWHotUpdateManager();
123
+ this.promiseMgr = new FWPromiseManager();
124
+ this.performanceMgr = new FWPerformanceManager();
125
+ this.utils = new FWUtils();
126
+ }
127
+
128
+ /**
129
+ * 启动场景
130
+ * @param bundleName bundle名字
131
+ * @param sceneName 场景名字
132
+ */
133
+ @FWSocketAutoProcessPause()
134
+ launchScene(name: string, forceRelease?: boolean): void {
135
+ FW.Entry.layerMgr.clear();
136
+
137
+ if (forceRelease) {
138
+ this.releaseBundle(this.bundleName);
139
+ } else {
140
+ if (this.bundleAutoRelease(this.bundleName)) {
141
+ this.releaseBundle(this.bundleName);
142
+ }
143
+ }
144
+
145
+ if (!this.hasSceneName(name)) {
146
+ try {
147
+ cc.director.loadScene(name);
148
+ this.bundleName = '';
149
+ return;
150
+ } catch (e) {
151
+ FW.Log.error('launchScene failed:', name);
152
+ }
153
+ }
154
+
155
+ this.bundleName = name;
156
+
157
+ cc.director.loadScene(this.getSceneName());
158
+ }
159
+
160
+ restart() {
161
+ this.engineMgr?.restart();
162
+ }
163
+
164
+ releaseBundle(bundleName: string) {
165
+ this.resMgr.releaseBundle(bundleName);
166
+ const depend = this.getDepend(bundleName);
167
+ for (const d of depend) {
168
+ this.resMgr.releaseBundle(d);
169
+ }
170
+ }
171
+
172
+ register(data: FW.RegisterBundle) {
173
+ this.map.set(data.bundleName, data);
174
+ }
175
+
176
+ unRegister(data: FW.RegisterBundle): void {
177
+ this.map.has(data?.bundleName) && this.map.delete(data?.bundleName);
178
+ }
179
+
180
+ bundleAutoRelease(bundleName: string) {
181
+ const autoRelease = this.map.get(bundleName)?.autoRelease;
182
+ return autoRelease === undefined ? true : autoRelease;
183
+ }
184
+
185
+ getDepend(bundleName: string) {
186
+ const dependencySet = new Set<string>();
187
+ const findDependencies = (name: string) => {
188
+ const directDeps = this.map.get(name)?.depend || [];
189
+ for (const dep of directDeps) {
190
+ if (!dependencySet.has(dep)) {
191
+ dependencySet.add(dep);
192
+ findDependencies(dep);
193
+ }
194
+ }
195
+ };
196
+
197
+ findDependencies(bundleName);
198
+
199
+ return Array.from(dependencySet);
200
+ }
201
+
202
+ hasSceneName(sceneName: string) {
203
+ return this.map.has(sceneName);
204
+ }
205
+
206
+ getSceneName() {
207
+ return this.map.get(this.bundleName)?.sceneName || undefined;
208
+ }
209
+
210
+ getComponent: <T>(serviceIdentifier: FW.ServiceIdentifier<T>) => T = (serviceIdentifier) =>
211
+ FW.Framework.getComponent(serviceIdentifier);
212
+
213
+ getComponents: <T>(serviceIdentifier?: FW.ServiceIdentifier<T>) => T[] = (serviceIdentifier) =>
214
+ FW.Framework.getComponents(serviceIdentifier);
215
+
216
+ update(dt: number) {
217
+ this.timeMgr?.onUpdate(dt);
218
+ }
219
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "8848bb37-a1fc-43cf-967d-63e757e5d663",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
+ }
package/entry.meta ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "ver": "1.1.3",
3
+ "uuid": "0886dc2c-004b-4b93-9c5e-eae8ac86edee",
4
+ "importer": "folder",
5
+ "isBundle": false,
6
+ "bundleName": "",
7
+ "priority": 1,
8
+ "compressionType": {},
9
+ "optimizeHotUpdate": {},
10
+ "inlineSpriteFrames": {},
11
+ "isRemoteBundle": {},
12
+ "subMetas": {}
13
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * 游戏整体速率修改
3
+ */
4
+ if (CC_DEBUG) {
5
+ let timeScaler = 1;
6
+
7
+ const originCalculateDeltaTime = cc.Director.prototype['calculateDeltaTime'];
8
+ cc.director['calculateDeltaTime'] = function (now) {
9
+ originCalculateDeltaTime.call(this, now);
10
+ this._deltaTime *= timeScaler;
11
+ };
12
+
13
+ /**
14
+ * 修改时间倍率
15
+ *
16
+ * @param {number} scaler 倍率值
17
+ */
18
+ FW.timeScale = function (scaler = 1) {
19
+ timeScaler = scaler;
20
+ return `当前帧率缩放比=${timeScaler}`;
21
+ };
22
+ }
23
+
24
+ /**
25
+ * 编辑器模式下预览spine动画
26
+ */
27
+ if (CC_DEBUG && CC_EDITOR) {
28
+ cc.game.once(cc.game.EVENT_ENGINE_INITED, function () {
29
+ cc.js.mixin(sp.Skeleton.prototype, {
30
+ update(dt) {
31
+ // if (CC_EDITOR) return;
32
+
33
+ if (CC_EDITOR) {
34
+ cc['engine']._animatingInEditMode = 1;
35
+ cc['engine'].animatingInEditMode = 1;
36
+ }
37
+
38
+ if (this.paused) return;
39
+
40
+ dt *= this.timeScale * sp['timeScale'];
41
+
42
+ if (this.isAnimationCached()) {
43
+ // Cache mode and has animation queue.
44
+ if (this._isAniComplete) {
45
+ if (this._animationQueue.length === 0 && !this._headAniInfo) {
46
+ let frameCache = this._frameCache;
47
+ if (frameCache && frameCache.isInvalid()) {
48
+ frameCache.updateToFrame();
49
+ let frames = frameCache.frames;
50
+ this._curFrame = frames[frames.length - 1];
51
+ }
52
+ return;
53
+ }
54
+ if (!this._headAniInfo) {
55
+ this._headAniInfo = this._animationQueue.shift();
56
+ }
57
+ this._accTime += dt;
58
+ if (this._accTime > this._headAniInfo.delay) {
59
+ let aniInfo = this._headAniInfo;
60
+ this._headAniInfo = null;
61
+ this.setAnimation(0, aniInfo.animationName, aniInfo.loop);
62
+ }
63
+ return;
64
+ }
65
+
66
+ this._updateCache(dt);
67
+ } else {
68
+ this._updateRealtime(dt);
69
+ }
70
+ },
71
+ });
72
+ });
73
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "a17028d0-eb34-48e2-846a-ce7bbd25a8f4",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
+ }
@@ -0,0 +1,366 @@
1
+ import 'reflect-metadata';
2
+
3
+ export function searchChild(node: cc.Node, name: string) {
4
+ let ret = node.getChildByName(name);
5
+ if (ret) return ret;
6
+ for (let i = 0; i < node.children.length; i++) {
7
+ let child = node.children[i];
8
+ if (!child.isValid) continue;
9
+ ret = searchChild(child, name);
10
+ if (ret) return ret;
11
+ }
12
+ return null;
13
+ }
14
+
15
+ const CookDecoratorKey = ($desc: string) => `__ccc_decorator_${$desc}__`;
16
+
17
+ const KeyChild = CookDecoratorKey('child_cache');
18
+
19
+ type ParamType = {
20
+ path?: string;
21
+ };
22
+
23
+ export function FWPropertyNode($opt?: ParamType): FW.PropertyDecorator {
24
+ return ($target, $propertyKey: string, $descriptorOrInitializer) => {
25
+ if (!$target.hasOwnProperty(KeyChild)) {
26
+ $target[KeyChild] = [];
27
+
28
+ const oldOnLoad: () => void = $target.onLoad || undefined;
29
+ $target.onLoad = function () {
30
+ const cache = $target[KeyChild];
31
+ cache.forEach(($vo) => {
32
+ const node = searchChild(this.node, $vo.childName);
33
+ this[$vo.propertyKey] = node;
34
+ });
35
+ oldOnLoad && oldOnLoad.apply(this);
36
+ };
37
+ }
38
+
39
+ const cache: { propertyKey: string; childName: string }[] = $target[KeyChild];
40
+
41
+ if (!cache.some(($vo) => $vo.propertyKey === $propertyKey)) {
42
+ cache.push({
43
+ propertyKey: $propertyKey,
44
+ childName: $opt?.path || $propertyKey,
45
+ });
46
+ } else {
47
+ throw new Error(`child 装饰器重复绑定属性:${$propertyKey},class:${$target?.name}`);
48
+ }
49
+ };
50
+ }
51
+
52
+ const KeyChildMulti = CookDecoratorKey('child_cache_multi');
53
+
54
+ export function FWPropertyNodes(...paths: string[]): FW.PropertyDecorator {
55
+ return ($target: any, $propertyKey: string) => {
56
+ if (!$target.hasOwnProperty(KeyChildMulti)) {
57
+ $target[KeyChildMulti] = [];
58
+
59
+ const oldOnLoad = $target.onLoad;
60
+ $target.onLoad = function () {
61
+ const cache = $target[KeyChildMulti];
62
+ if (!this.node) {
63
+ console.error(`this.node 为空,无法查找子节点`, this);
64
+ return;
65
+ }
66
+ cache.forEach(($vo) => {
67
+ const nodes: cc.Node[] = [];
68
+ $vo.childNames.forEach((childName) => {
69
+ const childNode = searchChild(this.node, childName);
70
+ if (!childNode) {
71
+ console.warn(`未找到子节点:${childName}`);
72
+ } else {
73
+ nodes.push(childNode);
74
+ }
75
+ });
76
+ this[$vo.propertyKey] = nodes;
77
+ });
78
+ if (oldOnLoad) {
79
+ oldOnLoad.apply(this);
80
+ }
81
+ };
82
+ }
83
+
84
+ const cache: { propertyKey: string; childNames: string[] }[] = $target[KeyChildMulti];
85
+ const existingEntry = cache.find(($vo) => $vo.propertyKey === $propertyKey);
86
+
87
+ if (!existingEntry) {
88
+ cache.push({
89
+ propertyKey: $propertyKey,
90
+ childNames: paths,
91
+ });
92
+ } else {
93
+ throw new Error(
94
+ `child 装饰器重复绑定属性:${$propertyKey}, class:${$target.constructor.name}`,
95
+ );
96
+ }
97
+ };
98
+ }
99
+
100
+ interface INewable<T = any> extends Function {
101
+ new (...args: any[]): T;
102
+ }
103
+
104
+ const KeyComp = CookDecoratorKey('comp_cache');
105
+
106
+ export function FWPropertyComponent(
107
+ $componentClass: INewable<cc.Component>,
108
+ $childName?: string,
109
+ $mute = false,
110
+ ): FW.PropertyDecorator {
111
+ return ($target, $propertyKey: string, $descriptorOrInitializer) => {
112
+ if (!$target.hasOwnProperty(KeyComp)) {
113
+ $target[KeyComp] = [];
114
+
115
+ const oldOnLoad: () => void = $target.onLoad || undefined;
116
+ $target.onLoad = function () {
117
+ const cache = $target[KeyComp];
118
+ cache.forEach(($vo) => {
119
+ const node = $vo.childName ? searchChild(this.node, $vo.childName) : this.node;
120
+ if (!node) {
121
+ if (!$mute) {
122
+ throw new Error(
123
+ `component装饰器没有找到适合的node节点:class:${$target?.name},组件:${$componentClass?.name},childName:${$childName}`,
124
+ );
125
+ } else {
126
+ return;
127
+ }
128
+ }
129
+ this[$vo.propertyKey] =
130
+ node.getComponent($vo.compClass) || node.addComponent($vo.compClass);
131
+ });
132
+ oldOnLoad && oldOnLoad.apply(this);
133
+ };
134
+ }
135
+
136
+ const cache: {
137
+ propertyKey: string;
138
+ compClass: INewable<cc.Component>;
139
+ childName: string;
140
+ }[] = $target[KeyComp];
141
+
142
+ if (!cache.some(($vo) => $vo.propertyKey === $propertyKey)) {
143
+ cache.push({
144
+ propertyKey: $propertyKey,
145
+ compClass: $componentClass,
146
+ childName: $childName || $propertyKey,
147
+ });
148
+ } else {
149
+ if (!$mute) {
150
+ throw new Error(`component装饰器重复绑定属性:${$propertyKey},class:${$target.name}`);
151
+ }
152
+ return;
153
+ }
154
+ };
155
+ }
156
+
157
+ export function FWPropertyComponents(
158
+ $componentClass: INewable<cc.Component>,
159
+ $childName?: string,
160
+ ): FW.PropertyDecorator {
161
+ return ($target, $propertyKey: string, $descriptorOrInitializer) => {
162
+ const componentName = $childName || $propertyKey;
163
+ const oldOnLoad: () => void = $target.onLoad || undefined;
164
+ $target.onLoad = function () {
165
+ const components = this.node.getComponentsInChildren($componentClass);
166
+ if (components.length == 0) return;
167
+ this[$propertyKey] = components.filter((v) => {
168
+ return v.node.name == componentName;
169
+ });
170
+ oldOnLoad && oldOnLoad.apply(this);
171
+ };
172
+ };
173
+ }
174
+
175
+ export function isNull(message?: string) {
176
+ return function (target: any, propertyKey: string) {
177
+ let value: any;
178
+
179
+ const getter = function () {
180
+ return value;
181
+ };
182
+
183
+ const setter = function (newVal: any) {
184
+ if (newVal === null || newVal === undefined) {
185
+ const errorMsg = message || `${propertyKey} 不能为 null 或 undefined`;
186
+ console.error(errorMsg);
187
+ throw new Error(errorMsg);
188
+ }
189
+ value = newVal;
190
+ };
191
+
192
+ Object.defineProperty(target, propertyKey, {
193
+ get: getter,
194
+ set: setter,
195
+ enumerable: true,
196
+ configurable: true,
197
+ });
198
+ };
199
+ }
200
+
201
+ export function FWSocketAutoProcessPause() {
202
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
203
+ const originalMethod = descriptor.value;
204
+
205
+ descriptor.value = async function (...args: any[]) {
206
+ try {
207
+ const result = await originalMethod.apply(this, args);
208
+ return result;
209
+ } finally {
210
+ FW.Log.debug('暂停socket消息处理');
211
+ FW.Entry.socketMgr.resumeMessageHandle();
212
+ }
213
+ };
214
+
215
+ return descriptor;
216
+ };
217
+ }
218
+
219
+ export function FWDeprecated(description?: string) {
220
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
221
+ const originalMethod = descriptor.value;
222
+ descriptor.value = async function (...args: any[]) {
223
+ FW.Log.warn(`${propertyKey}方法已弃用!${description || ''}`);
224
+ originalMethod.apply(this, args);
225
+ };
226
+ return descriptor;
227
+ };
228
+ }
229
+
230
+ export function FWSocketAutoProcessResume() {
231
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
232
+ const originalMethod = descriptor.value;
233
+
234
+ descriptor.value = async function (...args: any[]) {
235
+ try {
236
+ const result = await originalMethod.apply(this, args);
237
+ return result;
238
+ } finally {
239
+ FW.Log.debug('恢复socket消息处理');
240
+ FW.Entry.socketMgr.resumeMessageHandle();
241
+ }
242
+ };
243
+
244
+ return descriptor;
245
+ };
246
+ }
247
+
248
+ export function RegisterEvents(events: FW.RegisterEventArgs[]) {
249
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
250
+ const originalMethod = descriptor.value;
251
+
252
+ descriptor.value = function (...args: any[]) {
253
+ if (this.registerEvent) {
254
+ this.registerEvent(events);
255
+ }
256
+ return originalMethod.apply(this, args);
257
+ };
258
+
259
+ return descriptor;
260
+ };
261
+ }
262
+
263
+ export function AutoRegisterCCEvent(nodePath: string, eventName?: string) {
264
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
265
+ const originalMethod = descriptor.value;
266
+ const originalOnInit = target.onInit;
267
+ const evt = eventName || cc.Node.EventType.TOUCH_END;
268
+
269
+ target.onInit = function () {
270
+ originalOnInit?.call(this);
271
+
272
+ let targetNode: cc.Node | null = null;
273
+
274
+ const cachedNodes = this[KeyChild] || [];
275
+ const cachedNode = cachedNodes.find((vo: any) => vo.childName === nodePath);
276
+
277
+ if (cachedNode && this[cachedNode.propertyKey]) {
278
+ targetNode = this[cachedNode.propertyKey];
279
+ } else {
280
+ targetNode = searchChild(this.layer?.node || this.node, nodePath);
281
+
282
+ if (targetNode && !cachedNode) {
283
+ const cacheKey = `_cached_${nodePath.replace(/\//g, '_')}`;
284
+ this[cacheKey] = targetNode;
285
+ if (!this[KeyChild]) this[KeyChild] = [];
286
+ this[KeyChild].push({
287
+ propertyKey: cacheKey,
288
+ childName: nodePath,
289
+ });
290
+ }
291
+ }
292
+
293
+ if (targetNode) {
294
+ this.registerEvent({
295
+ CCEvent: [
296
+ {
297
+ eventName: evt,
298
+ cb: originalMethod.bind(this),
299
+ target: targetNode,
300
+ },
301
+ ],
302
+ });
303
+ FW.Log.debug(`自动注册事件: ${nodePath} -> ${propertyKey}`);
304
+ } else {
305
+ FW.Log.warn(`自动注册事件失败: 未找到节点 ${nodePath}`);
306
+ }
307
+ };
308
+ };
309
+ }
310
+
311
+ export function AutoRegisterFWEvent(eventName: any) {
312
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
313
+ const originalMethod = descriptor.value;
314
+ const originalOnInit = target.onInit;
315
+
316
+ target.onInit = function (...args) {
317
+ originalOnInit?.call(this, args);
318
+ this.registerEvent({
319
+ CCEvent: [
320
+ {
321
+ eventName: eventName,
322
+ cb: originalMethod.bind(this),
323
+ target: this,
324
+ },
325
+ ],
326
+ });
327
+ };
328
+ };
329
+ }
330
+
331
+ export function PerformanceMonitor(operationName?: string) {
332
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
333
+ const originalMethod = descriptor.value;
334
+
335
+ descriptor.value = async function (...args: any[]) {
336
+ const startTime = Date.now();
337
+ const moduleName = target.constructor.name;
338
+ let methodName = propertyKey;
339
+
340
+ if (args && args[0].type) {
341
+ methodName = `${methodName}->${args[0]?.type?.name}`;
342
+ } else {
343
+ methodName = operationName || propertyKey;
344
+ }
345
+
346
+ try {
347
+ const result = await originalMethod.apply(this, args);
348
+ const duration = Date.now() - startTime;
349
+
350
+ FW.Entry.performanceMgr?.recordOperationMetric(moduleName, methodName, duration);
351
+
352
+ if (duration > 100) {
353
+ FW.Log.warn(`[${moduleName}] ${methodName} took ${duration}ms`);
354
+ }
355
+
356
+ return result;
357
+ } catch (error) {
358
+ const duration = Date.now() - startTime;
359
+ FW.Entry.performanceMgr?.recordOperationMetric(moduleName, `${methodName}_error`, duration);
360
+ throw error;
361
+ }
362
+ };
363
+
364
+ return descriptor;
365
+ };
366
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "96d84c32-0f47-4743-bf8f-9a72adda6f7f",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
+ }