@ives_xxz/framework 2.3.11 → 2.3.12

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
  * 资源数据
@@ -46,7 +46,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
46
46
  const img = data.img;
47
47
  const ske = data.ske;
48
48
  const atlas = data.atlas;
49
- const type = bin ? ".bin" : ".txt";
49
+ const type = bin ? '.bin' : '.txt';
50
50
  cc.assetManager.loadAny(
51
51
  [
52
52
  { url: atlas, ext: type },
@@ -63,33 +63,44 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
63
63
  asset.atlasText = assets[0];
64
64
  asset.skeletonJson = assets[1];
65
65
  asset.textures.push(texture);
66
- asset["textureNames"] = [`${fileName}`];
67
- asset["_uuid"] = ske;
66
+ asset['textureNames'] = [`${fileName}`];
67
+ asset['_uuid'] = ske;
68
68
  resolve(asset);
69
69
  },
70
70
  );
71
71
  }, FWSystemConfig.PromiseConfig.loadAsset).promise,
72
72
  );
73
73
  } catch (e) {
74
- FW.Log.error("从远程加载spine动画资源失败!");
74
+ FW.Log.error('从远程加载spine动画资源失败!');
75
75
  }
76
76
  }
77
77
 
78
78
  /** 加载远程资源 */
79
79
  async loadRemote<T extends cc.Asset = cc.Asset>(
80
80
  url?: string,
81
- cb?: (asset: cc.Asset) => void,
81
+ options?: {
82
+ ext?: string;
83
+ enableCache?: boolean;
84
+ maxRetryCount?: number;
85
+ cb?: (asset: T) => void;
86
+ },
82
87
  ): Promise<T> {
83
88
  return await this.invoke(
84
89
  FW.Entry.promiseMgr.execute((resolve, reject, signal) => {
85
90
  cc.assetManager.loadRemote(
86
- `${url}?t=${new Date().getTime()}`,
87
- { cacheEnabled: false, maxRetryCount: 3 },
91
+ options?.enableCache === undefined || !options?.enableCache
92
+ ? `${url}?t=${new Date().getTime()}`
93
+ : `${url}`,
94
+ {
95
+ ext: options?.ext,
96
+ cacheEnabled: options?.enableCache || false,
97
+ maxRetryCount: options?.maxRetryCount || 3,
98
+ },
88
99
  (err, asset) => {
89
100
  if (err || !asset) {
90
101
  reject(err);
91
102
  }
92
- cb?.(asset as T);
103
+ options.cb?.(asset as T);
93
104
  resolve(asset as T);
94
105
  },
95
106
  );
@@ -104,9 +115,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
104
115
  return undefined;
105
116
  }
106
117
 
107
- const propertys = Array.isArray(assetProperty)
108
- ? assetProperty
109
- : [assetProperty];
118
+ const propertys = Array.isArray(assetProperty) ? assetProperty : [assetProperty];
110
119
 
111
120
  await Promise.all(
112
121
  propertys.map(async (property) => {
@@ -115,18 +124,17 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
115
124
  const path = property.path;
116
125
  const progress = property.progress;
117
126
 
118
- if (!bundleName || bundleName === "") {
127
+ if (!bundleName || bundleName === '') {
119
128
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
120
129
  return undefined;
121
130
  }
122
131
 
123
- if (!path || path === "") {
132
+ if (!path || path === '') {
124
133
  FW.Log.error(`找不到资源路径${path},请检查!`);
125
134
  return undefined;
126
135
  }
127
136
 
128
- let bundle: cc.AssetManager.Bundle =
129
- await this.resMgr.loadBundle(bundleName);
137
+ let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
130
138
 
131
139
  if (!bundle) {
132
140
  FW.Log.error(`加载bundle失败,请检查!`);
@@ -138,16 +146,12 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
138
146
  bundle.preload(
139
147
  path,
140
148
  type,
141
- (
142
- finish: number,
143
- total: number,
144
- item: cc.AssetManager.RequestItem,
145
- ) => {
149
+ (finish: number, total: number, item: cc.AssetManager.RequestItem) => {
146
150
  progress?.(finish, total, item);
147
151
  },
148
152
  (err: Error, item: cc.AssetManager.RequestItem[]) => {
149
153
  if (err || !item || item?.length == 0) {
150
- reject(err || "preload failed!");
154
+ reject(err || 'preload failed!');
151
155
  }
152
156
  resolve(item);
153
157
  },
@@ -176,18 +180,17 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
176
180
  const progress = assetProperty.progress;
177
181
  const autoRelease = assetProperty.autoRelease;
178
182
 
179
- if (!bundleName || bundleName === "") {
183
+ if (!bundleName || bundleName === '') {
180
184
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
181
185
  return undefined;
182
186
  }
183
187
 
184
- if (!path || path === "") {
188
+ if (!path || path === '') {
185
189
  FW.Log.error(`找不到资源路径${path},请检查!`);
186
190
  return undefined;
187
191
  }
188
192
 
189
- let bundle: cc.AssetManager.Bundle =
190
- await this.resMgr.loadBundle(bundleName);
193
+ let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
191
194
 
192
195
  if (!bundle) {
193
196
  FW.Log.error(`加载bundle失败,请检查!`);
@@ -215,11 +218,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
215
218
  bundle.load(
216
219
  path,
217
220
  type,
218
- (
219
- finish: number,
220
- total: number,
221
- item: cc.AssetManager.RequestItem,
222
- ) => {
221
+ (finish: number, total: number, item: cc.AssetManager.RequestItem) => {
223
222
  progress?.(finish, total, item);
224
223
  },
225
224
  (err: Error, asset: cc.Asset) => {
@@ -229,7 +228,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
229
228
  }
230
229
  assetData.loaded = true;
231
230
  assetData.dependentBundle = bundleName;
232
- assetData.uuid = asset["_uuid"];
231
+ assetData.uuid = asset['_uuid'];
233
232
  assetData.autoRelease = autoRelease;
234
233
  assetData.asset = asset;
235
234
  assetData.user = assetProperty.user;
@@ -261,18 +260,17 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
261
260
  const cb = assetProperty.cb;
262
261
  const autoRelease = assetProperty.autoRelease;
263
262
 
264
- if (!bundleName || bundleName === "") {
263
+ if (!bundleName || bundleName === '') {
265
264
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
266
265
  return undefined;
267
266
  }
268
267
 
269
- if (!path || path === "") {
268
+ if (!path || path === '') {
270
269
  FW.Log.error(`找不到资源路径${path},请检查!`);
271
270
  return undefined;
272
271
  }
273
272
 
274
- const bundle: cc.AssetManager.Bundle =
275
- await this.resMgr.loadBundle(bundleName);
273
+ const bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
276
274
 
277
275
  if (!bundle) {
278
276
  FW.Log.error(`加载bundle失败,请检查!`);
@@ -296,7 +294,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
296
294
  const assetData = new FWAssetData();
297
295
  assetData.loaded = true;
298
296
  assetData.dependentBundle = bundleName;
299
- assetData.uuid = asset["_uuid"];
297
+ assetData.uuid = asset['_uuid'];
300
298
  assetData.autoRelease = autoRelease;
301
299
  assetData.asset = asset;
302
300
  assetData.type = type;
@@ -305,7 +303,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
305
303
  const key = `${this.createAssetMapKey({
306
304
  bundle: bundleName,
307
305
  path: path,
308
- })}/${asset.name}${type ? `_${type?.name}` : ""}`;
306
+ })}/${asset.name}${type ? `_${type?.name}` : ''}`;
309
307
 
310
308
  this.assetsMap.set(key, assetData);
311
309
 
@@ -332,18 +330,18 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
332
330
  const bundleName = assetProperty.bundle || FW.Entry.bundleName;
333
331
  const path = assetProperty.path;
334
332
 
335
- if (!bundleName || bundleName === "") {
333
+ if (!bundleName || bundleName === '') {
336
334
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
337
335
  return undefined;
338
336
  }
339
337
 
340
- if (!path || path === "") {
338
+ if (!path || path === '') {
341
339
  FW.Log.error(`找不到资源路径${path},请检查!`);
342
340
  return undefined;
343
341
  }
344
342
 
345
343
  if (!this.has(assetProperty)) {
346
- FW.Log.error("获取资源失败,请先加载!", assetProperty);
344
+ FW.Log.error('获取资源失败,请先加载!', assetProperty);
347
345
  return undefined;
348
346
  }
349
347
 
@@ -366,12 +364,12 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
366
364
  const path = assetProperty.path;
367
365
  const autoRelease = assetProperty.autoRelease;
368
366
 
369
- if (!bundleName || bundleName === "") {
367
+ if (!bundleName || bundleName === '') {
370
368
  FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
371
369
  return undefined;
372
370
  }
373
371
 
374
- if (!path || path === "") {
372
+ if (!path || path === '') {
375
373
  FW.Log.error(`找不到资源路径${path},请检查!`);
376
374
  return undefined;
377
375
  }
@@ -424,7 +422,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
424
422
  const type = assetProperty.type;
425
423
 
426
424
  let typeKey: string | undefined;
427
- if (typeof type === "string") {
425
+ if (typeof type === 'string') {
428
426
  typeKey = type;
429
427
  } else if (type) {
430
428
  typeKey = (type as any).name;
@@ -91,10 +91,18 @@ export class FWResManager extends FWManager implements FW.ResManager {
91
91
  return await this.assetMgr.loadSpineDataFromRemote(data);
92
92
  }
93
93
 
94
- async loadRemote<T extends cc.Asset = cc.Asset>(url: string, texture?: boolean): Promise<T> {
94
+ async loadRemote<T extends cc.Asset = cc.Asset>(
95
+ url: string,
96
+ options?: {
97
+ ext?: string;
98
+ enableCache?: boolean;
99
+ maxRetryCount?: number;
100
+ cb?: (asset: T) => void;
101
+ },
102
+ ): Promise<T> {
95
103
  try {
96
- const asset = await this.assetMgr.loadRemote(url);
97
- if (texture) {
104
+ const asset = await this.assetMgr.loadRemote(url, options);
105
+ if (options?.ext) {
98
106
  return asset as T;
99
107
  } else {
100
108
  if (asset instanceof cc.Texture2D) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "2.3.11",
3
+ "version": "2.3.12",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": ["123456"],
package/types/FW.d.ts CHANGED
@@ -1076,7 +1076,12 @@ declare namespace FW {
1076
1076
  * @param cb - 回调函数
1077
1077
  * @returns Promise返回加载的资源
1078
1078
  */
1079
- loadRemote<T extends cc.Asset = cc.Asset>(url: string, texutre?: boolean): Promise<T>;
1079
+ loadRemote<T extends cc.Asset = cc.Asset>(url: string, options?: {
1080
+ ext?: string;
1081
+ enableCache?: boolean;
1082
+ maxRetryCount?: number;
1083
+ cb?: (asset: T) => void;
1084
+ },): Promise<T>;
1080
1085
 
1081
1086
  /**
1082
1087
  * 从远程加载spine动画数据
@@ -1260,7 +1265,12 @@ declare namespace FW {
1260
1265
  * @param url
1261
1266
  * @param cb
1262
1267
  */
1263
- loadRemote<T extends cc.Asset = cc.Asset>(url: string, cb?: (asset: cc.Asset) => T): Promise<T>;
1268
+ loadRemote<T extends cc.Asset = cc.Asset>(url: string, options?: {
1269
+ ext?: string;
1270
+ enableCache?: boolean;
1271
+ maxRetryCount?: number;
1272
+ cb?: (asset: T) => void;
1273
+ }): Promise<T>;
1264
1274
  /**
1265
1275
  * 从远程加载spine动画
1266
1276
  * @param data