@ives_xxz/framework 2.1.13 → 2.1.15
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/FrameworkInitialize.ts +1 -0
- package/controller/FWLayerController.ts +1 -1
- package/expand/FWDecorator.ts +47 -51
- package/manager/FWAssetManager.ts +46 -66
- package/manager/FWLayerManager.ts +37 -35
- package/package.json +1 -1
- package/types/FW.d.ts +23 -21
- package/utils/FWObject.ts +7 -2
package/FrameworkInitialize.ts
CHANGED
|
@@ -47,6 +47,7 @@ export function initializeFramework() {
|
|
|
47
47
|
FW.Registry = require('./registry/FWRegistry').FWRegistry;
|
|
48
48
|
FW.Framework = new (require('./Framework').Framework)();
|
|
49
49
|
FW.FrameworkBase = require('./FrameworkBase').FrameworkBase;
|
|
50
|
+
FW.Object = require('./object/FWObject').FWObject;
|
|
50
51
|
FW.Entry = new (require('./entry/FWEntry').FWEntry)();
|
|
51
52
|
FW.Scene = require('./scene/FWScene').FWScene;
|
|
52
53
|
FW.Logic = require('./logic/FWLogic').FWLogic;
|
package/expand/FWDecorator.ts
CHANGED
|
@@ -24,6 +24,16 @@ export function FWPropertyNode($opt?: ParamType): FW.PropertyDecorator {
|
|
|
24
24
|
return ($target, $propertyKey: string, $descriptorOrInitializer) => {
|
|
25
25
|
if (!$target.hasOwnProperty(KeyChild)) {
|
|
26
26
|
$target[KeyChild] = [];
|
|
27
|
+
|
|
28
|
+
const oldOnLoad: () => void = $target.onLoad || undefined;
|
|
29
|
+
$target.onLoad = function () {
|
|
30
|
+
const cache = $target[KeyChild];
|
|
31
|
+
cache.forEach(($vo) => {
|
|
32
|
+
const node = searchChild(this.node, $vo.childName);
|
|
33
|
+
this[$vo.propertyKey] = node;
|
|
34
|
+
});
|
|
35
|
+
oldOnLoad && oldOnLoad.apply(this);
|
|
36
|
+
};
|
|
27
37
|
}
|
|
28
38
|
|
|
29
39
|
const cache: { propertyKey: string; childName: string }[] = $target[KeyChild];
|
|
@@ -36,52 +46,25 @@ export function FWPropertyNode($opt?: ParamType): FW.PropertyDecorator {
|
|
|
36
46
|
} else {
|
|
37
47
|
throw new Error(`child 装饰器重复绑定属性:${$propertyKey},class:${$target?.name}`);
|
|
38
48
|
}
|
|
39
|
-
|
|
40
|
-
if (cache.length === 1) {
|
|
41
|
-
const oldOnLoad: () => void = $target.onLoad || undefined;
|
|
42
|
-
$target.onLoad = function () {
|
|
43
|
-
cache.forEach(($vo) => (this[$vo.propertyKey] = searchChild(this.node, $vo.childName)));
|
|
44
|
-
oldOnLoad && oldOnLoad.apply(this);
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
49
|
};
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
const KeyChildMulti = CookDecoratorKey('child_cache_multi');
|
|
51
53
|
|
|
52
|
-
/** 查找多个节点,并存储为数组 */
|
|
53
54
|
export function FWPropertyNodes(...paths: string[]): FW.PropertyDecorator {
|
|
54
55
|
return ($target: any, $propertyKey: string) => {
|
|
55
56
|
if (!$target.hasOwnProperty(KeyChildMulti)) {
|
|
56
57
|
$target[KeyChildMulti] = [];
|
|
57
|
-
}
|
|
58
58
|
|
|
59
|
-
const cache: { propertyKey: string; childNames: string[] }[] = $target[KeyChildMulti];
|
|
60
|
-
|
|
61
|
-
const existingEntry = cache.find(($vo) => $vo.propertyKey === $propertyKey);
|
|
62
|
-
|
|
63
|
-
if (!existingEntry) {
|
|
64
|
-
cache.push({
|
|
65
|
-
propertyKey: $propertyKey,
|
|
66
|
-
childNames: paths,
|
|
67
|
-
});
|
|
68
|
-
} else {
|
|
69
|
-
throw new Error(
|
|
70
|
-
`child 装饰器重复绑定属性:${$propertyKey}, class:${$target.constructor.name}`,
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (cache.length === 1) {
|
|
75
59
|
const oldOnLoad = $target.onLoad;
|
|
76
|
-
|
|
77
60
|
$target.onLoad = function () {
|
|
61
|
+
const cache = $target[KeyChildMulti];
|
|
78
62
|
if (!this.node) {
|
|
79
63
|
console.error(`this.node 为空,无法查找子节点`, this);
|
|
80
64
|
return;
|
|
81
65
|
}
|
|
82
66
|
cache.forEach(($vo) => {
|
|
83
67
|
const nodes: cc.Node[] = [];
|
|
84
|
-
|
|
85
68
|
$vo.childNames.forEach((childName) => {
|
|
86
69
|
const childNode = searchChild(this.node, childName);
|
|
87
70
|
if (!childNode) {
|
|
@@ -90,15 +73,27 @@ export function FWPropertyNodes(...paths: string[]): FW.PropertyDecorator {
|
|
|
90
73
|
nodes.push(childNode);
|
|
91
74
|
}
|
|
92
75
|
});
|
|
93
|
-
|
|
94
76
|
this[$vo.propertyKey] = nodes;
|
|
95
77
|
});
|
|
96
|
-
|
|
97
78
|
if (oldOnLoad) {
|
|
98
79
|
oldOnLoad.apply(this);
|
|
99
80
|
}
|
|
100
81
|
};
|
|
101
82
|
}
|
|
83
|
+
|
|
84
|
+
const cache: { propertyKey: string; childNames: string[] }[] = $target[KeyChildMulti];
|
|
85
|
+
const existingEntry = cache.find(($vo) => $vo.propertyKey === $propertyKey);
|
|
86
|
+
|
|
87
|
+
if (!existingEntry) {
|
|
88
|
+
cache.push({
|
|
89
|
+
propertyKey: $propertyKey,
|
|
90
|
+
childNames: paths,
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`child 装饰器重复绑定属性:${$propertyKey}, class:${$target.constructor.name}`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
102
97
|
};
|
|
103
98
|
}
|
|
104
99
|
|
|
@@ -116,28 +111,10 @@ export function FWPropertyComponent(
|
|
|
116
111
|
return ($target, $propertyKey: string, $descriptorOrInitializer) => {
|
|
117
112
|
if (!$target.hasOwnProperty(KeyComp)) {
|
|
118
113
|
$target[KeyComp] = [];
|
|
119
|
-
}
|
|
120
|
-
const cache: {
|
|
121
|
-
propertyKey: string;
|
|
122
|
-
compClass: INewable<cc.Component>;
|
|
123
|
-
childName: string;
|
|
124
|
-
}[] = $target[KeyComp];
|
|
125
114
|
|
|
126
|
-
|
|
127
|
-
cache.push({
|
|
128
|
-
propertyKey: $propertyKey,
|
|
129
|
-
compClass: $componentClass,
|
|
130
|
-
childName: $childName || $propertyKey,
|
|
131
|
-
});
|
|
132
|
-
} else {
|
|
133
|
-
if (!$mute) {
|
|
134
|
-
throw new Error(`component装饰器重复绑定属性:${$propertyKey},class:${$target.name}`);
|
|
135
|
-
}
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (cache.length === 1) {
|
|
139
|
-
const oldOnLoad: () => void = $target.onLoad || undefined; //$target.onLoad也可以拿到父类的实现
|
|
115
|
+
const oldOnLoad: () => void = $target.onLoad || undefined;
|
|
140
116
|
$target.onLoad = function () {
|
|
117
|
+
const cache = $target[KeyComp];
|
|
141
118
|
cache.forEach(($vo) => {
|
|
142
119
|
const node = $vo.childName ? searchChild(this.node, $vo.childName) : this.node;
|
|
143
120
|
if (!node) {
|
|
@@ -155,6 +132,25 @@ export function FWPropertyComponent(
|
|
|
155
132
|
oldOnLoad && oldOnLoad.apply(this);
|
|
156
133
|
};
|
|
157
134
|
}
|
|
135
|
+
|
|
136
|
+
const cache: {
|
|
137
|
+
propertyKey: string;
|
|
138
|
+
compClass: INewable<cc.Component>;
|
|
139
|
+
childName: string;
|
|
140
|
+
}[] = $target[KeyComp];
|
|
141
|
+
|
|
142
|
+
if (!cache.some(($vo) => $vo.propertyKey === $propertyKey)) {
|
|
143
|
+
cache.push({
|
|
144
|
+
propertyKey: $propertyKey,
|
|
145
|
+
compClass: $componentClass,
|
|
146
|
+
childName: $childName || $propertyKey,
|
|
147
|
+
});
|
|
148
|
+
} else {
|
|
149
|
+
if (!$mute) {
|
|
150
|
+
throw new Error(`component装饰器重复绑定属性:${$propertyKey},class:${$target.name}`);
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
158
154
|
};
|
|
159
155
|
}
|
|
160
156
|
|
|
@@ -176,7 +172,6 @@ export function FWPropertyComponents(
|
|
|
176
172
|
};
|
|
177
173
|
}
|
|
178
174
|
|
|
179
|
-
/** 判断是否为空 */
|
|
180
175
|
export function isNull(message?: string) {
|
|
181
176
|
return function (target: any, propertyKey: string) {
|
|
182
177
|
let value: any;
|
|
@@ -231,6 +226,7 @@ export function FWDeprecated(description?: string) {
|
|
|
231
226
|
return descriptor;
|
|
232
227
|
};
|
|
233
228
|
}
|
|
229
|
+
|
|
234
230
|
export function FWSocketAutoProcessResume() {
|
|
235
231
|
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
|
236
232
|
const originalMethod = descriptor.value;
|
|
@@ -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
|
* 资源数据
|
|
@@ -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 ?
|
|
49
|
+
const type = bin ? '.bin' : '.txt';
|
|
50
50
|
cc.assetManager.loadAny(
|
|
51
51
|
[
|
|
52
52
|
{ url: atlas, ext: type },
|
|
@@ -58,38 +58,34 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
58
58
|
asset.skeletonJson = assets[1];
|
|
59
59
|
asset.atlasText = assets[0];
|
|
60
60
|
asset.textures.push(texture);
|
|
61
|
-
asset[
|
|
62
|
-
asset[
|
|
61
|
+
asset['textureNames'] = [`${img}.png`];
|
|
62
|
+
asset['_uuid'] = ske;
|
|
63
63
|
resolve(asset);
|
|
64
|
-
}
|
|
64
|
+
},
|
|
65
65
|
);
|
|
66
|
-
}, FWSystemConfig.PromiseConfig.loadAsset).promise
|
|
66
|
+
}, FWSystemConfig.PromiseConfig.loadAsset).promise,
|
|
67
67
|
);
|
|
68
68
|
} catch (e) {
|
|
69
|
-
FW.Log.error(
|
|
69
|
+
FW.Log.error('从远程加载spine动画资源失败!');
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/** 加载远程资源 */
|
|
74
74
|
async loadRemote<T extends cc.Asset = cc.Asset>(
|
|
75
75
|
url?: string,
|
|
76
|
-
cb?: (asset: cc.Asset) => void
|
|
76
|
+
cb?: (asset: cc.Asset) => void,
|
|
77
77
|
): Promise<T> {
|
|
78
78
|
return await this.invoke(
|
|
79
79
|
FW.Entry.promiseMgr.execute((resolve, reject, signal) => {
|
|
80
|
-
cc.assetManager.loadRemote(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
(err, asset) => {
|
|
84
|
-
if (err || !asset) {
|
|
85
|
-
reject(err);
|
|
86
|
-
}
|
|
87
|
-
cb?.(asset as T);
|
|
88
|
-
resolve(asset as T);
|
|
80
|
+
cc.assetManager.loadRemote(url, { cacheEnabled: true, maxRetryCount: 3 }, (err, asset) => {
|
|
81
|
+
if (err || !asset) {
|
|
82
|
+
reject(err);
|
|
89
83
|
}
|
|
90
|
-
|
|
84
|
+
cb?.(asset as T);
|
|
85
|
+
resolve(asset as T);
|
|
86
|
+
});
|
|
91
87
|
}, FWSystemConfig.PromiseConfig.loadAsset).promise,
|
|
92
|
-
`loadAssets -> ${url}
|
|
88
|
+
`loadAssets -> ${url}`,
|
|
93
89
|
);
|
|
94
90
|
}
|
|
95
91
|
|
|
@@ -99,9 +95,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
99
95
|
return undefined;
|
|
100
96
|
}
|
|
101
97
|
|
|
102
|
-
const propertys = Array.isArray(assetProperty)
|
|
103
|
-
? assetProperty
|
|
104
|
-
: [assetProperty];
|
|
98
|
+
const propertys = Array.isArray(assetProperty) ? assetProperty : [assetProperty];
|
|
105
99
|
|
|
106
100
|
await Promise.all(
|
|
107
101
|
propertys.map(async (property) => {
|
|
@@ -110,19 +104,17 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
110
104
|
const path = property.path;
|
|
111
105
|
const progress = property.progress;
|
|
112
106
|
|
|
113
|
-
if (!bundleName || bundleName ===
|
|
107
|
+
if (!bundleName || bundleName === '') {
|
|
114
108
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
115
109
|
return undefined;
|
|
116
110
|
}
|
|
117
111
|
|
|
118
|
-
if (!path || path ===
|
|
112
|
+
if (!path || path === '') {
|
|
119
113
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
120
114
|
return undefined;
|
|
121
115
|
}
|
|
122
116
|
|
|
123
|
-
let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
|
|
124
|
-
bundleName
|
|
125
|
-
);
|
|
117
|
+
let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
|
|
126
118
|
|
|
127
119
|
if (!bundle) {
|
|
128
120
|
FW.Log.error(`加载bundle失败,请检查!`);
|
|
@@ -134,24 +126,20 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
134
126
|
bundle.preload(
|
|
135
127
|
path,
|
|
136
128
|
type,
|
|
137
|
-
(
|
|
138
|
-
finish: number,
|
|
139
|
-
total: number,
|
|
140
|
-
item: cc.AssetManager.RequestItem
|
|
141
|
-
) => {
|
|
129
|
+
(finish: number, total: number, item: cc.AssetManager.RequestItem) => {
|
|
142
130
|
progress?.(finish, total, item);
|
|
143
131
|
},
|
|
144
132
|
(err: Error, item: cc.AssetManager.RequestItem[]) => {
|
|
145
133
|
if (err || !item || item?.length == 0) {
|
|
146
|
-
reject(err ||
|
|
134
|
+
reject(err || 'preload failed!');
|
|
147
135
|
}
|
|
148
136
|
resolve(item);
|
|
149
|
-
}
|
|
137
|
+
},
|
|
150
138
|
);
|
|
151
139
|
}, FWSystemConfig.PromiseConfig.loadAsset).promise,
|
|
152
|
-
`preLoadAssets -> ${property.path}
|
|
140
|
+
`preLoadAssets -> ${property.path}`,
|
|
153
141
|
);
|
|
154
|
-
})
|
|
142
|
+
}),
|
|
155
143
|
);
|
|
156
144
|
}
|
|
157
145
|
|
|
@@ -172,19 +160,17 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
172
160
|
const progress = assetProperty.progress;
|
|
173
161
|
const autoRelease = assetProperty.autoRelease;
|
|
174
162
|
|
|
175
|
-
if (!bundleName || bundleName ===
|
|
163
|
+
if (!bundleName || bundleName === '') {
|
|
176
164
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
177
165
|
return undefined;
|
|
178
166
|
}
|
|
179
167
|
|
|
180
|
-
if (!path || path ===
|
|
168
|
+
if (!path || path === '') {
|
|
181
169
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
182
170
|
return undefined;
|
|
183
171
|
}
|
|
184
172
|
|
|
185
|
-
let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
|
|
186
|
-
bundleName
|
|
187
|
-
);
|
|
173
|
+
let bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
|
|
188
174
|
|
|
189
175
|
if (!bundle) {
|
|
190
176
|
FW.Log.error(`加载bundle失败,请检查!`);
|
|
@@ -194,9 +180,9 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
194
180
|
|
|
195
181
|
if (this.assetsMap.has(key)) {
|
|
196
182
|
const assetData = this.assetsMap.get(key);
|
|
197
|
-
if(!assetData.asset.loaded){
|
|
183
|
+
if (!assetData.asset.loaded) {
|
|
198
184
|
this.assetsMap.delete(key);
|
|
199
|
-
}else{
|
|
185
|
+
} else {
|
|
200
186
|
return assetData;
|
|
201
187
|
}
|
|
202
188
|
}
|
|
@@ -211,11 +197,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
211
197
|
bundle.load(
|
|
212
198
|
path,
|
|
213
199
|
type,
|
|
214
|
-
(
|
|
215
|
-
finish: number,
|
|
216
|
-
total: number,
|
|
217
|
-
item: cc.AssetManager.RequestItem
|
|
218
|
-
) => {
|
|
200
|
+
(finish: number, total: number, item: cc.AssetManager.RequestItem) => {
|
|
219
201
|
progress?.(finish, total, item);
|
|
220
202
|
},
|
|
221
203
|
(err: Error, asset: cc.Asset) => {
|
|
@@ -225,7 +207,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
225
207
|
}
|
|
226
208
|
assetData.loaded = true;
|
|
227
209
|
assetData.dependentBundle = bundleName;
|
|
228
|
-
assetData.uuid = asset[
|
|
210
|
+
assetData.uuid = asset['_uuid'];
|
|
229
211
|
assetData.autoRelease = autoRelease;
|
|
230
212
|
assetData.asset = asset;
|
|
231
213
|
assetData.user = assetProperty.user;
|
|
@@ -235,10 +217,10 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
235
217
|
|
|
236
218
|
cb?.(assetData);
|
|
237
219
|
resolve(assetData);
|
|
238
|
-
}
|
|
220
|
+
},
|
|
239
221
|
);
|
|
240
222
|
}, FWSystemConfig.PromiseConfig.loadAsset).promise,
|
|
241
|
-
`loadAssets -> ${assetProperty.path}
|
|
223
|
+
`loadAssets -> ${assetProperty.path}`,
|
|
242
224
|
);
|
|
243
225
|
}
|
|
244
226
|
/**
|
|
@@ -257,19 +239,17 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
257
239
|
const cb = assetProperty.cb;
|
|
258
240
|
const autoRelease = assetProperty.autoRelease;
|
|
259
241
|
|
|
260
|
-
if (!bundleName || bundleName ===
|
|
242
|
+
if (!bundleName || bundleName === '') {
|
|
261
243
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
262
244
|
return undefined;
|
|
263
245
|
}
|
|
264
246
|
|
|
265
|
-
if (!path || path ===
|
|
247
|
+
if (!path || path === '') {
|
|
266
248
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
267
249
|
return undefined;
|
|
268
250
|
}
|
|
269
251
|
|
|
270
|
-
const bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(
|
|
271
|
-
bundleName
|
|
272
|
-
);
|
|
252
|
+
const bundle: cc.AssetManager.Bundle = await this.resMgr.loadBundle(bundleName);
|
|
273
253
|
|
|
274
254
|
if (!bundle) {
|
|
275
255
|
FW.Log.error(`加载bundle失败,请检查!`);
|
|
@@ -279,7 +259,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
279
259
|
return new Promise(
|
|
280
260
|
(
|
|
281
261
|
resolve: (value: FW.AssetData[] | PromiseLike<FW.AssetData[]>) => void,
|
|
282
|
-
reject: (reason?: any) => void
|
|
262
|
+
reject: (reason?: any) => void,
|
|
283
263
|
) => {
|
|
284
264
|
bundle.loadDir(path, type, (err: Error, assets: cc.Asset[]) => {
|
|
285
265
|
if (err || assets.length === 0) {
|
|
@@ -293,7 +273,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
293
273
|
const assetData = new FWAssetData();
|
|
294
274
|
assetData.loaded = true;
|
|
295
275
|
assetData.dependentBundle = bundleName;
|
|
296
|
-
assetData.uuid = asset[
|
|
276
|
+
assetData.uuid = asset['_uuid'];
|
|
297
277
|
assetData.autoRelease = autoRelease;
|
|
298
278
|
assetData.asset = asset;
|
|
299
279
|
assetData.type = type;
|
|
@@ -302,7 +282,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
302
282
|
const key = `${this.createAssetMapKey({
|
|
303
283
|
bundle: bundleName,
|
|
304
284
|
path: path,
|
|
305
|
-
})}/${asset.name}${type ? `_${type?.name}` :
|
|
285
|
+
})}/${asset.name}${type ? `_${type?.name}` : ''}`;
|
|
306
286
|
|
|
307
287
|
this.assetsMap.set(key, assetData);
|
|
308
288
|
|
|
@@ -312,7 +292,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
312
292
|
cb?.(assetDataList);
|
|
313
293
|
resolve(assetDataList);
|
|
314
294
|
});
|
|
315
|
-
}
|
|
295
|
+
},
|
|
316
296
|
);
|
|
317
297
|
}
|
|
318
298
|
|
|
@@ -329,18 +309,18 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
329
309
|
const bundleName = assetProperty.bundle || FW.Entry.bundleName;
|
|
330
310
|
const path = assetProperty.path;
|
|
331
311
|
|
|
332
|
-
if (!bundleName || bundleName ===
|
|
312
|
+
if (!bundleName || bundleName === '') {
|
|
333
313
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
334
314
|
return undefined;
|
|
335
315
|
}
|
|
336
316
|
|
|
337
|
-
if (!path || path ===
|
|
317
|
+
if (!path || path === '') {
|
|
338
318
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
339
319
|
return undefined;
|
|
340
320
|
}
|
|
341
321
|
|
|
342
322
|
if (!this.has(assetProperty)) {
|
|
343
|
-
FW.Log.error(
|
|
323
|
+
FW.Log.error('获取资源失败,请先加载!', assetProperty);
|
|
344
324
|
return undefined;
|
|
345
325
|
}
|
|
346
326
|
|
|
@@ -363,12 +343,12 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
363
343
|
const path = assetProperty.path;
|
|
364
344
|
const autoRelease = assetProperty.autoRelease;
|
|
365
345
|
|
|
366
|
-
if (!bundleName || bundleName ===
|
|
346
|
+
if (!bundleName || bundleName === '') {
|
|
367
347
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
368
348
|
return undefined;
|
|
369
349
|
}
|
|
370
350
|
|
|
371
|
-
if (!path || path ===
|
|
351
|
+
if (!path || path === '') {
|
|
372
352
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
373
353
|
return undefined;
|
|
374
354
|
}
|
|
@@ -151,54 +151,56 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
151
151
|
/**
|
|
152
152
|
* 关闭layer
|
|
153
153
|
*/
|
|
154
|
-
async close<Ctr extends FW.LayerController = FW.LayerController>(
|
|
155
|
-
ctr: Ctr,
|
|
156
|
-
): Promise<FW.LayerController> {
|
|
154
|
+
async close<Ctr extends FW.LayerController = FW.LayerController>(ctr: Ctr): Promise<Ctr> {
|
|
157
155
|
if (!ctr) return;
|
|
158
156
|
|
|
159
|
-
|
|
157
|
+
return FW.Entry.promiseMgr.execute(async (resolve, reject) => {
|
|
158
|
+
let layerData = ctr.layerData;
|
|
160
159
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
160
|
+
if (cc.isValid(ctr.layer?.node)) {
|
|
161
|
+
await ctr.onClose?.();
|
|
162
|
+
ctr.destroy?.();
|
|
163
|
+
if (ctr.autoRelease) {
|
|
164
|
+
FW.Entry.resMgr.releaseAsset(ctr.layerData.layerAssetProperty);
|
|
165
|
+
}
|
|
166
|
+
this.dataManager.notifyExternalRefUpdates(ctr.layerData);
|
|
166
167
|
}
|
|
167
|
-
this.dataManager.notifyExternalRefUpdates(ctr.layerData);
|
|
168
|
-
}
|
|
169
168
|
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
this.dataManager.removeFromMap(layerData?.controllerConstructor);
|
|
170
|
+
this.dataManager.removeFromRegistry(ctr.layerData?.controllerConstructor);
|
|
172
171
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
});
|
|
176
|
-
if (index > -1) {
|
|
177
|
-
this.stackManager.getStack().splice(index, 1);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/** 如果队列中还有等待打开的layer */
|
|
181
|
-
if (!this.queueManager.isEmpty()) {
|
|
182
|
-
const nextLayerData = this.queueManager.getNextLayer();
|
|
183
|
-
/** 先尝试同步打开 */
|
|
184
|
-
const nextLayer = this.openSync({
|
|
185
|
-
parent: nextLayerData.layerParent,
|
|
186
|
-
position: nextLayerData.layerPosition,
|
|
187
|
-
type: nextLayerData.controllerConstructor,
|
|
172
|
+
const index = this.stackManager.getStack().findIndex((v) => {
|
|
173
|
+
v.controller == ctr;
|
|
188
174
|
});
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
175
|
+
if (index > -1) {
|
|
176
|
+
this.stackManager.getStack().splice(index, 1);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** 如果队列中还有等待打开的layer */
|
|
180
|
+
if (!this.queueManager.isEmpty()) {
|
|
181
|
+
const nextLayerData = this.queueManager.getNextLayer();
|
|
182
|
+
/** 先尝试同步打开 */
|
|
183
|
+
const nextLayer = this.openSync({
|
|
192
184
|
parent: nextLayerData.layerParent,
|
|
193
185
|
position: nextLayerData.layerPosition,
|
|
194
186
|
type: nextLayerData.controllerConstructor,
|
|
195
187
|
});
|
|
188
|
+
/** 如果同步打开失败,再次尝试异步打开(可能由于资源所在bundle并未提前加载) */
|
|
189
|
+
if (!nextLayer) {
|
|
190
|
+
resolve(
|
|
191
|
+
this.openAsync({
|
|
192
|
+
parent: nextLayerData.layerParent,
|
|
193
|
+
position: nextLayerData.layerPosition,
|
|
194
|
+
type: nextLayerData.controllerConstructor,
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
197
|
+
} else {
|
|
198
|
+
resolve(nextLayer as Ctr);
|
|
199
|
+
}
|
|
196
200
|
} else {
|
|
197
|
-
|
|
201
|
+
resolve(undefined);
|
|
198
202
|
}
|
|
199
|
-
}
|
|
200
|
-
return undefined;
|
|
201
|
-
}
|
|
203
|
+
}).promise;
|
|
202
204
|
}
|
|
203
205
|
|
|
204
206
|
getLayerMap(): Map<new () => FW.LayerController, FWLayerData> {
|
package/package.json
CHANGED
package/types/FW.d.ts
CHANGED
|
@@ -266,32 +266,32 @@ declare namespace FW {
|
|
|
266
266
|
|
|
267
267
|
type ObjectManager = {
|
|
268
268
|
/** 创建一个对象池 */
|
|
269
|
-
createObjectPool<T extends
|
|
269
|
+
createObjectPool<T extends FW.Object = FWObject>(
|
|
270
270
|
node: cc.Node,
|
|
271
271
|
parent: cc.Node,
|
|
272
272
|
tag?: string,
|
|
273
273
|
): Promise<ObjectPool<T>>;
|
|
274
|
-
createObjectPool<T extends
|
|
274
|
+
createObjectPool<T extends FW.Object = FWObject>(
|
|
275
275
|
prefab: cc.Prefab,
|
|
276
276
|
parent: cc.Node,
|
|
277
277
|
tag?: string,
|
|
278
278
|
): Promise<ObjectPool<T>>;
|
|
279
|
-
createObjectPool<T extends
|
|
279
|
+
createObjectPool<T extends FW.Object = FWObject>(
|
|
280
280
|
assetProperty: FW.AssetProperty,
|
|
281
281
|
parent: cc.Node,
|
|
282
282
|
tag?: string,
|
|
283
283
|
): Promise<ObjectPool<T>>;
|
|
284
|
-
createObjectPool<T extends
|
|
284
|
+
createObjectPool<T extends FW.Object = FWObject>(
|
|
285
285
|
node: cc.Node,
|
|
286
286
|
parent: cc.Node,
|
|
287
287
|
type?: number,
|
|
288
288
|
): Promise<ObjectPool<T>>;
|
|
289
|
-
createObjectPool<T extends
|
|
289
|
+
createObjectPool<T extends FW.Object = FWObject>(
|
|
290
290
|
prefab: cc.Prefab,
|
|
291
291
|
parent: cc.Node,
|
|
292
292
|
type?: number,
|
|
293
293
|
): Promise<ObjectPool<T>>;
|
|
294
|
-
createObjectPool<T extends
|
|
294
|
+
createObjectPool<T extends FW.Object = FWObject>(
|
|
295
295
|
assetProperty: FW.AssetProperty,
|
|
296
296
|
parent: cc.Node,
|
|
297
297
|
type?: number,
|
|
@@ -929,7 +929,7 @@ declare namespace FW {
|
|
|
929
929
|
* @param ctr - 控制器实例
|
|
930
930
|
* @returns 控制器实例
|
|
931
931
|
*/
|
|
932
|
-
hideLayer<Ctr extends
|
|
932
|
+
hideLayer<Ctr extends LayerController = LayerController>(ctr: Ctr): Ctr;
|
|
933
933
|
|
|
934
934
|
/**
|
|
935
935
|
* 关闭layer
|
|
@@ -937,7 +937,7 @@ declare namespace FW {
|
|
|
937
937
|
* @param ctr - 控制器实例
|
|
938
938
|
* @returns LayerController实例
|
|
939
939
|
*/
|
|
940
|
-
close<Ctr extends
|
|
940
|
+
close<Ctr extends LayerController = LayerController>(ctr: Ctr): Promise<Ctr>;
|
|
941
941
|
|
|
942
942
|
/**
|
|
943
943
|
* 从栈关闭指定数量的layer
|
|
@@ -1975,19 +1975,6 @@ declare namespace FW {
|
|
|
1975
1975
|
getAllReports(): Map<string, FW.PerformanceReport>;
|
|
1976
1976
|
};
|
|
1977
1977
|
|
|
1978
|
-
type Object = {
|
|
1979
|
-
/** 是否已经初始化 */
|
|
1980
|
-
initialize: boolean;
|
|
1981
|
-
/** 对象唯一id */
|
|
1982
|
-
uniqueId: number;
|
|
1983
|
-
/** 对象是否启用 */
|
|
1984
|
-
enable: boolean;
|
|
1985
|
-
onGet(...args: any);
|
|
1986
|
-
onPut();
|
|
1987
|
-
onInit();
|
|
1988
|
-
onDestroy();
|
|
1989
|
-
};
|
|
1990
|
-
|
|
1991
1978
|
type ObjectProperty<T extends Object = Object> = {
|
|
1992
1979
|
/** 对象节点 */
|
|
1993
1980
|
node?: cc.Node;
|
|
@@ -2968,3 +2955,18 @@ declare namespace FW {
|
|
|
2968
2955
|
public static updateMockResponses(mockResponses: {});
|
|
2969
2956
|
}
|
|
2970
2957
|
}
|
|
2958
|
+
|
|
2959
|
+
declare namespace FW {
|
|
2960
|
+
export abstract class Object extends cc.Component {
|
|
2961
|
+
/** 是否已经初始化 */
|
|
2962
|
+
initialize: boolean;
|
|
2963
|
+
/** 对象唯一id */
|
|
2964
|
+
uniqueId: number;
|
|
2965
|
+
/** 对象是否启用 */
|
|
2966
|
+
enable: boolean;
|
|
2967
|
+
onGet(...args: any);
|
|
2968
|
+
onPut();
|
|
2969
|
+
onInit();
|
|
2970
|
+
onDestroy();
|
|
2971
|
+
}
|
|
2972
|
+
}
|
package/utils/FWObject.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export abstract class FWObject extends cc.Component {
|
|
2
2
|
/** 是否已经初始化 */
|
|
3
3
|
public initialize: boolean;
|
|
4
4
|
/** 对象唯一id */
|
|
@@ -18,5 +18,10 @@ export default abstract class FWObject extends cc.Component implements FW.Object
|
|
|
18
18
|
abstract onGet(args: any);
|
|
19
19
|
abstract onPut();
|
|
20
20
|
abstract onInit();
|
|
21
|
-
|
|
21
|
+
onDestroy() {
|
|
22
|
+
FW.Entry.timeMgr?.unSchedule(this);
|
|
23
|
+
FW.Entry.evtMgr?.targetOff(this);
|
|
24
|
+
this?.unscheduleAllCallbacks();
|
|
25
|
+
this?.node?.stopAllActions();
|
|
26
|
+
}
|
|
22
27
|
}
|