@ives_xxz/framework 2.1.30 → 2.1.31

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/Framework.ts CHANGED
@@ -1,5 +1,5 @@
1
- import 'reflect-metadata';
2
- import { Container, interfaces } from 'inversify';
1
+ import "reflect-metadata";
2
+ import { Container, interfaces } from "inversify";
3
3
 
4
4
  export class Framework implements FW.Framework {
5
5
  private container: Container;
@@ -8,7 +8,7 @@ export class Framework implements FW.Framework {
8
8
 
9
9
  initialize() {
10
10
  this.container = new Container({
11
- defaultScope: 'Singleton',
11
+ defaultScope: "Singleton",
12
12
  autoBindInjectable: true,
13
13
  });
14
14
  this.registry = new Map<string, new () => FW.Registry>();
@@ -21,11 +21,11 @@ export class Framework implements FW.Framework {
21
21
 
22
22
  /** 获取组件 */
23
23
  public getComponent<T>(serviceIdentifier: FW.ServiceIdentifier<T>): T {
24
- if (typeof serviceIdentifier === 'string') {
24
+ if (typeof serviceIdentifier === "string") {
25
25
  if (this.container.isBound(serviceIdentifier)) {
26
26
  return this.container.get<T>(serviceIdentifier);
27
27
  }
28
- } else if (typeof serviceIdentifier === 'function') {
28
+ } else if (typeof serviceIdentifier === "function") {
29
29
  const className = serviceIdentifier.name;
30
30
 
31
31
  if (this.container.isBound(serviceIdentifier)) {
@@ -40,7 +40,9 @@ export class Framework implements FW.Framework {
40
40
  Handle: FW.SystemDefine.FWBindTag.HANDLE,
41
41
  };
42
42
 
43
- const [suffix] = Object.entries(suffixMap).find(([key]) => className.endsWith(key)) || [];
43
+ const [suffix] =
44
+ Object.entries(suffixMap).find(([key]) => className.endsWith(key)) ||
45
+ [];
44
46
 
45
47
  if (suffix) {
46
48
  const bundleName = FW.Entry.bundleName;
@@ -116,7 +118,10 @@ export class Framework implements FW.Framework {
116
118
  */
117
119
  createRegistry(bundleName: string): FW.Registry {
118
120
  if (!this.registry.has(bundleName)) return;
119
- this.container.bind(this.registry.get(bundleName)).toSelf().inSingletonScope();
121
+ this.container
122
+ .bind(this.registry.get(bundleName))
123
+ .toSelf()
124
+ .inSingletonScope();
120
125
  return this.getRegistry(bundleName);
121
126
  }
122
127
 
@@ -134,7 +139,13 @@ export class Framework implements FW.Framework {
134
139
  * @param data
135
140
  */
136
141
  register(data: FW.RegisterFramework) {
137
- const classes = [data.logic, data.data, data.config, data.sender, data.handle];
142
+ const classes = [
143
+ data.logic,
144
+ data.data,
145
+ data.config,
146
+ data.sender,
147
+ data.handle,
148
+ ];
138
149
  classes.forEach((cls, index) => {
139
150
  if (cls && !this.container.isBound(cls)) {
140
151
  this.container.bind(cls).toSelf().inSingletonScope();
@@ -150,7 +161,10 @@ export class Framework implements FW.Framework {
150
161
  const instance = this.container.get(cls) as FW.FrameworkBase;
151
162
  instance?.initializeDependencies?.();
152
163
  } catch (error) {
153
- FW.Log.warn(`Error initializing dependencies for ${cls.name}:`, error);
164
+ FW.Log.warn(
165
+ `Error initializing dependencies for ${cls.name}:`,
166
+ error,
167
+ );
154
168
  }
155
169
  }
156
170
  });
@@ -162,15 +176,21 @@ export class Framework implements FW.Framework {
162
176
  * @returns
163
177
  */
164
178
  unRegister(data: FW.RegisterFramework) {
165
- const classes = [data.logic, data.data, data.config, data.sender, data.handle];
179
+ const classes = [
180
+ data.logic,
181
+ data.data,
182
+ data.config,
183
+ data.sender,
184
+ data.handle,
185
+ ];
166
186
  classes.forEach((cls, index) => {
167
187
  const key = this.getKey(data.bundleName, index);
168
188
  if (cls && this.container.isBound(cls)) {
169
- this.container.get(key)?.['onDestroy']?.();
189
+ this.container.get(key)?.["onDestroy"]?.();
170
190
  this.container.unbind(cls);
171
191
  }
172
192
  if (this.container.isBound(key)) {
173
- this.container.get(key)?.['onDestroy']?.();
193
+ this.container.get(key)?.["onDestroy"]?.();
174
194
  this.container.unbind(this.getKey(data.bundleName, index));
175
195
  }
176
196
  });
@@ -193,7 +213,10 @@ export class Framework implements FW.Framework {
193
213
  if (!registrations) return;
194
214
 
195
215
  const exists = registrations.some(
196
- (reg) => reg.logic === data.logic && reg.data === data.data && reg.config === data.config,
216
+ (reg) =>
217
+ reg.logic === data.logic &&
218
+ reg.data === data.data &&
219
+ reg.config === data.config,
197
220
  );
198
221
 
199
222
  if (!exists) {
@@ -206,7 +229,10 @@ export class Framework implements FW.Framework {
206
229
  if (this.registeredComponents.has(bundleName)) {
207
230
  const registrations = this.registeredComponents.get(bundleName)!;
208
231
  const index = registrations.findIndex(
209
- (reg) => reg.logic === data.logic && reg.data === data.data && reg.config === data.config,
232
+ (reg) =>
233
+ reg.logic === data.logic &&
234
+ reg.data === data.data &&
235
+ reg.config === data.config,
210
236
  );
211
237
 
212
238
  if (index !== -1) {
@@ -223,7 +249,7 @@ export class Framework implements FW.Framework {
223
249
  this.destroyAllComponents();
224
250
  this.container.unbindAll();
225
251
  this.container = new Container({
226
- defaultScope: 'Singleton',
252
+ defaultScope: "Singleton",
227
253
  autoBindInjectable: true,
228
254
  });
229
255
  this.reregisterAllComponents();
@@ -238,7 +264,7 @@ export class Framework implements FW.Framework {
238
264
  try {
239
265
  if (this.container.isBound(binding.serviceIdentifier)) {
240
266
  const instance = this.container.get(binding.serviceIdentifier);
241
- instance?.['onDestroy']?.();
267
+ instance?.["onDestroy"]?.();
242
268
  }
243
269
  } catch (e) {
244
270
  FW.Log.warn(`Error destroying component ${key}:`, e);
@@ -248,12 +274,18 @@ export class Framework implements FW.Framework {
248
274
  }
249
275
 
250
276
  private reregisterAllComponents(): void {
251
- for (const [bundleName, registrations] of this.registeredComponents.entries()) {
277
+ for (const [
278
+ bundleName,
279
+ registrations,
280
+ ] of this.registeredComponents.entries()) {
252
281
  for (const data of registrations) {
253
282
  try {
254
283
  this.register(data);
255
284
  } catch (e) {
256
- console.error(`Error re-registering component for bundle ${bundleName}:`, e);
285
+ console.error(
286
+ `Error re-registering component for bundle ${bundleName}:`,
287
+ e,
288
+ );
257
289
  }
258
290
  }
259
291
  }
@@ -268,7 +300,7 @@ export class Framework implements FW.Framework {
268
300
  }
269
301
 
270
302
  private isSubclassOf(child: any, parent: any): boolean {
271
- if (typeof child !== 'function' || typeof parent !== 'function') {
303
+ if (typeof child !== "function" || typeof parent !== "function") {
272
304
  return false;
273
305
  }
274
306
  let current = child;
package/FrameworkBase.ts CHANGED
@@ -2,7 +2,7 @@ import { injectable } from "inversify";
2
2
 
3
3
  @injectable()
4
4
  export abstract class FrameworkBase {
5
- public logic?: FW.Logic;
5
+ public _logic?: FW.Logic;
6
6
  public data?: FW.Data;
7
7
  public config?: FW.AssetConfig;
8
8
  public sender?: FW.Sender;
@@ -16,12 +16,20 @@ export abstract class FrameworkBase {
16
16
  return FW.Entry;
17
17
  }
18
18
 
19
+ get logic() {
20
+ return this._logic;
21
+ }
22
+
23
+ set logic(value: FW.Logic) {
24
+ this._logic = value;
25
+ }
26
+
19
27
  constructor() {
20
28
  this.initialize?.();
21
29
  this.entry.evtMgr.register(
22
30
  FW.EventDefine.SystemEvent.SYSTEM_RESTART,
23
31
  this.onRestart,
24
- this
32
+ this,
25
33
  );
26
34
  }
27
35
 
@@ -62,38 +70,38 @@ export abstract class FrameworkBase {
62
70
 
63
71
  if (tag !== FW.SystemDefine.FWBindTag.LOGIC) {
64
72
  this.logic = FW.Framework.getComponent<FW.Logic>(
65
- `${bundleName}${FW.SystemDefine.FWBindTag.LOGIC}`
73
+ `${bundleName}${FW.SystemDefine.FWBindTag.LOGIC}`,
66
74
  );
67
75
  }
68
76
 
69
77
  if (tag !== FW.SystemDefine.FWBindTag.DATA) {
70
78
  this.data = FW.Framework.getComponent<FW.Data>(
71
- `${bundleName}${FW.SystemDefine.FWBindTag.DATA}`
79
+ `${bundleName}${FW.SystemDefine.FWBindTag.DATA}`,
72
80
  );
73
81
  }
74
82
 
75
83
  if (tag !== FW.SystemDefine.FWBindTag.CONFIG) {
76
84
  this.config = FW.Framework.getComponent<FW.AssetConfig>(
77
- `${bundleName}${FW.SystemDefine.FWBindTag.CONFIG}`
85
+ `${bundleName}${FW.SystemDefine.FWBindTag.CONFIG}`,
78
86
  );
79
87
  }
80
88
 
81
89
  if (tag !== FW.SystemDefine.FWBindTag.SENDER) {
82
90
  this.sender = FW.Framework.getComponent<FW.Sender>(
83
- `${bundleName}${FW.SystemDefine.FWBindTag.SENDER}`
91
+ `${bundleName}${FW.SystemDefine.FWBindTag.SENDER}`,
84
92
  );
85
93
  }
86
94
 
87
95
  if (tag !== FW.SystemDefine.FWBindTag.HANDLE) {
88
96
  this.handle = FW.Framework.getComponent<FW.Handle>(
89
- `${bundleName}${FW.SystemDefine.FWBindTag.HANDLE}`
97
+ `${bundleName}${FW.SystemDefine.FWBindTag.HANDLE}`,
90
98
  );
91
99
  }
92
100
  }
93
101
 
94
102
  protected async invoke<T>(
95
103
  operation: Promise<T>,
96
- operationName: string = "unknown"
104
+ operationName: string = "unknown",
97
105
  ): Promise<T> {
98
106
  const startTime = this.getCurrentTime();
99
107
 
@@ -110,13 +118,13 @@ export abstract class FrameworkBase {
110
118
 
111
119
  private recordPerformanceMetric(
112
120
  operationName: string,
113
- duration: number
121
+ duration: number,
114
122
  ): void {
115
123
  if (FW.Entry.performanceMgr) {
116
124
  FW.Entry.performanceMgr.recordOperationMetric(
117
125
  this.moduleName,
118
126
  operationName,
119
- duration
127
+ duration,
120
128
  );
121
129
  }
122
130
 
@@ -125,7 +133,7 @@ export abstract class FrameworkBase {
125
133
  if (FW.Entry.engineMgr.debug || shouldWarn) {
126
134
  const log = shouldWarn ? FW.Log.warn : FW.Log.debug;
127
135
  log(
128
- `[${this.moduleName?.toUpperCase()}] Operation ${operationName} took ${duration}ms`
136
+ `[${this.moduleName?.toUpperCase()}] Operation ${operationName} took ${duration}ms`,
129
137
  );
130
138
  }
131
139
  }
@@ -161,7 +169,7 @@ export abstract class FrameworkBase {
161
169
 
162
170
  private doesClassNameContainBundleName(
163
171
  className: string,
164
- bundleName: string
172
+ bundleName: string,
165
173
  ): boolean {
166
174
  const bundleNameLower = bundleName.toLowerCase();
167
175
  const classNameLower = className.toLowerCase();
@@ -0,0 +1,56 @@
1
+ const { ccclass, disallowMultiple, menu, executionOrder, requireComponent } =
2
+ cc._decorator;
3
+ @ccclass
4
+ @disallowMultiple()
5
+ @menu("CustomComponent/FWVirtualScrollViewComponent")
6
+ @requireComponent(cc.ScrollView)
7
+ @executionOrder(-5000)
8
+ export default class FWVirtuaScrollViewComponent extends cc.Component {
9
+ private listener: FW.VirtualScrollViewListener = null;
10
+ private config: FW.VirtualScrollViewConfig = null;
11
+ private pool: FW.ObjectPool = null;
12
+ protected async onLoad(): Promise<void> {}
13
+
14
+ protected onDestroy(): void {
15
+ this.listener = null;
16
+ this.config = null;
17
+ }
18
+ /**
19
+ * 注册监听
20
+ * @param listener
21
+ */
22
+ registerListener(listener: FW.VirtualScrollViewListener) {
23
+ this.listener = listener;
24
+ }
25
+ /**
26
+ * 更新配置
27
+ * @param config
28
+ */
29
+ async updateConfig(config: FW.VirtualScrollViewConfig) {
30
+ if (!config) return;
31
+ if (!cc.isValid(config.container)) return;
32
+ if (!config.prefab) return;
33
+ if (config.count <= 0) return;
34
+ this.pool = await FW.Entry.objectMgr.createObjectPool(
35
+ config.prefab,
36
+ config.container,
37
+ );
38
+ this.config = config;
39
+ this.updateElement();
40
+ }
41
+
42
+ /**
43
+ * 更新元素
44
+ */
45
+ private updateElement() {
46
+ if (this.config.count <= 0) {
47
+ FW.Log.warn("列表元素数量小于等于0");
48
+ return;
49
+ }
50
+ const count = this.config.count;
51
+ for (let index = 0; index < count; index++) {
52
+ const element = this.pool.get();
53
+ this.listener.onRender(element, index);
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "17379900-9cc3-401c-9444-ad9deb2b3495",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
+ }