@ives_xxz/framework 2.0.5 → 2.0.7

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/FrameworkBase.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { injectable } from 'inversify';
1
+ import { injectable } from "inversify";
2
2
 
3
3
  @injectable()
4
4
  export abstract class FrameworkBase {
@@ -18,7 +18,11 @@ export abstract class FrameworkBase {
18
18
 
19
19
  constructor() {
20
20
  this.initialize?.();
21
- // this.entry.evtMgr.register(FW.EventDefine.SystemEvent.SYSTEM_RESTART, this.onRestart, this);
21
+ this.entry.evtMgr.register(
22
+ FW.EventDefine.SystemEvent.SYSTEM_RESTART,
23
+ this.onRestart,
24
+ this
25
+ );
22
26
  }
23
27
 
24
28
  protected get moduleName(): string {
@@ -58,36 +62,39 @@ export abstract class FrameworkBase {
58
62
 
59
63
  if (tag !== FW.SystemDefine.FWBindTag.LOGIC) {
60
64
  this.logic = FW.Framework.getComponent<FW.Logic>(
61
- `${bundleName}${FW.SystemDefine.FWBindTag.LOGIC}`,
65
+ `${bundleName}${FW.SystemDefine.FWBindTag.LOGIC}`
62
66
  );
63
67
  }
64
68
 
65
69
  if (tag !== FW.SystemDefine.FWBindTag.DATA) {
66
70
  this.data = FW.Framework.getComponent<FW.Data>(
67
- `${bundleName}${FW.SystemDefine.FWBindTag.DATA}`,
71
+ `${bundleName}${FW.SystemDefine.FWBindTag.DATA}`
68
72
  );
69
73
  }
70
74
 
71
75
  if (tag !== FW.SystemDefine.FWBindTag.CONFIG) {
72
76
  this.config = FW.Framework.getComponent<FW.AssetConfig>(
73
- `${bundleName}${FW.SystemDefine.FWBindTag.CONFIG}`,
77
+ `${bundleName}${FW.SystemDefine.FWBindTag.CONFIG}`
74
78
  );
75
79
  }
76
80
 
77
81
  if (tag !== FW.SystemDefine.FWBindTag.SENDER) {
78
82
  this.sender = FW.Framework.getComponent<FW.Sender>(
79
- `${bundleName}${FW.SystemDefine.FWBindTag.SENDER}`,
83
+ `${bundleName}${FW.SystemDefine.FWBindTag.SENDER}`
80
84
  );
81
85
  }
82
86
 
83
87
  if (tag !== FW.SystemDefine.FWBindTag.HANDLE) {
84
88
  this.handle = FW.Framework.getComponent<FW.Handle>(
85
- `${bundleName}${FW.SystemDefine.FWBindTag.HANDLE}`,
89
+ `${bundleName}${FW.SystemDefine.FWBindTag.HANDLE}`
86
90
  );
87
91
  }
88
92
  }
89
93
 
90
- protected async invoke<T>(operation: Promise<T>, operationName: string = 'unknown'): Promise<T> {
94
+ protected async invoke<T>(
95
+ operation: Promise<T>,
96
+ operationName: string = "unknown"
97
+ ): Promise<T> {
91
98
  const startTime = this.getCurrentTime();
92
99
 
93
100
  try {
@@ -101,16 +108,25 @@ export abstract class FrameworkBase {
101
108
  }
102
109
  }
103
110
 
104
- private recordPerformanceMetric(operationName: string, duration: number): void {
111
+ private recordPerformanceMetric(
112
+ operationName: string,
113
+ duration: number
114
+ ): void {
105
115
  if (FW.Entry.performanceMgr) {
106
- FW.Entry.performanceMgr.recordOperationMetric(this.moduleName, operationName, duration);
116
+ FW.Entry.performanceMgr.recordOperationMetric(
117
+ this.moduleName,
118
+ operationName,
119
+ duration
120
+ );
107
121
  }
108
122
 
109
123
  const shouldWarn = duration > 1000;
110
124
 
111
125
  if (FW.Entry.engineMgr.debug || shouldWarn) {
112
126
  const log = shouldWarn ? FW.Log.warn : FW.Log.debug;
113
- log(`[${this.moduleName?.toUpperCase()}] Operation ${operationName} took ${duration}ms`);
127
+ log(
128
+ `[${this.moduleName?.toUpperCase()}] Operation ${operationName} took ${duration}ms`
129
+ );
114
130
  }
115
131
  }
116
132
 
@@ -143,7 +159,10 @@ export abstract class FrameworkBase {
143
159
  return undefined;
144
160
  }
145
161
 
146
- private doesClassNameContainBundleName(className: string, bundleName: string): boolean {
162
+ private doesClassNameContainBundleName(
163
+ className: string,
164
+ bundleName: string
165
+ ): boolean {
147
166
  const bundleNameLower = bundleName.toLowerCase();
148
167
  const classNameLower = className.toLowerCase();
149
168
  return classNameLower.includes(bundleNameLower);
@@ -151,13 +170,13 @@ export abstract class FrameworkBase {
151
170
 
152
171
  private getClassTag(): FW.SystemDefine.FWBindTag {
153
172
  const className = this.moduleName;
154
- if (className.endsWith('Logic')) return FW.SystemDefine.FWBindTag.LOGIC;
155
- if (className.endsWith('Data')) return FW.SystemDefine.FWBindTag.DATA;
156
- if (className.endsWith('Config') || className.endsWith('AssetConfig'))
173
+ if (className.endsWith("Logic")) return FW.SystemDefine.FWBindTag.LOGIC;
174
+ if (className.endsWith("Data")) return FW.SystemDefine.FWBindTag.DATA;
175
+ if (className.endsWith("Config") || className.endsWith("AssetConfig"))
157
176
  return FW.SystemDefine.FWBindTag.CONFIG;
158
- if (className.endsWith('Sender') || className.endsWith('SocketSender'))
177
+ if (className.endsWith("Sender") || className.endsWith("SocketSender"))
159
178
  return FW.SystemDefine.FWBindTag.SENDER;
160
- if (className.endsWith('Handle') || className.endsWith('SocketHandle'))
179
+ if (className.endsWith("Handle") || className.endsWith("SocketHandle"))
161
180
  return FW.SystemDefine.FWBindTag.HANDLE;
162
181
  return;
163
182
  }
@@ -1,5 +1,5 @@
1
- import { FWSystemConfig } from '../config/FWSystemConfig';
2
- import { FWManager } from './FWManager';
1
+ import { FWSystemConfig } from "../config/FWSystemConfig";
2
+ import { FWManager } from "./FWManager";
3
3
 
4
4
  /**
5
5
  * 资源数据
@@ -47,7 +47,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
47
47
  const img = data.img;
48
48
  const ske = data.ske;
49
49
  const atlas = data.atlas;
50
- const type = bin ? '.bin' : '.txt';
50
+ const type = bin ? ".bin" : ".txt";
51
51
  cc.assetManager.loadAny(
52
52
  [
53
53
  { url: atlas, ext: type },
@@ -59,34 +59,38 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
59
59
  asset.skeletonJson = assets[1];
60
60
  asset.atlasText = assets[0];
61
61
  asset.textures.push(texture);
62
- asset['textureNames'] = [`${img}.png`];
63
- asset['_uuid'] = ske;
62
+ asset["textureNames"] = [`${img}.png`];
63
+ asset["_uuid"] = ske;
64
64
  resolve(asset);
65
- },
65
+ }
66
66
  );
67
- }, FWSystemConfig.PromiseConfig.loadAsset).promise,
67
+ }, FWSystemConfig.PromiseConfig.loadAsset).promise
68
68
  );
69
69
  } catch (e) {
70
- FW.Log.error('从远程加载spine动画资源失败!');
70
+ FW.Log.error("从远程加载spine动画资源失败!");
71
71
  }
72
72
  }
73
73
 
74
74
  /** 加载远程资源 */
75
75
  async loadRemote<T extends cc.Asset = cc.Asset>(
76
76
  url?: string,
77
- cb?: (asset: cc.Asset) => void,
77
+ cb?: (asset: cc.Asset) => void
78
78
  ): Promise<T> {
79
79
  return await this.invoke(
80
80
  FW.Entry.promiseMgr.execute((resolve, reject, signal) => {
81
- cc.assetManager.loadRemote(url, { cacheEnabled: true, maxRetryCount: 3 }, (err, asset) => {
82
- if (err || !asset) {
83
- reject(err);
81
+ cc.assetManager.loadRemote(
82
+ url,
83
+ { cacheEnabled: true, maxRetryCount: 3 },
84
+ (err, asset) => {
85
+ if (err || !asset) {
86
+ reject(err);
87
+ }
88
+ cb?.(asset as T);
89
+ resolve(asset as T);
84
90
  }
85
- cb?.(asset as T);
86
- resolve(asset as T);
87
- });
91
+ );
88
92
  }, FWSystemConfig.PromiseConfig.loadAsset).promise,
89
- `loadAssets -> ${url}`,
93
+ `loadAssets -> ${url}`
90
94
  );
91
95
  }
92
96
 
@@ -96,7 +100,9 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
96
100
  return undefined;
97
101
  }
98
102
 
99
- const propertys = Array.isArray(assetProperty) ? assetProperty : [assetProperty];
103
+ const propertys = Array.isArray(assetProperty)
104
+ ? assetProperty
105
+ : [assetProperty];
100
106
 
101
107
  await Promise.all(
102
108
  propertys.map(async (property) => {
@@ -105,17 +111,19 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
105
111
  const path = property.path;
106
112
  const progress = property.progress;
107
113
 
108
- if (!bundleName || bundleName === '') {
114
+ if (!bundleName || bundleName === "") {
109
115
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
110
116
  return undefined;
111
117
  }
112
118
 
113
- if (!path || path === '') {
119
+ if (!path || path === "") {
114
120
  FW.Log.error(`找不到资源路径${path},请检查!`);
115
121
  return undefined;
116
122
  }
117
123
 
118
- let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
124
+ let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
125
+ bundleName
126
+ );
119
127
 
120
128
  if (!bundle) {
121
129
  FW.Log.error(`加载bundle失败,请检查!`);
@@ -127,20 +135,24 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
127
135
  bundle.preload(
128
136
  path,
129
137
  type,
130
- (finish: number, total: number, item: cc.AssetManager.RequestItem) => {
138
+ (
139
+ finish: number,
140
+ total: number,
141
+ item: cc.AssetManager.RequestItem
142
+ ) => {
131
143
  progress?.(finish, total, item);
132
144
  },
133
145
  (err: Error, item: cc.AssetManager.RequestItem[]) => {
134
146
  if (err || !item || item?.length == 0) {
135
- reject(err || 'preload failed!');
147
+ reject(err || "preload failed!");
136
148
  }
137
149
  resolve(item);
138
- },
150
+ }
139
151
  );
140
152
  }, FWSystemConfig.PromiseConfig.loadAsset).promise,
141
- `preLoadAssets -> ${property.path}`,
153
+ `preLoadAssets -> ${property.path}`
142
154
  );
143
- }),
155
+ })
144
156
  );
145
157
  }
146
158
 
@@ -161,17 +173,19 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
161
173
  const progress = assetProperty.progress;
162
174
  const autoRelease = assetProperty.autoRelease;
163
175
 
164
- if (!bundleName || bundleName === '') {
176
+ if (!bundleName || bundleName === "") {
165
177
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
166
178
  return undefined;
167
179
  }
168
180
 
169
- if (!path || path === '') {
181
+ if (!path || path === "") {
170
182
  FW.Log.error(`找不到资源路径${path},请检查!`);
171
183
  return undefined;
172
184
  }
173
185
 
174
- let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
186
+ let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
187
+ bundleName
188
+ );
175
189
 
176
190
  if (!bundle) {
177
191
  FW.Log.error(`加载bundle失败,请检查!`);
@@ -195,7 +209,11 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
195
209
  bundle.load(
196
210
  path,
197
211
  type,
198
- (finish: number, total: number, item: cc.AssetManager.RequestItem) => {
212
+ (
213
+ finish: number,
214
+ total: number,
215
+ item: cc.AssetManager.RequestItem
216
+ ) => {
199
217
  progress?.(finish, total, item);
200
218
  },
201
219
  (err: Error, asset: cc.Asset) => {
@@ -205,7 +223,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
205
223
  }
206
224
  assetData.loaded = true;
207
225
  assetData.dependentBundle = bundleName;
208
- assetData.uuid = asset['_uuid'];
226
+ assetData.uuid = asset["_uuid"];
209
227
  assetData.autoRelease = autoRelease;
210
228
  assetData.asset = asset;
211
229
  assetData.user = assetProperty.user;
@@ -216,10 +234,10 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
216
234
 
217
235
  cb?.(assetData);
218
236
  resolve(assetData);
219
- },
237
+ }
220
238
  );
221
239
  }, FWSystemConfig.PromiseConfig.loadAsset).promise,
222
- `loadAssets -> ${assetProperty.path}`,
240
+ `loadAssets -> ${assetProperty.path}`
223
241
  );
224
242
  }
225
243
  /**
@@ -238,17 +256,19 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
238
256
  const cb = assetProperty.cb;
239
257
  const autoRelease = assetProperty.autoRelease;
240
258
 
241
- if (!bundleName || bundleName === '') {
259
+ if (!bundleName || bundleName === "") {
242
260
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
243
261
  return undefined;
244
262
  }
245
263
 
246
- if (!path || path === '') {
264
+ if (!path || path === "") {
247
265
  FW.Log.error(`找不到资源路径${path},请检查!`);
248
266
  return undefined;
249
267
  }
250
268
 
251
- const bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
269
+ const bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
270
+ bundleName
271
+ );
252
272
 
253
273
  if (!bundle) {
254
274
  FW.Log.error(`加载bundle失败,请检查!`);
@@ -258,7 +278,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
258
278
  return new Promise(
259
279
  (
260
280
  resolve: (value: FW.AssetData[] | PromiseLike<FW.AssetData[]>) => void,
261
- reject: (reason?: any) => void,
281
+ reject: (reason?: any) => void
262
282
  ) => {
263
283
  bundle.loadDir(path, type, (err: Error, assets: cc.Asset[]) => {
264
284
  if (err || assets.length === 0) {
@@ -272,7 +292,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
272
292
  const assetData = new FWAssetData();
273
293
  assetData.loaded = true;
274
294
  assetData.dependentBundle = bundleName;
275
- assetData.uuid = asset['_uuid'];
295
+ assetData.uuid = asset["_uuid"];
276
296
  assetData.autoRelease = autoRelease;
277
297
  assetData.asset = asset;
278
298
  assetData.type = type;
@@ -281,7 +301,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
281
301
  const key = `${this.createAssetMapKey({
282
302
  bundle: bundleName,
283
303
  path: path,
284
- })}/${asset.name}${type ? `_${type?.name}` : ''}`;
304
+ })}/${asset.name}${type ? `_${type?.name}` : ""}`;
285
305
 
286
306
  this.assetsMap.set(key, assetData);
287
307
 
@@ -291,7 +311,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
291
311
  cb?.(assetDataList);
292
312
  resolve(assetDataList);
293
313
  });
294
- },
314
+ }
295
315
  );
296
316
  }
297
317
 
@@ -308,18 +328,18 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
308
328
  const bundleName = assetProperty.bundle || FW.Entry.bundleName;
309
329
  const path = assetProperty.path;
310
330
 
311
- if (!bundleName || bundleName === '') {
331
+ if (!bundleName || bundleName === "") {
312
332
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
313
333
  return undefined;
314
334
  }
315
335
 
316
- if (!path || path === '') {
336
+ if (!path || path === "") {
317
337
  FW.Log.error(`找不到资源路径${path},请检查!`);
318
338
  return undefined;
319
339
  }
320
340
 
321
341
  if (!this.has(assetProperty)) {
322
- FW.Log.error('获取资源失败,请先加载!');
342
+ FW.Log.error("获取资源失败,请先加载!");
323
343
  return undefined;
324
344
  }
325
345
 
@@ -343,12 +363,12 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
343
363
  const path = assetProperty.path;
344
364
  const autoRelease = assetProperty.autoRelease;
345
365
 
346
- if (!bundleName || bundleName === '') {
366
+ if (!bundleName || bundleName === "") {
347
367
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
348
368
  return undefined;
349
369
  }
350
370
 
351
- if (!path || path === '') {
371
+ if (!path || path === "") {
352
372
  FW.Log.error(`找不到资源路径${path},请检查!`);
353
373
  return undefined;
354
374
  }
@@ -361,8 +381,8 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
361
381
  assetData.refCount--;
362
382
 
363
383
  if (assetData.refCount <= 0) {
384
+ this.resMgr.getBundle(bundleName)?.release(path);
364
385
  this.assetsMap.delete(key);
365
- autoRelease && this.resMgr.getBundle(bundleName)?.release(path);
366
386
  }
367
387
  }
368
388
 
@@ -1,5 +1,5 @@
1
- import { FWManager } from './FWManager';
2
- import { FWSystemConfig } from '../config/FWSystemConfig';
1
+ import { FWManager } from "./FWManager";
2
+ import { FWSystemConfig } from "../config/FWSystemConfig";
3
3
 
4
4
  export class FWBundleManager extends FWManager implements FW.BundleManager {
5
5
  bundleMap: Map<string, cc.AssetManager.Bundle>;
@@ -33,12 +33,12 @@ export class FWBundleManager extends FWManager implements FW.BundleManager {
33
33
  return await this.invoke(
34
34
  FW.Entry.promiseMgr.execute((resolve, reject, signal) => {
35
35
  const remote = this.remoteBundleConfigMap.get(bundleName);
36
- const url = remote ? remote.url : '';
36
+ const url = remote ? remote.url : "";
37
37
  const path = `${url}${bundleName}`;
38
38
  cc.assetManager.loadBundle(
39
39
  path,
40
40
  {
41
- version: this.remoteBundleConfigMap.get(bundleName)?.version || '',
41
+ version: this.remoteBundleConfigMap.get(bundleName)?.version || "",
42
42
  },
43
43
  async (err: Error, bundle: cc.AssetManager.Bundle) => {
44
44
  if (err || !bundle) {
@@ -51,10 +51,10 @@ export class FWBundleManager extends FWManager implements FW.BundleManager {
51
51
  this.bundleMap.set(bundleName, bundle);
52
52
 
53
53
  resolve(bundle);
54
- },
54
+ }
55
55
  );
56
56
  }, FWSystemConfig.PromiseConfig.loadBundle).promise,
57
- `loadBundle -> ${bundleName}`,
57
+ `loadBundle -> ${bundleName}`
58
58
  );
59
59
  }
60
60
 
@@ -65,7 +65,7 @@ export class FWBundleManager extends FWManager implements FW.BundleManager {
65
65
  */
66
66
  get(bundleName: string): cc.AssetManager.Bundle {
67
67
  if (!this.has(bundleName)) {
68
- FW.Log.error('获取bundle失败,请先加载!');
68
+ FW.Log.error("获取bundle失败,请先加载!");
69
69
  return undefined;
70
70
  }
71
71
  return this.bundleMap.get(bundleName);
@@ -1,9 +1,8 @@
1
- import FWAssetConfig from '../config/FWAssetConfig';
2
- import { FWSystemConfig } from '../config/FWSystemConfig';
3
- import { FWLodash } from '../utils/FWLodash';
4
- import { FWAssetManager } from './FWAssetManager';
5
- import { FWBundleManager } from './FWBundleManager';
6
- import { FWManager } from './FWManager';
1
+ import { FWSystemConfig } from "../config/FWSystemConfig";
2
+ import { FWLodash } from "../utils/FWLodash";
3
+ import { FWAssetManager } from "./FWAssetManager";
4
+ import { FWBundleManager } from "./FWBundleManager";
5
+ import { FWManager } from "./FWManager";
7
6
 
8
7
  export class FWResManager extends FWManager implements FW.ResManager {
9
8
  private bundleMgr: FW.BundleManager;
@@ -31,8 +30,8 @@ export class FWResManager extends FWManager implements FW.ResManager {
31
30
 
32
31
  await this.loadBundle(depend);
33
32
 
34
- const config = FW.Entry.getComponent<FWAssetConfig>(
35
- `${depend}${FW.SystemDefine.FWBindTag.CONFIG}`,
33
+ const config = FW.Entry.getComponent<FW.AssetConfig>(
34
+ `${depend}${FW.SystemDefine.FWBindTag.CONFIG}`
36
35
  );
37
36
  if (!config) continue;
38
37
  const preLoad = config.preLoad;
@@ -68,7 +67,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
68
67
  reject(e);
69
68
  }
70
69
  }, FWSystemConfig.PromiseConfig.loadBundle).promise,
71
- `loadBundle -> ${bundleName}`,
70
+ `loadBundle -> ${bundleName}`
72
71
  );
73
72
  }
74
73
  /**
@@ -85,7 +84,10 @@ export class FWResManager extends FWManager implements FW.ResManager {
85
84
  return await this.assetMgr.loadSpineDataFromRemote(data);
86
85
  }
87
86
 
88
- async loadRemote<T extends cc.Asset = cc.Asset>(url: string, cb: (asset: any) => T): Promise<T> {
87
+ async loadRemote<T extends cc.Asset = cc.Asset>(
88
+ url: string,
89
+ cb: (asset: any) => T
90
+ ): Promise<T> {
89
91
  const asset = await this.assetMgr.loadRemote(url);
90
92
  if (asset instanceof cc.Texture2D) {
91
93
  return new cc.SpriteFrame(asset) as unknown as T;
@@ -132,7 +134,9 @@ export class FWResManager extends FWManager implements FW.ResManager {
132
134
  * @param assetProperty
133
135
  * @returns
134
136
  */
135
- async loadAsset<T extends cc.Asset>(assetProperty: FW.AssetProperty): Promise<T> {
137
+ async loadAsset<T extends cc.Asset>(
138
+ assetProperty: FW.AssetProperty
139
+ ): Promise<T> {
136
140
  const res = await this.assetMgr.load(assetProperty);
137
141
  return this.process<T>(res).asset as T;
138
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": [