@ives_xxz/framework 2.1.6 → 2.1.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.
@@ -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
  * 资源数据
@@ -14,7 +14,6 @@ class FWAssetData implements FW.AssetData {
14
14
  dependentBundle: string;
15
15
  loaded: boolean;
16
16
  autoRelease: boolean;
17
- refCount: number;
18
17
  assetProperty: FW.AssetProperty;
19
18
  }
20
19
 
@@ -47,7 +46,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
47
46
  const img = data.img;
48
47
  const ske = data.ske;
49
48
  const atlas = data.atlas;
50
- const type = bin ? '.bin' : '.txt';
49
+ const type = bin ? ".bin" : ".txt";
51
50
  cc.assetManager.loadAny(
52
51
  [
53
52
  { url: atlas, ext: type },
@@ -59,34 +58,38 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
59
58
  asset.skeletonJson = assets[1];
60
59
  asset.atlasText = assets[0];
61
60
  asset.textures.push(texture);
62
- asset['textureNames'] = [`${img}.png`];
63
- asset['_uuid'] = ske;
61
+ asset["textureNames"] = [`${img}.png`];
62
+ asset["_uuid"] = ske;
64
63
  resolve(asset);
65
- },
64
+ }
66
65
  );
67
- }, FWSystemConfig.PromiseConfig.loadAsset).promise,
66
+ }, FWSystemConfig.PromiseConfig.loadAsset).promise
68
67
  );
69
68
  } catch (e) {
70
- FW.Log.error('从远程加载spine动画资源失败!');
69
+ FW.Log.error("从远程加载spine动画资源失败!");
71
70
  }
72
71
  }
73
72
 
74
73
  /** 加载远程资源 */
75
74
  async loadRemote<T extends cc.Asset = cc.Asset>(
76
75
  url?: string,
77
- cb?: (asset: cc.Asset) => void,
76
+ cb?: (asset: cc.Asset) => void
78
77
  ): Promise<T> {
79
78
  return await this.invoke(
80
79
  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);
80
+ cc.assetManager.loadRemote(
81
+ url,
82
+ { cacheEnabled: true, maxRetryCount: 3 },
83
+ (err, asset) => {
84
+ if (err || !asset) {
85
+ reject(err);
86
+ }
87
+ cb?.(asset as T);
88
+ resolve(asset as T);
84
89
  }
85
- cb?.(asset as T);
86
- resolve(asset as T);
87
- });
90
+ );
88
91
  }, FWSystemConfig.PromiseConfig.loadAsset).promise,
89
- `loadAssets -> ${url}`,
92
+ `loadAssets -> ${url}`
90
93
  );
91
94
  }
92
95
 
@@ -96,7 +99,9 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
96
99
  return undefined;
97
100
  }
98
101
 
99
- const propertys = Array.isArray(assetProperty) ? assetProperty : [assetProperty];
102
+ const propertys = Array.isArray(assetProperty)
103
+ ? assetProperty
104
+ : [assetProperty];
100
105
 
101
106
  await Promise.all(
102
107
  propertys.map(async (property) => {
@@ -105,17 +110,19 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
105
110
  const path = property.path;
106
111
  const progress = property.progress;
107
112
 
108
- if (!bundleName || bundleName === '') {
113
+ if (!bundleName || bundleName === "") {
109
114
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
110
115
  return undefined;
111
116
  }
112
117
 
113
- if (!path || path === '') {
118
+ if (!path || path === "") {
114
119
  FW.Log.error(`找不到资源路径${path},请检查!`);
115
120
  return undefined;
116
121
  }
117
122
 
118
- let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
123
+ let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
124
+ bundleName
125
+ );
119
126
 
120
127
  if (!bundle) {
121
128
  FW.Log.error(`加载bundle失败,请检查!`);
@@ -127,20 +134,24 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
127
134
  bundle.preload(
128
135
  path,
129
136
  type,
130
- (finish: number, total: number, item: cc.AssetManager.RequestItem) => {
137
+ (
138
+ finish: number,
139
+ total: number,
140
+ item: cc.AssetManager.RequestItem
141
+ ) => {
131
142
  progress?.(finish, total, item);
132
143
  },
133
144
  (err: Error, item: cc.AssetManager.RequestItem[]) => {
134
145
  if (err || !item || item?.length == 0) {
135
- reject(err || 'preload failed!');
146
+ reject(err || "preload failed!");
136
147
  }
137
148
  resolve(item);
138
- },
149
+ }
139
150
  );
140
151
  }, FWSystemConfig.PromiseConfig.loadAsset).promise,
141
- `preLoadAssets -> ${property.path}`,
152
+ `preLoadAssets -> ${property.path}`
142
153
  );
143
- }),
154
+ })
144
155
  );
145
156
  }
146
157
 
@@ -161,17 +172,19 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
161
172
  const progress = assetProperty.progress;
162
173
  const autoRelease = assetProperty.autoRelease;
163
174
 
164
- if (!bundleName || bundleName === '') {
175
+ if (!bundleName || bundleName === "") {
165
176
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
166
177
  return undefined;
167
178
  }
168
179
 
169
- if (!path || path === '') {
180
+ if (!path || path === "") {
170
181
  FW.Log.error(`找不到资源路径${path},请检查!`);
171
182
  return undefined;
172
183
  }
173
184
 
174
- let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
185
+ let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
186
+ bundleName
187
+ );
175
188
 
176
189
  if (!bundle) {
177
190
  FW.Log.error(`加载bundle失败,请检查!`);
@@ -181,10 +194,9 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
181
194
 
182
195
  if (this.assetsMap.has(key)) {
183
196
  const assetData = this.assetsMap.get(key);
184
- if (!assetData.asset.loaded) {
197
+ if(!assetData.asset.loaded){
185
198
  this.assetsMap.delete(key);
186
- } else {
187
- assetData.refCount++;
199
+ }else{
188
200
  return assetData;
189
201
  }
190
202
  }
@@ -199,7 +211,11 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
199
211
  bundle.load(
200
212
  path,
201
213
  type,
202
- (finish: number, total: number, item: cc.AssetManager.RequestItem) => {
214
+ (
215
+ finish: number,
216
+ total: number,
217
+ item: cc.AssetManager.RequestItem
218
+ ) => {
203
219
  progress?.(finish, total, item);
204
220
  },
205
221
  (err: Error, asset: cc.Asset) => {
@@ -209,21 +225,20 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
209
225
  }
210
226
  assetData.loaded = true;
211
227
  assetData.dependentBundle = bundleName;
212
- assetData.uuid = asset['_uuid'];
228
+ assetData.uuid = asset["_uuid"];
213
229
  assetData.autoRelease = autoRelease;
214
230
  assetData.asset = asset;
215
231
  assetData.user = assetProperty.user;
216
- assetData.refCount = 1;
217
232
  assetData.assetProperty = assetProperty;
218
233
 
219
234
  self.assetsMap.set(key, assetData);
220
235
 
221
236
  cb?.(assetData);
222
237
  resolve(assetData);
223
- },
238
+ }
224
239
  );
225
240
  }, FWSystemConfig.PromiseConfig.loadAsset).promise,
226
- `loadAssets -> ${assetProperty.path}`,
241
+ `loadAssets -> ${assetProperty.path}`
227
242
  );
228
243
  }
229
244
  /**
@@ -242,17 +257,19 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
242
257
  const cb = assetProperty.cb;
243
258
  const autoRelease = assetProperty.autoRelease;
244
259
 
245
- if (!bundleName || bundleName === '') {
260
+ if (!bundleName || bundleName === "") {
246
261
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
247
262
  return undefined;
248
263
  }
249
264
 
250
- if (!path || path === '') {
265
+ if (!path || path === "") {
251
266
  FW.Log.error(`找不到资源路径${path},请检查!`);
252
267
  return undefined;
253
268
  }
254
269
 
255
- const bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
270
+ const bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
271
+ bundleName
272
+ );
256
273
 
257
274
  if (!bundle) {
258
275
  FW.Log.error(`加载bundle失败,请检查!`);
@@ -262,7 +279,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
262
279
  return new Promise(
263
280
  (
264
281
  resolve: (value: FW.AssetData[] | PromiseLike<FW.AssetData[]>) => void,
265
- reject: (reason?: any) => void,
282
+ reject: (reason?: any) => void
266
283
  ) => {
267
284
  bundle.loadDir(path, type, (err: Error, assets: cc.Asset[]) => {
268
285
  if (err || assets.length === 0) {
@@ -276,7 +293,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
276
293
  const assetData = new FWAssetData();
277
294
  assetData.loaded = true;
278
295
  assetData.dependentBundle = bundleName;
279
- assetData.uuid = asset['_uuid'];
296
+ assetData.uuid = asset["_uuid"];
280
297
  assetData.autoRelease = autoRelease;
281
298
  assetData.asset = asset;
282
299
  assetData.type = type;
@@ -285,7 +302,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
285
302
  const key = `${this.createAssetMapKey({
286
303
  bundle: bundleName,
287
304
  path: path,
288
- })}/${asset.name}${type ? `_${type?.name}` : ''}`;
305
+ })}/${asset.name}${type ? `_${type?.name}` : ""}`;
289
306
 
290
307
  this.assetsMap.set(key, assetData);
291
308
 
@@ -295,7 +312,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
295
312
  cb?.(assetDataList);
296
313
  resolve(assetDataList);
297
314
  });
298
- },
315
+ }
299
316
  );
300
317
  }
301
318
 
@@ -312,24 +329,23 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
312
329
  const bundleName = assetProperty.bundle || FW.Entry.bundleName;
313
330
  const path = assetProperty.path;
314
331
 
315
- if (!bundleName || bundleName === '') {
332
+ if (!bundleName || bundleName === "") {
316
333
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
317
334
  return undefined;
318
335
  }
319
336
 
320
- if (!path || path === '') {
337
+ if (!path || path === "") {
321
338
  FW.Log.error(`找不到资源路径${path},请检查!`);
322
339
  return undefined;
323
340
  }
324
341
 
325
342
  if (!this.has(assetProperty)) {
326
- FW.Log.error('获取资源失败,请先加载!');
343
+ FW.Log.error("获取资源失败,请先加载!");
327
344
  return undefined;
328
345
  }
329
346
 
330
347
  const key = this.createAssetMapKey(assetProperty);
331
348
  const assetsData = this.assetsMap.get(key);
332
- assetsData.refCount++;
333
349
  return assetsData;
334
350
  }
335
351
 
@@ -347,12 +363,12 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
347
363
  const path = assetProperty.path;
348
364
  const autoRelease = assetProperty.autoRelease;
349
365
 
350
- if (!bundleName || bundleName === '') {
366
+ if (!bundleName || bundleName === "") {
351
367
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
352
368
  return undefined;
353
369
  }
354
370
 
355
- if (!path || path === '') {
371
+ if (!path || path === "") {
356
372
  FW.Log.error(`找不到资源路径${path},请检查!`);
357
373
  return undefined;
358
374
  }
@@ -360,11 +376,11 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
360
376
  if (!this.has(assetProperty)) {
361
377
  return undefined;
362
378
  }
379
+
363
380
  const key = this.createAssetMapKey(assetProperty);
364
381
  const assetData = this.assetsMap.get(key);
365
- assetData.refCount--;
366
382
 
367
- if (assetData.refCount <= 0) {
383
+ if (assetData.asset?.refCount <= 0 && autoRelease) {
368
384
  this.resMgr.getBundle(bundleName)?.release(path);
369
385
  this.assetsMap.delete(key);
370
386
  }
@@ -377,7 +393,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
377
393
  */
378
394
  public getReferenceCount(assetProperty: FW.AssetProperty): number {
379
395
  const key = this.createAssetMapKey(assetProperty);
380
- return this.assetsMap.get(key)?.refCount || 0;
396
+ return this.assetsMap.get(key)?.asset?.refCount || 0;
381
397
  }
382
398
 
383
399
  /**
@@ -218,7 +218,6 @@ export class FWResManager extends FWManager implements FW.ResManager {
218
218
  dependentBundle: res.dependentBundle,
219
219
  autoRelease: res.autoRelease,
220
220
  loaded: res.loaded,
221
- refCount: res.refCount,
222
221
  assetProperty: res.assetProperty,
223
222
  };
224
223
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "2.1.6",
3
+ "version": "2.1.7",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": ["123456"],
package/types/FW.d.ts CHANGED
@@ -1001,10 +1001,6 @@ declare namespace FW {
1001
1001
  * 释放时是否从bundle内释放
1002
1002
  */
1003
1003
  autoRelease: boolean;
1004
- /**
1005
- * 资源引用计数
1006
- */
1007
- refCount: number;
1008
1004
  /**
1009
1005
  * 资源属性
1010
1006
  */