@ives_xxz/framework 2.0.17 → 2.1.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.
- package/Framework.ts +9 -2
- package/manager/FWAssetManager.ts +50 -66
- package/package.json +1 -1
- package/service/socket/FWSocket.ts +1 -1
- package/service/socket/mock/FWSocketMock.ts +5 -3
- package/types/FW.d.ts +871 -265
package/Framework.ts
CHANGED
|
@@ -174,10 +174,14 @@ export class Framework implements FW.Framework {
|
|
|
174
174
|
this.container.unbind(this.getKey(data.bundleName, index));
|
|
175
175
|
}
|
|
176
176
|
});
|
|
177
|
-
|
|
178
177
|
this.removeRegistration(data);
|
|
179
178
|
}
|
|
180
|
-
|
|
179
|
+
/**
|
|
180
|
+
* 获取注册表
|
|
181
|
+
* @param bundleName
|
|
182
|
+
* @param tag
|
|
183
|
+
* @returns
|
|
184
|
+
*/
|
|
181
185
|
private recordRegistration(data: FW.RegisterFramework) {
|
|
182
186
|
const bundleName = data.bundleName;
|
|
183
187
|
if (!this.registeredComponents.has(bundleName)) {
|
|
@@ -185,6 +189,9 @@ export class Framework implements FW.Framework {
|
|
|
185
189
|
}
|
|
186
190
|
|
|
187
191
|
const registrations = this.registeredComponents.get(bundleName)!;
|
|
192
|
+
|
|
193
|
+
if (!registrations) return;
|
|
194
|
+
|
|
188
195
|
const exists = registrations.some(
|
|
189
196
|
(reg) => reg.logic === data.logic && reg.data === data.data && reg.config === data.config,
|
|
190
197
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FWSystemConfig } from
|
|
2
|
-
import { FWManager } from
|
|
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 ?
|
|
50
|
+
const type = bin ? '.bin' : '.txt';
|
|
51
51
|
cc.assetManager.loadAny(
|
|
52
52
|
[
|
|
53
53
|
{ url: atlas, ext: type },
|
|
@@ -59,38 +59,34 @@ 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[
|
|
63
|
-
asset[
|
|
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(
|
|
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(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
(err, asset) => {
|
|
85
|
-
if (err || !asset) {
|
|
86
|
-
reject(err);
|
|
87
|
-
}
|
|
88
|
-
cb?.(asset as T);
|
|
89
|
-
resolve(asset as T);
|
|
81
|
+
cc.assetManager.loadRemote(url, { cacheEnabled: true, maxRetryCount: 3 }, (err, asset) => {
|
|
82
|
+
if (err || !asset) {
|
|
83
|
+
reject(err);
|
|
90
84
|
}
|
|
91
|
-
|
|
85
|
+
cb?.(asset as T);
|
|
86
|
+
resolve(asset as T);
|
|
87
|
+
});
|
|
92
88
|
}, FWSystemConfig.PromiseConfig.loadAsset).promise,
|
|
93
|
-
`loadAssets -> ${url}
|
|
89
|
+
`loadAssets -> ${url}`,
|
|
94
90
|
);
|
|
95
91
|
}
|
|
96
92
|
|
|
@@ -100,9 +96,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
100
96
|
return undefined;
|
|
101
97
|
}
|
|
102
98
|
|
|
103
|
-
const propertys = Array.isArray(assetProperty)
|
|
104
|
-
? assetProperty
|
|
105
|
-
: [assetProperty];
|
|
99
|
+
const propertys = Array.isArray(assetProperty) ? assetProperty : [assetProperty];
|
|
106
100
|
|
|
107
101
|
await Promise.all(
|
|
108
102
|
propertys.map(async (property) => {
|
|
@@ -111,19 +105,17 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
111
105
|
const path = property.path;
|
|
112
106
|
const progress = property.progress;
|
|
113
107
|
|
|
114
|
-
if (!bundleName || bundleName ===
|
|
108
|
+
if (!bundleName || bundleName === '') {
|
|
115
109
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
116
110
|
return undefined;
|
|
117
111
|
}
|
|
118
112
|
|
|
119
|
-
if (!path || path ===
|
|
113
|
+
if (!path || path === '') {
|
|
120
114
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
121
115
|
return undefined;
|
|
122
116
|
}
|
|
123
117
|
|
|
124
|
-
let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
|
|
125
|
-
bundleName
|
|
126
|
-
);
|
|
118
|
+
let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
|
|
127
119
|
|
|
128
120
|
if (!bundle) {
|
|
129
121
|
FW.Log.error(`加载bundle失败,请检查!`);
|
|
@@ -135,24 +127,20 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
135
127
|
bundle.preload(
|
|
136
128
|
path,
|
|
137
129
|
type,
|
|
138
|
-
(
|
|
139
|
-
finish: number,
|
|
140
|
-
total: number,
|
|
141
|
-
item: cc.AssetManager.RequestItem
|
|
142
|
-
) => {
|
|
130
|
+
(finish: number, total: number, item: cc.AssetManager.RequestItem) => {
|
|
143
131
|
progress?.(finish, total, item);
|
|
144
132
|
},
|
|
145
133
|
(err: Error, item: cc.AssetManager.RequestItem[]) => {
|
|
146
134
|
if (err || !item || item?.length == 0) {
|
|
147
|
-
reject(err ||
|
|
135
|
+
reject(err || 'preload failed!');
|
|
148
136
|
}
|
|
149
137
|
resolve(item);
|
|
150
|
-
}
|
|
138
|
+
},
|
|
151
139
|
);
|
|
152
140
|
}, FWSystemConfig.PromiseConfig.loadAsset).promise,
|
|
153
|
-
`preLoadAssets -> ${property.path}
|
|
141
|
+
`preLoadAssets -> ${property.path}`,
|
|
154
142
|
);
|
|
155
|
-
})
|
|
143
|
+
}),
|
|
156
144
|
);
|
|
157
145
|
}
|
|
158
146
|
|
|
@@ -173,19 +161,17 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
173
161
|
const progress = assetProperty.progress;
|
|
174
162
|
const autoRelease = assetProperty.autoRelease;
|
|
175
163
|
|
|
176
|
-
if (!bundleName || bundleName ===
|
|
164
|
+
if (!bundleName || bundleName === '') {
|
|
177
165
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
178
166
|
return undefined;
|
|
179
167
|
}
|
|
180
168
|
|
|
181
|
-
if (!path || path ===
|
|
169
|
+
if (!path || path === '') {
|
|
182
170
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
183
171
|
return undefined;
|
|
184
172
|
}
|
|
185
173
|
|
|
186
|
-
let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
|
|
187
|
-
bundleName
|
|
188
|
-
);
|
|
174
|
+
let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
|
|
189
175
|
|
|
190
176
|
if (!bundle) {
|
|
191
177
|
FW.Log.error(`加载bundle失败,请检查!`);
|
|
@@ -195,8 +181,12 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
195
181
|
|
|
196
182
|
if (this.assetsMap.has(key)) {
|
|
197
183
|
const assetData = this.assetsMap.get(key);
|
|
198
|
-
assetData.
|
|
199
|
-
|
|
184
|
+
if (!assetData.asset.loaded) {
|
|
185
|
+
this.assetsMap.delete(key);
|
|
186
|
+
} else {
|
|
187
|
+
assetData.refCount++;
|
|
188
|
+
return assetData;
|
|
189
|
+
}
|
|
200
190
|
}
|
|
201
191
|
|
|
202
192
|
const assetData = new FWAssetData();
|
|
@@ -209,11 +199,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
209
199
|
bundle.load(
|
|
210
200
|
path,
|
|
211
201
|
type,
|
|
212
|
-
(
|
|
213
|
-
finish: number,
|
|
214
|
-
total: number,
|
|
215
|
-
item: cc.AssetManager.RequestItem
|
|
216
|
-
) => {
|
|
202
|
+
(finish: number, total: number, item: cc.AssetManager.RequestItem) => {
|
|
217
203
|
progress?.(finish, total, item);
|
|
218
204
|
},
|
|
219
205
|
(err: Error, asset: cc.Asset) => {
|
|
@@ -223,7 +209,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
223
209
|
}
|
|
224
210
|
assetData.loaded = true;
|
|
225
211
|
assetData.dependentBundle = bundleName;
|
|
226
|
-
assetData.uuid = asset[
|
|
212
|
+
assetData.uuid = asset['_uuid'];
|
|
227
213
|
assetData.autoRelease = autoRelease;
|
|
228
214
|
assetData.asset = asset;
|
|
229
215
|
assetData.user = assetProperty.user;
|
|
@@ -234,10 +220,10 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
234
220
|
|
|
235
221
|
cb?.(assetData);
|
|
236
222
|
resolve(assetData);
|
|
237
|
-
}
|
|
223
|
+
},
|
|
238
224
|
);
|
|
239
225
|
}, FWSystemConfig.PromiseConfig.loadAsset).promise,
|
|
240
|
-
`loadAssets -> ${assetProperty.path}
|
|
226
|
+
`loadAssets -> ${assetProperty.path}`,
|
|
241
227
|
);
|
|
242
228
|
}
|
|
243
229
|
/**
|
|
@@ -256,19 +242,17 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
256
242
|
const cb = assetProperty.cb;
|
|
257
243
|
const autoRelease = assetProperty.autoRelease;
|
|
258
244
|
|
|
259
|
-
if (!bundleName || bundleName ===
|
|
245
|
+
if (!bundleName || bundleName === '') {
|
|
260
246
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
261
247
|
return undefined;
|
|
262
248
|
}
|
|
263
249
|
|
|
264
|
-
if (!path || path ===
|
|
250
|
+
if (!path || path === '') {
|
|
265
251
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
266
252
|
return undefined;
|
|
267
253
|
}
|
|
268
254
|
|
|
269
|
-
const bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
|
|
270
|
-
bundleName
|
|
271
|
-
);
|
|
255
|
+
const bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
|
|
272
256
|
|
|
273
257
|
if (!bundle) {
|
|
274
258
|
FW.Log.error(`加载bundle失败,请检查!`);
|
|
@@ -278,7 +262,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
278
262
|
return new Promise(
|
|
279
263
|
(
|
|
280
264
|
resolve: (value: FW.AssetData[] | PromiseLike<FW.AssetData[]>) => void,
|
|
281
|
-
reject: (reason?: any) => void
|
|
265
|
+
reject: (reason?: any) => void,
|
|
282
266
|
) => {
|
|
283
267
|
bundle.loadDir(path, type, (err: Error, assets: cc.Asset[]) => {
|
|
284
268
|
if (err || assets.length === 0) {
|
|
@@ -292,7 +276,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
292
276
|
const assetData = new FWAssetData();
|
|
293
277
|
assetData.loaded = true;
|
|
294
278
|
assetData.dependentBundle = bundleName;
|
|
295
|
-
assetData.uuid = asset[
|
|
279
|
+
assetData.uuid = asset['_uuid'];
|
|
296
280
|
assetData.autoRelease = autoRelease;
|
|
297
281
|
assetData.asset = asset;
|
|
298
282
|
assetData.type = type;
|
|
@@ -301,7 +285,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
301
285
|
const key = `${this.createAssetMapKey({
|
|
302
286
|
bundle: bundleName,
|
|
303
287
|
path: path,
|
|
304
|
-
})}/${asset.name}${type ? `_${type?.name}` :
|
|
288
|
+
})}/${asset.name}${type ? `_${type?.name}` : ''}`;
|
|
305
289
|
|
|
306
290
|
this.assetsMap.set(key, assetData);
|
|
307
291
|
|
|
@@ -311,7 +295,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
311
295
|
cb?.(assetDataList);
|
|
312
296
|
resolve(assetDataList);
|
|
313
297
|
});
|
|
314
|
-
}
|
|
298
|
+
},
|
|
315
299
|
);
|
|
316
300
|
}
|
|
317
301
|
|
|
@@ -328,18 +312,18 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
328
312
|
const bundleName = assetProperty.bundle || FW.Entry.bundleName;
|
|
329
313
|
const path = assetProperty.path;
|
|
330
314
|
|
|
331
|
-
if (!bundleName || bundleName ===
|
|
315
|
+
if (!bundleName || bundleName === '') {
|
|
332
316
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
333
317
|
return undefined;
|
|
334
318
|
}
|
|
335
319
|
|
|
336
|
-
if (!path || path ===
|
|
320
|
+
if (!path || path === '') {
|
|
337
321
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
338
322
|
return undefined;
|
|
339
323
|
}
|
|
340
324
|
|
|
341
325
|
if (!this.has(assetProperty)) {
|
|
342
|
-
FW.Log.error(
|
|
326
|
+
FW.Log.error('获取资源失败,请先加载!');
|
|
343
327
|
return undefined;
|
|
344
328
|
}
|
|
345
329
|
|
|
@@ -363,12 +347,12 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
363
347
|
const path = assetProperty.path;
|
|
364
348
|
const autoRelease = assetProperty.autoRelease;
|
|
365
349
|
|
|
366
|
-
if (!bundleName || bundleName ===
|
|
350
|
+
if (!bundleName || bundleName === '') {
|
|
367
351
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
368
352
|
return undefined;
|
|
369
353
|
}
|
|
370
354
|
|
|
371
|
-
if (!path || path ===
|
|
355
|
+
if (!path || path === '') {
|
|
372
356
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
373
357
|
return undefined;
|
|
374
358
|
}
|
package/package.json
CHANGED
|
@@ -168,10 +168,12 @@ class WebSocketMockServer {
|
|
|
168
168
|
export class FWSocketMock {
|
|
169
169
|
private isInitialized = false;
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
if (this.isInitialized) return;
|
|
173
|
-
|
|
171
|
+
updateMockResponses(mockResponses: {}) {
|
|
174
172
|
WebSocketMockServer.getInstance().mockResponses = mockResponses;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
start(): void {
|
|
176
|
+
if (this.isInitialized) return;
|
|
175
177
|
|
|
176
178
|
const OriginalWebSocket = window.WebSocket;
|
|
177
179
|
|