@ives_xxz/framework 1.2.9 → 1.2.11

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.
@@ -20,7 +20,7 @@ export class FWLayerData<T extends FWLayerController = FWLayerController>
20
20
  layerParent?: cc.Node;
21
21
  layerPosition?: cc.Vec3;
22
22
  controllerName: string;
23
- controller: FWLayerController;
23
+ controller: FW.LayerController;
24
24
  loaded: boolean;
25
25
  externalReference?: Set<(ref: FW.LayerController | null) => void>;
26
26
  }
@@ -35,7 +35,6 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
35
35
  */
36
36
  private layerMap: Map<string, FWLayerData>;
37
37
 
38
- private layerProxyMap: Map<string, FW.LayerController>;
39
38
  /**
40
39
  * 当前所有打开Layer注册表
41
40
  */
@@ -48,7 +47,6 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
48
47
  public initialize(): void {
49
48
  this.layerQueue = new FWQueue<FWLayerData>();
50
49
  this.layerMap = new Map<string, FWLayerData>();
51
- this.layerProxyMap = new Map<string, FW.LayerController>();
52
50
  this.layerRegistry = new Set<new () => FW.LayerController>();
53
51
  this.layerStack = [];
54
52
  }
@@ -124,41 +122,46 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
124
122
  return undefined;
125
123
  }
126
124
 
127
- const ctr = new data.type();
128
-
129
- /** 如果不是重复打开的Layer,不是需要添加进队列末尾的,并且已经存在于注册表中的 不进行重复打开 */
130
- if (this.layerRegistry.has(data.type) && !ctr.isRepeatOpen) {
131
- const targetController = this.findLayerProxy<Ctr>(ctr);
132
- if (targetController) {
133
- return targetController;
125
+ for (const [key, value] of this.layerMap) {
126
+ if (value.layerConstructor == data.type) {
127
+ return value.controller as Ctr;
134
128
  }
135
129
  }
136
130
 
137
- this.layerRegistry.add(data.type);
131
+ const ctr = new data.type();
132
+ const ctrName = cc.js.getClassName(ctr);
133
+ const layerData = this.createLayerData(ctr);
138
134
 
139
- if (ctr.layerType == FWSystemDefine.FWLayerType.POPUP_QUEUE && !this.layerQueue.isEmpty()) {
140
- this.layerQueue.add(ctr.layerData);
141
- this.layerRegistry.delete(data.type);
142
- const targetController = this.findLayerProxy<Ctr>(ctr);
143
- if (targetController) {
144
- return targetController;
145
- }
135
+ layerData.layerConstructor = data.type;
136
+ layerData.controller = ctr;
137
+ layerData.controllerName = ctrName;
138
+
139
+ this.layerMap.set(ctrName, layerData);
140
+
141
+ if (this.layerRegistry.has(data.type)) {
142
+ return this.layerMap.get(ctrName).controller as Ctr;
146
143
  }
147
144
 
148
- if (ctr.layerType != FWSystemDefine.FWLayerType.REPEAT && !ctr.isRepeatOpen) {
149
- for (const [key, value] of this.layerMap) {
150
- if (value.layerAssetProperty.path == ctr.layerAssetProperty.path) {
151
- return this.findLayerProxy<Ctr>(ctr);
145
+ this.layerRegistry.add(data.type);
146
+
147
+ if (ctr.layerType == FWSystemDefine.FWLayerType.POPUP_QUEUE) {
148
+ if (this.layerRegistry.size == 0) {
149
+ let unclose = true;
150
+ for (const [key, value] of this.layerMap) {
151
+ if (value.layerType != FWSystemDefine.FWLayerType.PERMANENT) {
152
+ unclose = false;
153
+ }
154
+ }
155
+ if (!unclose) {
156
+ this.layerQueue.add(ctr.layerData);
157
+ return;
152
158
  }
153
159
  }
154
160
  }
155
161
 
156
162
  ctr.initialize();
157
163
 
158
- const layerData = this.createLayerData(ctr);
159
-
160
164
  const res = await this.openLayerAsync(layerData);
161
-
162
165
  const layer = await this.createLayer(
163
166
  res.asset,
164
167
  res.asset.name,
@@ -168,21 +171,17 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
168
171
  );
169
172
 
170
173
  const layerName = cc.js.getClassName(layer);
171
- const ctrName = cc.js.getClassName(ctr);
172
174
 
173
175
  ctr.layerData = layerData;
174
176
  ctr.layerData.loaded = true;
175
177
  ctr.layer = layer;
176
178
  ctr.layerData.layerName = layerName;
177
- ctr.layerData.controllerName = ctrName;
178
179
  ctr.layerData.uuid = res.uuid;
179
180
  ctr.uuid = res.uuid;
180
181
  ctr.onInit?.(data.args);
181
182
 
182
183
  this.lifecycleProcessing(ctr);
183
184
 
184
- this.layerMap.set(res.uuid, layerData);
185
-
186
185
  if (ctr.layerType !== FWSystemDefine.FWLayerType.PERMANENT) {
187
186
  this.layerStack.push(layerData);
188
187
  }
@@ -199,7 +198,7 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
199
198
  return target[prop];
200
199
  },
201
200
  });
202
- this.layerProxyMap.set(ctr.uuid, proxy);
201
+
203
202
  return proxy;
204
203
  }
205
204
 
@@ -214,74 +213,72 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
214
213
  return undefined;
215
214
  }
216
215
 
217
- const ctr = new data.type();
218
-
219
- /** 如果不是重复打开的Layer,不是需要添加进队列末尾的,并且已经存在于注册表中的 不进行重复打开 */
220
- if (this.layerRegistry.has(data.type) && !ctr.isRepeatOpen) {
221
- const targetController = this.findLayerProxy<Ctr>(ctr);
222
- if (targetController) {
223
- return targetController;
216
+ for (const [key, value] of this.layerMap) {
217
+ if (value.layerConstructor == data.type) {
218
+ return value.controller as Ctr;
224
219
  }
225
220
  }
226
221
 
227
- this.layerRegistry.add(data.type);
222
+ const ctr = new data.type();
223
+ const ctrName = cc.js.getClassName(ctr);
224
+ const layerData = this.createLayerData(ctr);
228
225
 
229
- if (ctr.layerType == FWSystemDefine.FWLayerType.POPUP_QUEUE && !this.layerQueue.isEmpty()) {
230
- this.layerQueue.add(ctr.layerData);
231
- this.layerRegistry.delete(data.type);
232
- const targetController = this.findLayerProxy<Ctr>(ctr);
233
- if (targetController) {
234
- return targetController;
235
- }
226
+ layerData.layerConstructor = data.type;
227
+ layerData.controller = ctr;
228
+ layerData.controllerName = ctrName;
229
+
230
+ this.layerMap.set(ctrName, layerData);
231
+
232
+ if (this.layerRegistry.has(data.type)) {
233
+ return this.layerMap.get(ctrName).controller as Ctr;
236
234
  }
237
235
 
238
- if (ctr.layerType != FWSystemDefine.FWLayerType.REPEAT && !ctr.isRepeatOpen) {
239
- for (const [key, value] of this.layerMap) {
240
- if (value.layerAssetProperty.path == ctr.layerAssetProperty.path) {
241
- return this.findLayerProxy<Ctr>(ctr);
236
+ this.layerRegistry.add(data.type);
237
+
238
+ if (ctr.layerType == FWSystemDefine.FWLayerType.POPUP_QUEUE) {
239
+ if (this.layerRegistry.size == 0) {
240
+ let unclose = true;
241
+ for (const [key, value] of this.layerMap) {
242
+ if (value.layerType != FWSystemDefine.FWLayerType.PERMANENT) {
243
+ unclose = false;
244
+ }
245
+ }
246
+ if (!unclose) {
247
+ this.layerQueue.add(ctr.layerData);
248
+ return;
242
249
  }
243
250
  }
244
251
  }
245
252
 
246
253
  ctr.initialize();
247
254
 
248
- const layerData = this.createLayerData(ctr);
255
+ this.layerQueue.add(layerData);
256
+ const res = this.openLayerSync(layerData);
257
+ const layer = this.createLayer(
258
+ res.asset,
259
+ res.asset.name,
260
+ layerData.layerRenderOrder,
261
+ layerData.layerParent,
262
+ layerData.layerPosition,
263
+ );
264
+ const layerName = cc.js.getClassName(layer);
249
265
 
250
- if (
251
- layerData.layerType == FWSystemDefine.FWLayerType.POPUP_QUEUE &&
252
- !this.layerQueue.isEmpty()
253
- ) {
254
- this.layerQueue.add(layerData);
255
- } else {
256
- const res = this.openLayerSync(layerData);
257
- const layer = this.createLayer(
258
- res.asset,
259
- res.asset.name,
260
- layerData.layerRenderOrder,
261
- layerData.layerParent,
262
- layerData.layerPosition,
263
- );
264
- this.layerMap.set(res.uuid, layerData);
265
- const layerName = cc.js.getClassName(layer);
266
- const ctrName = cc.js.getClassName(ctr);
267
-
268
- ctr.layerData = layerData;
269
- ctr.layerData.loaded = true;
270
- ctr.layer = layer;
271
- ctr.layerData.layerName = layerName;
272
- ctr.layerData.controllerName = ctrName;
273
- ctr.layerData.uuid = res.uuid;
274
- ctr.uuid = res.uuid;
275
- ctr.onInit?.(data.args);
276
-
277
- this.lifecycleProcessing(ctr);
278
- }
266
+ ctr.layerData = layerData;
267
+ ctr.layerData.loaded = true;
268
+ ctr.layer = layer;
269
+ ctr.layerData.layerName = layerName;
270
+ ctr.layerData.uuid = res.uuid;
271
+ ctr.uuid = res.uuid;
272
+ ctr.onInit?.(data.args);
273
+
274
+ this.lifecycleProcessing(ctr);
279
275
 
280
276
  if (ctr.layerType !== FWSystemDefine.FWLayerType.PERMANENT) {
281
277
  this.layerStack.push(layerData);
282
278
  }
283
279
 
284
280
  this.layerRegistry.delete(data.type);
281
+
285
282
  const proxy = new Proxy(ctr, {
286
283
  get: (target, prop) => {
287
284
  if (prop === 'addExternalReference') {
@@ -292,7 +289,6 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
292
289
  return target[prop];
293
290
  },
294
291
  });
295
- this.layerProxyMap.set(ctr.uuid, proxy);
296
292
  return proxy;
297
293
  }
298
294
 
@@ -303,7 +299,7 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
303
299
  */
304
300
  displayLayer<Ctr extends FWLayerController = FWLayerController>(ctr: Ctr): Ctr {
305
301
  const layerData = ctr.layerData;
306
- if (!this.layerMap.has(layerData.uuid)) {
302
+ if (!this.layerMap.has(layerData.controllerName)) {
307
303
  FWLog.warn(`display layer failed,layer name : ${layerData.layerName}`);
308
304
  return;
309
305
  }
@@ -325,7 +321,7 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
325
321
  */
326
322
  hideLayer<Ctr extends FWLayerController = FWLayerController>(ctr: Ctr): Ctr {
327
323
  const layerData = ctr.layerData;
328
- if (!this.layerMap.has(layerData.uuid)) {
324
+ if (!this.layerMap.has(layerData.controllerName)) {
329
325
  FWLog.warn(`hide layer failed,layer name : ${layerData.layerName}`);
330
326
  return;
331
327
  }
@@ -367,18 +363,17 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
367
363
  for (let i = 0; i < count; i++) {
368
364
  let layerData = this.layerStack.pop();
369
365
  let ctr = layerData.controller;
370
- if (!this.layerMap.has(layerData.uuid)) {
366
+ if (!this.layerMap.has(layerData.controllerName)) {
371
367
  return;
372
368
  }
373
369
  if (cc.isValid(ctr.layer?.node)) {
374
- ctr.destroy?.();
370
+ ctr.layer.destroy?.();
375
371
  if (ctr.autoRelease) {
376
372
  FW.Entry.resMgr.releaseAsset(ctr.layerData.layerAssetProperty);
377
373
  }
378
374
  this.notifyExternalRefUpdates(ctr.layerData);
379
375
  }
380
- this.layerMap.delete(layerData.uuid);
381
- this.layerProxyMap.delete(layerData.uuid);
376
+ this.layerMap.delete(layerData.controllerName);
382
377
  }
383
378
  }
384
379
 
@@ -386,28 +381,24 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
386
381
  * 关闭layer
387
382
  * @param ctr
388
383
  */
389
- async close<Ctr extends FWLayerController = FWLayerController>(
384
+ async close<Ctr extends FW.LayerController = FW.LayerController>(
390
385
  ctr: Ctr,
391
- ): Promise<FWLayerController> {
386
+ ): Promise<FW.LayerController> {
392
387
  if (!ctr) return;
393
388
 
394
389
  let layerData = ctr.layerData;
395
390
 
396
- if (!this.layerMap.has(layerData.uuid)) {
397
- return;
398
- }
399
-
400
391
  if (cc.isValid(ctr.layer?.node)) {
401
- ctr.destroy?.();
392
+ ctr.layer.node.destroy?.();
393
+ ctr.onClose();
402
394
  if (ctr.autoRelease) {
403
395
  FW.Entry.resMgr.releaseAsset(ctr.layerData.layerAssetProperty);
404
396
  }
405
397
  this.notifyExternalRefUpdates(ctr.layerData);
406
398
  }
407
399
 
408
- this.layerMap.delete(layerData.uuid);
409
- this.layerProxyMap.delete(layerData.uuid);
410
- this.layerStack.pop();
400
+ this.layerMap.delete(layerData.controllerName);
401
+ this.layerRegistry.delete(ctr.layerData.layerConstructor);
411
402
 
412
403
  const index = this.layerStack.findIndex((v) => {
413
404
  v.controller == ctr;
@@ -523,6 +514,9 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
523
514
  }
524
515
 
525
516
  public clear() {
517
+ this.layerQueue = new FWQueue();
518
+ this.layerStack = [];
519
+ this.layerRegistry = new Set<new () => FW.LayerController>();
526
520
  this.layerMap.forEach((v) => this.close(v.controller));
527
521
  this.layerMap.clear();
528
522
  }
@@ -532,12 +526,4 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
532
526
  this.layerMap = null;
533
527
  this.layerQueue = null;
534
528
  }
535
-
536
- private findLayerProxy<Ctr extends FW.LayerController>(ctr: FW.LayerController): Ctr {
537
- for (const [key, value] of this.layerMap) {
538
- if (value.layerAssetProperty.path == ctr.layerAssetProperty.path) {
539
- return this.layerProxyMap.get(value.uuid) as Ctr;
540
- }
541
- }
542
- }
543
529
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": [