@ives_xxz/framework 1.0.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.
Files changed (139) hide show
  1. package/FW.d.ts +1845 -0
  2. package/FW.d.ts.meta +6 -0
  3. package/Framework.ts +148 -0
  4. package/Framework.ts.meta +10 -0
  5. package/README.md +93 -0
  6. package/README.md.meta +6 -0
  7. package/animation/FWAnimation.ts +13 -0
  8. package/animation/FWAnimation.ts.meta +10 -0
  9. package/animation/FWSkeleton.ts +176 -0
  10. package/animation/FWSkeleton.ts.meta +10 -0
  11. package/animation/FWTween.ts +60 -0
  12. package/animation/FWTween.ts.meta +10 -0
  13. package/animation.meta +13 -0
  14. package/component/FWVirtualViewComponent.ts +2080 -0
  15. package/component/FWVirtualViewComponent.ts.meta +10 -0
  16. package/component.meta +13 -0
  17. package/config/FWAssetConfig.ts +7 -0
  18. package/config/FWAssetConfig.ts.meta +10 -0
  19. package/config.meta +13 -0
  20. package/controller/FWLayerController.ts +236 -0
  21. package/controller/FWLayerController.ts.meta +10 -0
  22. package/controller.meta +13 -0
  23. package/data/FWData.ts +10 -0
  24. package/data/FWData.ts.meta +10 -0
  25. package/data.meta +13 -0
  26. package/define/FWEventDefine.ts +26 -0
  27. package/define/FWEventDefine.ts.meta +10 -0
  28. package/define/FWSystemDefine.ts +133 -0
  29. package/define/FWSystemDefine.ts.meta +10 -0
  30. package/define.meta +13 -0
  31. package/entry/FWEntry.ts +196 -0
  32. package/entry/FWEntry.ts.meta +10 -0
  33. package/entry.meta +13 -0
  34. package/expand/FWCocosExpand.ts +73 -0
  35. package/expand/FWCocosExpand.ts.meta +10 -0
  36. package/expand/FWDecorator.ts +256 -0
  37. package/expand/FWDecorator.ts.meta +10 -0
  38. package/expand/FWRollingViewNesting.ts +191 -0
  39. package/expand/FWRollingViewNesting.ts.meta +10 -0
  40. package/expand/FWTweenExpand.ts +44 -0
  41. package/expand/FWTweenExpand.ts.meta +10 -0
  42. package/expand.meta +13 -0
  43. package/item/FWVirtualListItem.ts +150 -0
  44. package/item/FWVirtualListItem.ts.meta +10 -0
  45. package/item.meta +13 -0
  46. package/language/FWLanguage.ts +69 -0
  47. package/language/FWLanguage.ts.meta +10 -0
  48. package/language/FWLanguageLabelLocalize.ts +144 -0
  49. package/language/FWLanguageLabelLocalize.ts.meta +10 -0
  50. package/language/FWLanguageSkeletonLocalize.ts +106 -0
  51. package/language/FWLanguageSkeletonLocalize.ts.meta +10 -0
  52. package/language/FWLanguageSpriteLocalize.ts +81 -0
  53. package/language/FWLanguageSpriteLocalize.ts.meta +10 -0
  54. package/language.meta +13 -0
  55. package/layer/FWLayer.ts +13 -0
  56. package/layer/FWLayer.ts.meta +10 -0
  57. package/layer.meta +13 -0
  58. package/log/FWLog.ts +115 -0
  59. package/log/FWLog.ts.meta +10 -0
  60. package/log.meta +13 -0
  61. package/logic/FWLogic.ts +10 -0
  62. package/logic/FWLogic.ts.meta +10 -0
  63. package/logic.meta +13 -0
  64. package/machine/FWAnimationMachine.ts +28 -0
  65. package/machine/FWAnimationMachine.ts.meta +10 -0
  66. package/machine/FWStateMachine.ts +75 -0
  67. package/machine/FWStateMachine.ts.meta +10 -0
  68. package/machine.meta +13 -0
  69. package/manager/FWAnimationManager.ts +128 -0
  70. package/manager/FWAnimationManager.ts.meta +10 -0
  71. package/manager/FWAssetManager.ts +349 -0
  72. package/manager/FWAssetManager.ts.meta +10 -0
  73. package/manager/FWAudioManager.ts +289 -0
  74. package/manager/FWAudioManager.ts.meta +10 -0
  75. package/manager/FWBundleManager.ts +91 -0
  76. package/manager/FWBundleManager.ts.meta +10 -0
  77. package/manager/FWComponentManager.ts +25 -0
  78. package/manager/FWComponentManager.ts.meta +10 -0
  79. package/manager/FWEngineManager.ts +63 -0
  80. package/manager/FWEngineManager.ts.meta +10 -0
  81. package/manager/FWEventManager.ts +275 -0
  82. package/manager/FWEventManager.ts.meta +10 -0
  83. package/manager/FWHotUpdateManager.ts +213 -0
  84. package/manager/FWHotUpdateManager.ts.meta +10 -0
  85. package/manager/FWLanguageManager.ts +116 -0
  86. package/manager/FWLanguageManager.ts.meta +10 -0
  87. package/manager/FWLayerManager.ts +490 -0
  88. package/manager/FWLayerManager.ts.meta +10 -0
  89. package/manager/FWManager.ts +8 -0
  90. package/manager/FWManager.ts.meta +10 -0
  91. package/manager/FWObjectManager.ts +91 -0
  92. package/manager/FWObjectManager.ts.meta +10 -0
  93. package/manager/FWResManager.ts +171 -0
  94. package/manager/FWResManager.ts.meta +10 -0
  95. package/manager/FWSocketManager.ts +94 -0
  96. package/manager/FWSocketManager.ts.meta +10 -0
  97. package/manager/FWStateManager.ts +102 -0
  98. package/manager/FWStateManager.ts.meta +10 -0
  99. package/manager/FWTaskManager.ts +38 -0
  100. package/manager/FWTaskManager.ts.meta +10 -0
  101. package/manager/FWTimeManager.ts +473 -0
  102. package/manager/FWTimeManager.ts.meta +10 -0
  103. package/manager/FWUiManager.ts +164 -0
  104. package/manager/FWUiManager.ts.meta +10 -0
  105. package/manager.meta +13 -0
  106. package/package.json +17 -0
  107. package/package.json.meta +6 -0
  108. package/scene/FWScene.ts +25 -0
  109. package/scene/FWScene.ts.meta +10 -0
  110. package/scene.meta +13 -0
  111. package/service/FWService.ts +7 -0
  112. package/service/FWService.ts.meta +10 -0
  113. package/service/http/FWHttp.ts +70 -0
  114. package/service/http/FWHttp.ts.meta +10 -0
  115. package/service/http.meta +13 -0
  116. package/service/socket/FWSocket.ts +236 -0
  117. package/service/socket/FWSocket.ts.meta +10 -0
  118. package/service/socket/FWSocketHandle.ts +17 -0
  119. package/service/socket/FWSocketHandle.ts.meta +10 -0
  120. package/service/socket/FWSocketSender.ts +16 -0
  121. package/service/socket/FWSocketSender.ts.meta +10 -0
  122. package/service/socket.meta +13 -0
  123. package/service.meta +13 -0
  124. package/state/FWState.ts +8 -0
  125. package/state/FWState.ts.meta +10 -0
  126. package/state.meta +13 -0
  127. package/utils/FWLodash.ts +105 -0
  128. package/utils/FWLodash.ts.meta +10 -0
  129. package/utils/FWMask.ts +222 -0
  130. package/utils/FWMask.ts.meta +10 -0
  131. package/utils/FWObject.ts +22 -0
  132. package/utils/FWObject.ts.meta +10 -0
  133. package/utils/FWObjectPool.ts +178 -0
  134. package/utils/FWObjectPool.ts.meta +10 -0
  135. package/utils/FWQueue.ts +47 -0
  136. package/utils/FWQueue.ts.meta +10 -0
  137. package/utils/FWTask.ts +223 -0
  138. package/utils/FWTask.ts.meta +10 -0
  139. package/utils.meta +13 -0
@@ -0,0 +1,196 @@
1
+ import FWUiManager from '../manager/FWUiManager';
2
+ import Framework from '../Framework';
3
+ import FWLog from '../log/FWLog';
4
+ import FWAnimationManager from '../manager/FWAnimationManager';
5
+ import FWAudioManager from '../manager/FWAudioManager';
6
+ import FWComponentManager from '../manager/FWComponentManager';
7
+ import FWEventManager from '../manager/FWEventManager';
8
+ import FWLanguageManager from '../manager/FWLanguageManager';
9
+ import { FWLayerManager } from '../manager/FWLayerManager';
10
+ import FWObjectManager from '../manager/FWObjectManager';
11
+ import { FWResManager } from '../manager/FWResManager';
12
+ import FWSocketManager from '../manager/FWSocketManager';
13
+ import { FWStateManager } from '../manager/FWStateManager';
14
+ import { FWTimeManager } from '../manager/FWTimeManager';
15
+ import FWScene from '../scene/FWScene';
16
+ import { FWSocketAutoProcessPause } from '../expand/FWDecorator';
17
+ import { FWEventDefine } from '../define/FWEventDefine';
18
+ import FWTaskManager from '../manager/FWTaskManager';
19
+ import FWEngineManager from '../manager/FWEngineManager';
20
+ import FWHotUpdateManager from '../manager/FWHotUpdateManager';
21
+
22
+ /**
23
+ * 入口脚本
24
+ */
25
+ export default class FWEntry implements FW.Entry {
26
+ map: Map<string, FW.RegisterBundle>;
27
+ /**
28
+ * 事件管理器
29
+ */
30
+ timeMgr: FW.TimeManager;
31
+ /**
32
+ * 层级管理器
33
+ */
34
+ layerMgr: FW.LayerManager;
35
+ /**
36
+ * 资源管理器
37
+ */
38
+ resMgr: FW.ResManager;
39
+ /**
40
+ * 动画管理器
41
+ */
42
+ animationMgr: FW.AnimationManager;
43
+ /**
44
+ * 状态管理器
45
+ */
46
+ stateMgr: FW.StateManager;
47
+ /**
48
+ * 音效管理器
49
+ */
50
+ audioMgr: FW.AudioManager;
51
+ /**
52
+ * socket管理器
53
+ */
54
+ socketMgr: FW.SocketManager;
55
+ /**
56
+ * 对象管理器
57
+ */
58
+ objectMgr: FW.ObjectManager;
59
+ /**
60
+ * 事件管理器
61
+ */
62
+ evtMgr: FW.EventManager;
63
+ /**
64
+ * UI管理器
65
+ */
66
+ uiMgr: FW.UiManager;
67
+ /**
68
+ * 任务管理器
69
+ */
70
+ taskMgr: FW.TaskManager;
71
+ /**
72
+ * 组件管理器
73
+ */
74
+ componentMgr: FWComponentManager;
75
+ /**
76
+ * 多语言管理器
77
+ */
78
+ languageMgr: FW.LanguageManager;
79
+ /**
80
+ * 引擎管理器
81
+ */
82
+ engineMgr: FW.EngineManager;
83
+ /**
84
+ * 热更新管理器
85
+ */
86
+ hotUpdateMgr: FW.HotUpdateManager;
87
+ /**
88
+ * 当前Scene
89
+ */
90
+ scene: FWScene;
91
+ /**
92
+ * bundle名字
93
+ */
94
+ bundleName: string;
95
+
96
+ /**
97
+ * 初始化
98
+ * */
99
+ initialize() {
100
+ this.map = new Map<string, FW.RegisterBundle>();
101
+ this.engineMgr = new FWEngineManager();
102
+ this.taskMgr = new FWTaskManager();
103
+ this.evtMgr = new FWEventManager();
104
+ this.resMgr = new FWResManager();
105
+ this.layerMgr = new FWLayerManager();
106
+ this.timeMgr = new FWTimeManager();
107
+ this.uiMgr = new FWUiManager();
108
+ this.animationMgr = new FWAnimationManager();
109
+ this.stateMgr = new FWStateManager();
110
+ this.audioMgr = new FWAudioManager();
111
+ this.objectMgr = new FWObjectManager();
112
+ this.socketMgr = new FWSocketManager();
113
+ this.componentMgr = new FWComponentManager();
114
+ this.languageMgr = new FWLanguageManager();
115
+ this.hotUpdateMgr = new FWHotUpdateManager();
116
+
117
+ this.resMgr.initialize();
118
+ this.layerMgr.initialize();
119
+ this.timeMgr.initialize();
120
+ this.animationMgr.initialize();
121
+ this.stateMgr.initialize();
122
+ }
123
+
124
+ /**
125
+ * 启动场景
126
+ * @param bundleName bundle名字
127
+ * @param sceneName 场景名字
128
+ */
129
+ @FWSocketAutoProcessPause()
130
+ launchScene(name: string): void {
131
+ FW.Entry.layerMgr.clear();
132
+ if (!this.hasSceneName(name)) {
133
+ try {
134
+ cc.director.loadScene(name);
135
+ return;
136
+ } catch (e) {
137
+ FWLog.error('launchScene failed:', name);
138
+ }
139
+ }
140
+ if (this.bundleAutoRelease(this.bundleName)) {
141
+ this.releaseBundle(this.bundleName);
142
+ }
143
+ this.bundleName = name;
144
+ cc.director.loadScene(this.getSceneName());
145
+ }
146
+
147
+ releaseBundle(bundleName: string) {
148
+ this.resMgr.releaseBundle(bundleName);
149
+ this.evtMgr.dispatch(`${FWEventDefine.SystemEvent.BUNDLE_RELEASE}-${bundleName}`);
150
+ }
151
+
152
+ register(data: FW.RegisterBundle) {
153
+ this.map.set(data.bundleName, data);
154
+ }
155
+
156
+ bundleAutoRelease(bundleName: string) {
157
+ const autoRelease = this.map.get(bundleName)?.autoRelease;
158
+ return autoRelease === undefined ? true : autoRelease;
159
+ }
160
+
161
+ getDepend(bundleName: string) {
162
+ return this.map.get(bundleName)?.depend || [];
163
+ }
164
+
165
+ hasSceneName(sceneName: string) {
166
+ return this.map.has(sceneName);
167
+ }
168
+
169
+ getSceneName() {
170
+ return this.map.get(this.bundleName)?.sceneName || undefined;
171
+ }
172
+
173
+ getComponent: <T>(serviceIdentifier: FW.ServiceIdentifier<T>) => T = (serviceIdentifier) =>
174
+ Framework.getComponent(serviceIdentifier);
175
+
176
+ getComponents: <T>(serviceIdentifier?: FW.ServiceIdentifier<T>) => T[] = (serviceIdentifier) =>
177
+ Framework.getComponents(serviceIdentifier);
178
+
179
+ onDestroy() {
180
+ this.resMgr.onDestroy();
181
+ this.layerMgr.onDestroy();
182
+ this.timeMgr.onDestroy();
183
+ this.animationMgr.onDestroy();
184
+ this.stateMgr.onDestroy();
185
+
186
+ this.resMgr = null;
187
+ this.layerMgr = null;
188
+ this.timeMgr = null;
189
+ this.animationMgr = null;
190
+ this.stateMgr = null;
191
+ }
192
+
193
+ update(dt: number) {
194
+ this.timeMgr?.onUpdate(dt);
195
+ }
196
+ }
@@ -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,256 @@
1
+ import 'reflect-metadata';
2
+ import FWLog from '../log/FWLog';
3
+
4
+ type PropertyDecorator = (
5
+ $class: Record<string, any>,
6
+ $propertyKey: string | symbol,
7
+ $descriptorOrInitializer?: any,
8
+ ) => void;
9
+
10
+ const searchChild = function (node: cc.Node, name: string) {
11
+ let ret = node.getChildByName(name);
12
+ if (ret) return ret;
13
+ for (let i = 0; i < node.children.length; i++) {
14
+ let child = node.children[i];
15
+ if (!child.isValid) continue;
16
+ ret = searchChild(child, name);
17
+ if (ret) return ret;
18
+ }
19
+ return null;
20
+ };
21
+
22
+ const CookDecoratorKey = ($desc: string) => `__ccc_decorator_${$desc}__`;
23
+
24
+ const KeyChild = CookDecoratorKey('child_cache');
25
+
26
+ type ParamType = {
27
+ path?: string;
28
+ };
29
+
30
+ export function FWPropertyNode($opt?: ParamType): PropertyDecorator {
31
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
+ return ($target, $propertyKey: string, $descriptorOrInitializer) => {
33
+ const cache: { propertyKey: string; childName: string }[] = ($target[KeyChild] ??= []);
34
+ if (!cache.some(($vo) => $vo.propertyKey === $propertyKey)) {
35
+ cache.push({
36
+ propertyKey: $propertyKey,
37
+ childName: $opt?.path || $propertyKey,
38
+ });
39
+ } else {
40
+ throw new Error(`child 装饰器重复绑定属性:${$propertyKey},class:${$target?.name}`);
41
+ }
42
+ if (cache.length === 1) {
43
+ const oldOnLoad: () => void = $target.onLoad || undefined;
44
+ $target.onLoad = function () {
45
+ cache.forEach(($vo) => (this[$vo.propertyKey] = searchChild(this.node, $vo.childName)));
46
+ oldOnLoad && oldOnLoad.apply(this);
47
+ };
48
+ }
49
+ };
50
+ }
51
+
52
+ const KeyChildMulti = CookDecoratorKey('child_cache_multi'); // 重新定义 Key,避免冲突
53
+
54
+ /** 查找多个节点,并存储为数组 */
55
+ export function FWPropertyNodes(...paths: string[]): PropertyDecorator {
56
+ return ($target: any, $propertyKey: string) => {
57
+ // 确保 $target[KeyChild] 是数组
58
+ if (!$target[KeyChildMulti]) {
59
+ $target[KeyChildMulti] = [];
60
+ }
61
+
62
+ const cache: { propertyKey: string; childNames: string[] }[] = $target[KeyChildMulti];
63
+
64
+ // 查找是否已经存在该属性的绑定
65
+ const existingEntry = cache.find(($vo) => $vo.propertyKey === $propertyKey);
66
+
67
+ // 如果没有找到绑定,则添加
68
+ if (!existingEntry) {
69
+ cache.push({
70
+ propertyKey: $propertyKey,
71
+ childNames: paths,
72
+ });
73
+ } else {
74
+ throw new Error(
75
+ `child 装饰器重复绑定属性:${$propertyKey}, class:${$target.constructor.name}`,
76
+ );
77
+ }
78
+
79
+ // 确保只绑定一次 onLoad,防止重复调用
80
+ if (cache.length === 1) {
81
+ const oldOnLoad = $target.onLoad;
82
+
83
+ $target.onLoad = function () {
84
+ if (!this.node) {
85
+ console.error(`this.node 为空,无法查找子节点`, this);
86
+ return;
87
+ }
88
+ cache.forEach(($vo) => {
89
+ const nodes: cc.Node[] = [];
90
+
91
+ // 将所有路径对应的节点存入数组
92
+ $vo.childNames.forEach((childName) => {
93
+ const childNode = searchChild(this.node, childName);
94
+ if (!childNode) {
95
+ console.warn(`未找到子节点:${childName}`);
96
+ } else {
97
+ nodes.push(childNode);
98
+ }
99
+ });
100
+
101
+ // 将结果赋值为数组,保证拿到所有节点
102
+ this[$vo.propertyKey] = nodes;
103
+ });
104
+
105
+ // 调用父类 onLoad 方法
106
+ if (oldOnLoad) {
107
+ oldOnLoad.apply(this);
108
+ }
109
+ };
110
+ }
111
+ };
112
+ }
113
+
114
+ interface INewable<T = any> extends Function {
115
+ new (...args: any[]): T;
116
+ }
117
+
118
+ const KeyComp = CookDecoratorKey('comp_cache');
119
+
120
+ export function FWPropertyComponent(
121
+ $componentClass: INewable<cc.Component>,
122
+ $childName?: string,
123
+ $mute = false,
124
+ ): PropertyDecorator {
125
+ return ($target, $propertyKey: string, $descriptorOrInitializer) => {
126
+ const cache: {
127
+ propertyKey: string;
128
+ compClass: INewable<cc.Component>;
129
+ childName: string;
130
+ }[] = ($target[KeyComp] ??= []);
131
+ if (!cache.some(($vo) => $vo.propertyKey === $propertyKey)) {
132
+ cache.push({
133
+ propertyKey: $propertyKey,
134
+ compClass: $componentClass,
135
+ childName: $childName || $propertyKey,
136
+ });
137
+ } else {
138
+ if (!$mute) {
139
+ throw new Error(`component装饰器重复绑定属性:${$propertyKey},class:${$target.name}`);
140
+ }
141
+ return;
142
+ }
143
+ if (cache.length === 1) {
144
+ const oldOnLoad: () => void = $target.onLoad || undefined; //$target.onLoad也可以拿到父类的实现
145
+ $target.onLoad = function () {
146
+ cache.forEach(($vo) => {
147
+ const node = $vo.childName ? searchChild(this.node, $vo.childName) : this.node;
148
+ if (!node) {
149
+ if (!$mute) {
150
+ throw new Error(
151
+ `component装饰器没有找到适合的node节点:class:${$target?.name},组件:${$componentClass?.name},childName:${$childName}`,
152
+ );
153
+ } else {
154
+ return;
155
+ }
156
+ }
157
+ this[$vo.propertyKey] =
158
+ node.getComponent($vo.compClass) || node.addComponent($vo.compClass);
159
+ });
160
+ oldOnLoad && oldOnLoad.apply(this);
161
+ };
162
+ }
163
+ };
164
+ }
165
+
166
+ export function FWPropertyComponents(
167
+ $componentClass: INewable<cc.Component>,
168
+ $childName?: string,
169
+ ): PropertyDecorator {
170
+ return ($target, $propertyKey: string, $descriptorOrInitializer) => {
171
+ const componentName = $childName || $propertyKey;
172
+ const oldOnLoad: () => void = $target.onLoad || undefined; //$target.onLoad也可以拿到父类的实现
173
+ $target.onLoad = function () {
174
+ const components = this.node.getComponentsInChildren($componentClass);
175
+ if (components.length == 0) return;
176
+ this[$propertyKey] = components.filter((v) => {
177
+ return v.node.name == componentName;
178
+ });
179
+ oldOnLoad && oldOnLoad.apply(this);
180
+ };
181
+ };
182
+ }
183
+
184
+ /** 判断是否为空 */
185
+ export function isNull(message?: string) {
186
+ return function (target: any, propertyKey: string) {
187
+ let value: any;
188
+
189
+ const getter = function () {
190
+ return value;
191
+ };
192
+
193
+ const setter = function (newVal: any) {
194
+ if (newVal === null || newVal === undefined) {
195
+ const errorMsg = message || `${propertyKey} 不能为 null 或 undefined`;
196
+ console.error(errorMsg);
197
+ throw new Error(errorMsg);
198
+ }
199
+ value = newVal;
200
+ };
201
+
202
+ // 使用 defineProperty 来替换原来的属性
203
+ Object.defineProperty(target, propertyKey, {
204
+ get: getter,
205
+ set: setter,
206
+ enumerable: true,
207
+ configurable: true,
208
+ });
209
+ };
210
+ }
211
+
212
+ export function FWSocketAutoProcessPause() {
213
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
214
+ const originalMethod = descriptor.value;
215
+
216
+ descriptor.value = async function (...args: any[]) {
217
+ try {
218
+ const result = await originalMethod.apply(this, args);
219
+ return result;
220
+ } finally {
221
+ FWLog.debug('暂停socket消息处理');
222
+ FW.Entry.socketMgr.resumeMessageHandle();
223
+ }
224
+ };
225
+
226
+ return descriptor;
227
+ };
228
+ }
229
+
230
+ export function FWDeprecated(description?: string) {
231
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
232
+ const originalMethod = descriptor.value;
233
+ descriptor.value = async function (...args: any[]) {
234
+ FWLog.warn(`${propertyKey}方法已弃用!${description || ''}`);
235
+ originalMethod.apply(this, args);
236
+ };
237
+ return descriptor;
238
+ };
239
+ }
240
+ export function FWSocketAutoProcessResume() {
241
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
242
+ const originalMethod = descriptor.value;
243
+
244
+ descriptor.value = async function (...args: any[]) {
245
+ try {
246
+ const result = await originalMethod.apply(this, args);
247
+ return result;
248
+ } finally {
249
+ FWLog.debug('恢复socket消息处理');
250
+ FW.Entry.socketMgr.resumeMessageHandle();
251
+ }
252
+ };
253
+
254
+ return descriptor;
255
+ };
256
+ }
@@ -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
+ }