@ives_xxz/framework 1.0.6 → 1.0.8

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/FW.d.ts CHANGED
@@ -661,6 +661,10 @@ declare namespace FW {
661
661
  * 资源引用计数
662
662
  */
663
663
  refCount: number;
664
+ /**
665
+ * 资源属性
666
+ */
667
+ assetProperty: AssetProperty;
664
668
  };
665
669
 
666
670
  type ResManager = {
@@ -744,12 +748,17 @@ declare namespace FW {
744
748
  * @param assetProperty
745
749
  */
746
750
  hasAsset(assetProperty: AssetProperty): boolean;
751
+ /**
752
+ * 初始化远程包配置
753
+ * @param config
754
+ */
755
+ initializeRemoteBundleConfig(config: RemoteBundleConfig): void;
747
756
  };
748
757
 
749
758
  type RemoteBundleConfig = {
750
759
  bundleName: string;
751
760
  url: string;
752
- hash: string;
761
+ version: string;
753
762
  };
754
763
 
755
764
  type BundleManager = {
@@ -881,13 +890,13 @@ declare namespace FW {
881
890
  */
882
891
  load(assetProperty: AssetProperty): Promise<AssetData>;
883
892
 
884
- loadDir(assetProperty: FW.AssetProperty): Promise<FW.AssetData[]>;
893
+ loadDir(assetProperty: AssetProperty): Promise<FW.AssetData[]>;
885
894
 
886
895
  /**
887
896
  * 获取资源
888
897
  * @param asset
889
898
  */
890
- get(assetProperty: FW.AssetProperty): AssetData;
899
+ get(assetProperty: AssetProperty): AssetData;
891
900
 
892
901
  /**
893
902
  * 释放资源
@@ -15,6 +15,7 @@ class FWAssetData implements FW.AssetData {
15
15
  loaded: boolean;
16
16
  autoRelease: boolean;
17
17
  refCount: number;
18
+ assetProperty: FW.AssetProperty;
18
19
  }
19
20
 
20
21
  export class FWAssetManager extends FWManager implements FW.AssetManager {
@@ -152,6 +153,8 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
152
153
  assetData.asset = asset;
153
154
  assetData.user = assetProperty.user;
154
155
  assetData.refCount = 1;
156
+ assetData.assetProperty = assetProperty;
157
+
155
158
  self.assetsMap.set(key, assetData);
156
159
 
157
160
  cb?.(assetData);
@@ -216,6 +219,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
216
219
  assetData.autoRelease = autoRelease;
217
220
  assetData.asset = asset;
218
221
  assetData.type = type;
222
+ assetData.assetProperty = assetProperty;
219
223
 
220
224
  const key = `${this.createAssetMapKey({
221
225
  bundle: bundleName,
@@ -293,7 +297,6 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
293
297
  }
294
298
 
295
299
  if (!this.has(assetProperty)) {
296
- FWLog.error('获取资源失败,请先加载!');
297
300
  return undefined;
298
301
  }
299
302
  const key = this.createAssetMapKey(assetProperty);
@@ -344,6 +347,9 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
344
347
  }
345
348
 
346
349
  public onDestroy(): void {
350
+ this.assetsMap.forEach((v) => {
351
+ this.release(v.assetProperty);
352
+ });
347
353
  this.assetsMap.clear();
348
354
  }
349
355
  }
@@ -38,10 +38,9 @@ export class FWBundleManager extends FWManager implements FW.BundleManager {
38
38
  const remote = this.remoteBundleConfigMap.get(bundleName);
39
39
  const url = remote ? remote.url : '';
40
40
  const path = `${url}${bundleName}`;
41
-
42
41
  cc.assetManager.loadBundle(
43
42
  path,
44
- { version: this.remoteBundleConfigMap.get(bundleName) || '' },
43
+ { version: this.remoteBundleConfigMap.get(bundleName)?.version || '' },
45
44
  (err: Error, bundle: cc.AssetManager.Bundle) => {
46
45
  if (err || !bundle) {
47
46
  FWLog.error(`"加载bundle失败:"${bundleName}!`);
@@ -86,6 +85,9 @@ export class FWBundleManager extends FWManager implements FW.BundleManager {
86
85
  }
87
86
 
88
87
  public onDestroy(): void {
88
+ this.bundleMap.forEach((bundle) => {
89
+ this.release(bundle.name);
90
+ });
89
91
  this.bundleMap.clear();
90
92
  }
91
93
  }
@@ -1,6 +1,8 @@
1
1
  import FWLog from '../log/FWLog';
2
2
  import { FWManager } from './FWManager';
3
3
 
4
+ const TEMOTE_ASSET = 'remote-asset';
5
+
4
6
  export default class FWHotUpdateManager extends FWManager implements FW.HotUpdateManager {
5
7
  private listener: FW.HotUpdateListener;
6
8
  private assetMgr: any;
@@ -19,6 +21,7 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
19
21
  return;
20
22
  }
21
23
  this.localManifest = localManifest;
24
+ this.storePath = `${jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/'}${TEMOTE_ASSET}`;
22
25
  this.assetMgr = new jsb.AssetsManager('', this.storePath, this.versionCompareHandle);
23
26
  this.assetMgr.setVerifyCallback(function (path: string, asset: any) {
24
27
  const compressed = asset.compressed;
@@ -161,6 +161,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
161
161
  autoRelease: res.autoRelease,
162
162
  loaded: res.loaded,
163
163
  refCount: res.refCount,
164
+ assetProperty: res.assetProperty,
164
165
  };
165
166
  }
166
167
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -60,6 +60,7 @@ export default class FWSocket implements FW.Socket {
60
60
  this.messageEvents = cc.js.createMap();
61
61
  this.protocolContainer = new Map<Symbol, string>();
62
62
  this.protocolRegistry = new Map<string, Set<Symbol>>();
63
+ this.reconnectTimes = 0;
63
64
  }
64
65
 
65
66
  createSocket(
@@ -80,7 +81,7 @@ export default class FWSocket implements FW.Socket {
80
81
  this.isReconnect = true;
81
82
  this.sendHeartTimestamp = 0;
82
83
  this.receiveTimeStamp = new Date().getTime();
83
-
84
+ FWLog.debug('创建socket -> ', address);
84
85
  this.socket = new WebSocket(address);
85
86
  this.socket.onopen = this.onSocketOpen.bind(this);
86
87
  this.socket.onclose = this.onSocketClose.bind(this);
@@ -248,6 +249,7 @@ export default class FWSocket implements FW.Socket {
248
249
 
249
250
  /** socket关闭 */
250
251
  private onSocketClose() {
252
+ FWLog.debug('on close!');
251
253
  this.handle?.onClose?.();
252
254
  FW.Entry.timeMgr.scheduleOnce(
253
255
  () => {
package/utils/FWTask.ts CHANGED
@@ -47,7 +47,6 @@ export default class FWTask implements FW.Task {
47
47
  taskId,
48
48
  });
49
49
  this.taskStartTime = FW.Entry.timeMgr.getTime();
50
- FWLog.debug('执行任务开始', this.taskStartTime);
51
50
  await this.executeFrame();
52
51
  return this;
53
52
  }
@@ -119,45 +118,32 @@ export default class FWTask implements FW.Task {
119
118
  performance.now() - frameStart < this.frameBudget
120
119
  ) {
121
120
  const task = this.taskQueue[0];
121
+
122
122
  const taskId = (task as any).taskId || `id-${processed}`;
123
123
 
124
- try {
125
- const result = await task.next();
126
-
127
- if (result.done) {
128
- this.taskQueue.shift();
129
- this.recordEvent({
130
- type: FWEventDefine.TaskEvent.COMPLETE,
131
- progress: 1,
132
- message: '任务完成',
133
- taskId,
134
- });
135
- } else if (result.value) {
136
- this.recordEvent({
137
- ...result.value,
138
- taskId,
139
- });
140
- }
141
-
142
- frameTasks.push({
143
- taskId: taskId,
144
- result: result.done ? FWEventDefine.TaskEvent.COMPLETE : FWEventDefine.TaskEvent.YIELDED,
145
- message: (result?.value as any)?.message,
146
- });
147
- } catch (error) {
148
- FWLog.error('执行任务出错', error);
124
+ const result = await task.next();
125
+
126
+ if (result.done) {
149
127
  this.taskQueue.shift();
150
128
  this.recordEvent({
151
- type: FWEventDefine.TaskEvent.ERROR,
152
- message: `任务执行出错: ${error.message}`,
129
+ type: FWEventDefine.TaskEvent.COMPLETE,
130
+ progress: 1,
131
+ message: '任务完成',
153
132
  taskId,
154
133
  });
155
- frameTasks.push({
156
- taskId: taskId,
157
- result: FWEventDefine.TaskEvent.ERROR,
158
- message: error.message,
134
+ } else if (result.value) {
135
+ this.recordEvent({
136
+ ...result.value,
137
+ taskId,
159
138
  });
160
139
  }
140
+
141
+ frameTasks.push({
142
+ taskId: taskId,
143
+ result: result.done ? FWEventDefine.TaskEvent.COMPLETE : FWEventDefine.TaskEvent.YIELDED,
144
+ message: (result?.value as any)?.message,
145
+ });
146
+
161
147
  processed++;
162
148
  }
163
149