@ives_xxz/framework 2.1.40 → 2.2.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 +35 -15
- package/FrameworkBase.ts +20 -4
- package/FrameworkInitialize.ts +48 -33
- package/config/FWSystemConfig.ts +4 -4
- package/manager/FWAssetManager.ts +58 -31
- package/manager/FWLayerManager.ts +1 -1
- package/manager/FWPromiseManager.ts +66 -42
- package/manager/FWResManager.ts +36 -23
- package/manager/FWUiManager.ts +25 -8
- package/package.json +1 -1
- package/service/http/FWHttp.ts +57 -31
- package/service/socket/FWSocket.ts +37 -23
- package/utils/FWResLoader.ts +139 -0
- package/utils/FWResLoader.ts.meta +10 -0
package/Framework.ts
CHANGED
|
@@ -58,24 +58,44 @@ export class Framework implements FW.Framework {
|
|
|
58
58
|
|
|
59
59
|
/** 获取所有组件 */
|
|
60
60
|
public getComponents<T>(serviceIdentifier: FW.ServiceIdentifier<T>): T[] {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (this.isSubclassOf(binding.implementationType, serviceIdentifier)) {
|
|
67
|
-
childBindings.push(binding);
|
|
68
|
-
}
|
|
61
|
+
const instances: T[] = [];
|
|
62
|
+
|
|
63
|
+
if (typeof serviceIdentifier === "string") {
|
|
64
|
+
if (this.container.isBound(serviceIdentifier)) {
|
|
65
|
+
instances.push(this.container.get<T>(serviceIdentifier));
|
|
69
66
|
}
|
|
67
|
+
return instances;
|
|
70
68
|
}
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
if (typeof serviceIdentifier === "function") {
|
|
71
|
+
for (const registrations of this.registeredComponents.values()) {
|
|
72
|
+
for (const data of registrations) {
|
|
73
|
+
const classes = [
|
|
74
|
+
data.logic,
|
|
75
|
+
data.data,
|
|
76
|
+
data.config,
|
|
77
|
+
data.sender,
|
|
78
|
+
data.handle,
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
for (const cls of classes) {
|
|
82
|
+
if (!cls) continue;
|
|
83
|
+
|
|
84
|
+
if (!this.isSubclassOf(cls, serviceIdentifier)) continue;
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const instance = this.getComponent<T>(cls as any);
|
|
88
|
+
if (instance && !instances.includes(instance)) {
|
|
89
|
+
instances.push(instance);
|
|
90
|
+
}
|
|
91
|
+
} catch (e) {
|
|
92
|
+
FW.Log.warn(
|
|
93
|
+
`Error getting component instance for ${cls.name}:`,
|
|
94
|
+
e,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
79
99
|
}
|
|
80
100
|
}
|
|
81
101
|
|
package/FrameworkBase.ts
CHANGED
|
@@ -60,13 +60,29 @@ export abstract class FrameworkBase {
|
|
|
60
60
|
public initializeDependencies(): void {
|
|
61
61
|
if (this.dependenciesInjected || this.isInitialized) return;
|
|
62
62
|
|
|
63
|
-
this.dependenciesInjected = true;
|
|
64
|
-
this.isInitialized = true;
|
|
65
|
-
|
|
66
63
|
const bundleName = this.findBundleNameByClassName();
|
|
67
|
-
if (!bundleName)
|
|
64
|
+
if (!bundleName) {
|
|
65
|
+
if (FW.Entry?.engineMgr?.debug) {
|
|
66
|
+
FW.Log.warn(
|
|
67
|
+
`[FrameworkBase] 未能根据类名 "${this.moduleName}" 推断出 bundleName,跳过依赖注入`,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
68
72
|
|
|
69
73
|
const tag = this.getClassTag();
|
|
74
|
+
if (tag === undefined) {
|
|
75
|
+
if (FW.Entry?.engineMgr?.debug) {
|
|
76
|
+
FW.Log.warn(
|
|
77
|
+
`[FrameworkBase] 未能根据类名 "${this.moduleName}" 推断出绑定类型(Logic/Data/Config/Sender/Handle),跳过依赖注入`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 只有在 bundleName / tag 均解析成功时,才标记为已初始化,避免无效的“锁死”状态
|
|
84
|
+
this.dependenciesInjected = true;
|
|
85
|
+
this.isInitialized = true;
|
|
70
86
|
|
|
71
87
|
if (tag !== FW.SystemDefine.FWBindTag.LOGIC) {
|
|
72
88
|
this.logic = FW.Entry.getComponent<FW.Logic>(
|
package/FrameworkInitialize.ts
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
1
|
export function initializeFramework() {
|
|
2
2
|
const WD = window as any;
|
|
3
|
-
const SD = require(
|
|
4
|
-
const ED = require(
|
|
3
|
+
const SD = require("./define/FWSystemDefine");
|
|
4
|
+
const ED = require("./define/FWEventDefine");
|
|
5
|
+
|
|
6
|
+
// 防止重复初始化导致状态错乱(例如热重载或多次调用)
|
|
7
|
+
if (WD.FW && WD.FW.Framework && WD.FW.Entry) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
|
|
5
11
|
WD.FW = {};
|
|
6
12
|
|
|
7
|
-
globalThis.FWPropertyNode = require(
|
|
8
|
-
globalThis.searchChild = require(
|
|
9
|
-
globalThis.FWPropertyNode = require(
|
|
10
|
-
globalThis.FWPropertyNodes = require(
|
|
11
|
-
globalThis.FWPropertyComponent =
|
|
12
|
-
|
|
13
|
-
globalThis.
|
|
14
|
-
|
|
15
|
-
globalThis.
|
|
16
|
-
|
|
17
|
-
globalThis.
|
|
18
|
-
globalThis.
|
|
19
|
-
|
|
20
|
-
globalThis.
|
|
13
|
+
globalThis.FWPropertyNode = require("./expand/FWDecorator").FWPropertyNode;
|
|
14
|
+
globalThis.searchChild = require("./expand/FWDecorator").searchChild;
|
|
15
|
+
globalThis.FWPropertyNode = require("./expand/FWDecorator").FWPropertyNode;
|
|
16
|
+
globalThis.FWPropertyNodes = require("./expand/FWDecorator").FWPropertyNodes;
|
|
17
|
+
globalThis.FWPropertyComponent =
|
|
18
|
+
require("./expand/FWDecorator").FWPropertyComponent;
|
|
19
|
+
globalThis.FWPropertyComponents =
|
|
20
|
+
require("./expand/FWDecorator").FWPropertyComponents;
|
|
21
|
+
globalThis.PerformanceMonitor =
|
|
22
|
+
require("./expand/FWDecorator").PerformanceMonitor;
|
|
23
|
+
globalThis.FWDeprecated = require("./expand/FWDecorator").FWDeprecated;
|
|
24
|
+
globalThis.FWSocketAutoProcessPause =
|
|
25
|
+
require("./expand/FWDecorator").FWSocketAutoProcessPause;
|
|
26
|
+
globalThis.FWSocketAutoProcessResume =
|
|
27
|
+
require("./expand/FWDecorator").FWSocketAutoProcessResume;
|
|
28
|
+
globalThis.RegisterEvents = require("./expand/FWDecorator").RegisterEvents;
|
|
29
|
+
globalThis.AutoRegisterCCEvent =
|
|
30
|
+
require("./expand/FWDecorator").AutoRegisterCCEvent;
|
|
31
|
+
globalThis.AutoRegisterFWEvent =
|
|
32
|
+
require("./expand/FWDecorator").AutoRegisterFWEvent;
|
|
33
|
+
globalThis.launchScene = "";
|
|
21
34
|
|
|
22
35
|
(FW.SystemDefine as any) = {};
|
|
23
36
|
(FW.EventDefine as any) = {};
|
|
@@ -42,23 +55,25 @@ export function initializeFramework() {
|
|
|
42
55
|
FW.SystemDefine.FWPromiseStatus = new SD.FWPromiseStatus();
|
|
43
56
|
FW.SystemDefine.FWLayerState = new SD.FWLayerState();
|
|
44
57
|
FW.SystemDefine.FWAudioType = new SD.FWAudioType();
|
|
45
|
-
FW.Service = require(
|
|
46
|
-
FW.Http = require(
|
|
47
|
-
FW.Registry = require(
|
|
48
|
-
FW.Framework = new (require(
|
|
49
|
-
FW.FrameworkBase = require(
|
|
50
|
-
FW.Object = require(
|
|
51
|
-
FW.Entry = new (require(
|
|
52
|
-
FW.Scene = require(
|
|
53
|
-
FW.Logic = require(
|
|
54
|
-
FW.Data = require(
|
|
55
|
-
FW.Sender = require(
|
|
56
|
-
FW.Handle = require(
|
|
57
|
-
FW.AssetConfig = require(
|
|
58
|
-
FW.Log = new (require(
|
|
59
|
-
FW.Layer = require(
|
|
60
|
-
FW.LayerController =
|
|
61
|
-
|
|
58
|
+
FW.Service = require("./service/FWService").FWService;
|
|
59
|
+
FW.Http = require("./service/http/FWHttp").FWHttp;
|
|
60
|
+
FW.Registry = require("./registry/FWRegistry").FWRegistry;
|
|
61
|
+
FW.Framework = new (require("./Framework").Framework)();
|
|
62
|
+
FW.FrameworkBase = require("./FrameworkBase").FrameworkBase;
|
|
63
|
+
FW.Object = require("./utils/FWObject").FWObject;
|
|
64
|
+
FW.Entry = new (require("./entry/FWEntry").FWEntry)();
|
|
65
|
+
FW.Scene = require("./scene/FWScene").FWScene;
|
|
66
|
+
FW.Logic = require("./logic/FWLogic").FWLogic;
|
|
67
|
+
FW.Data = require("./data/FWData").FWData;
|
|
68
|
+
FW.Sender = require("./service/socket/FWSocketSender").FWSocketSender;
|
|
69
|
+
FW.Handle = require("./service/socket/FWSocketHandle").FWSocketHandle;
|
|
70
|
+
FW.AssetConfig = require("./config/FWAssetConfig").FWAssetConfig;
|
|
71
|
+
FW.Log = new (require("./log/FWLog").FWLog)();
|
|
72
|
+
FW.Layer = require("./layer/FWLayer").FWLayer;
|
|
73
|
+
FW.LayerController =
|
|
74
|
+
require("./controller/FWLayerController").FWLayerController;
|
|
75
|
+
FW.SocketMock =
|
|
76
|
+
new (require("./service/socket/mock/FWSocketMock").FWSocketMock)();
|
|
62
77
|
FW.Framework.initialize();
|
|
63
78
|
FW.Entry.initialize();
|
|
64
79
|
}
|
package/config/FWSystemConfig.ts
CHANGED
|
@@ -6,24 +6,24 @@ export namespace FWSystemConfig {
|
|
|
6
6
|
maxReconnectTimes: 10,
|
|
7
7
|
reconnectInternal: 3000,
|
|
8
8
|
protocolSymbol: null,
|
|
9
|
-
protocolPollingTime:
|
|
9
|
+
protocolPollingTime: 10000,
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export const PromiseConfig = {
|
|
13
13
|
loadAsset: {
|
|
14
14
|
retryCount: 0,
|
|
15
15
|
retryInterval: 0,
|
|
16
|
-
timeout:
|
|
16
|
+
timeout: 10000,
|
|
17
17
|
},
|
|
18
18
|
loadBundle: {
|
|
19
19
|
retryCount: 0,
|
|
20
20
|
retryInterval: 0,
|
|
21
|
-
timeout:
|
|
21
|
+
timeout: 10000,
|
|
22
22
|
},
|
|
23
23
|
http: {
|
|
24
24
|
retryCount: 3,
|
|
25
25
|
retryInterval: 5,
|
|
26
|
-
timeout:
|
|
26
|
+
timeout: 10000,
|
|
27
27
|
},
|
|
28
28
|
};
|
|
29
29
|
}
|
|
@@ -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 },
|
|
@@ -63,15 +63,15 @@ 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[
|
|
67
|
-
asset[
|
|
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(
|
|
74
|
+
FW.Log.error("从远程加载spine动画资源失败!");
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -104,7 +104,9 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
104
104
|
return undefined;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
const propertys = Array.isArray(assetProperty)
|
|
107
|
+
const propertys = Array.isArray(assetProperty)
|
|
108
|
+
? assetProperty
|
|
109
|
+
: [assetProperty];
|
|
108
110
|
|
|
109
111
|
await Promise.all(
|
|
110
112
|
propertys.map(async (property) => {
|
|
@@ -113,17 +115,18 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
113
115
|
const path = property.path;
|
|
114
116
|
const progress = property.progress;
|
|
115
117
|
|
|
116
|
-
if (!bundleName || bundleName ===
|
|
118
|
+
if (!bundleName || bundleName === "") {
|
|
117
119
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
118
120
|
return undefined;
|
|
119
121
|
}
|
|
120
122
|
|
|
121
|
-
if (!path || path ===
|
|
123
|
+
if (!path || path === "") {
|
|
122
124
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
123
125
|
return undefined;
|
|
124
126
|
}
|
|
125
127
|
|
|
126
|
-
let bundle: cc.AssetManager.Bundle =
|
|
128
|
+
let bundle: cc.AssetManager.Bundle =
|
|
129
|
+
await this.resMgr.loadBundle(bundleName);
|
|
127
130
|
|
|
128
131
|
if (!bundle) {
|
|
129
132
|
FW.Log.error(`加载bundle失败,请检查!`);
|
|
@@ -135,12 +138,16 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
135
138
|
bundle.preload(
|
|
136
139
|
path,
|
|
137
140
|
type,
|
|
138
|
-
(
|
|
141
|
+
(
|
|
142
|
+
finish: number,
|
|
143
|
+
total: number,
|
|
144
|
+
item: cc.AssetManager.RequestItem,
|
|
145
|
+
) => {
|
|
139
146
|
progress?.(finish, total, item);
|
|
140
147
|
},
|
|
141
148
|
(err: Error, item: cc.AssetManager.RequestItem[]) => {
|
|
142
149
|
if (err || !item || item?.length == 0) {
|
|
143
|
-
reject(err ||
|
|
150
|
+
reject(err || "preload failed!");
|
|
144
151
|
}
|
|
145
152
|
resolve(item);
|
|
146
153
|
},
|
|
@@ -169,17 +176,18 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
169
176
|
const progress = assetProperty.progress;
|
|
170
177
|
const autoRelease = assetProperty.autoRelease;
|
|
171
178
|
|
|
172
|
-
if (!bundleName || bundleName ===
|
|
179
|
+
if (!bundleName || bundleName === "") {
|
|
173
180
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
174
181
|
return undefined;
|
|
175
182
|
}
|
|
176
183
|
|
|
177
|
-
if (!path || path ===
|
|
184
|
+
if (!path || path === "") {
|
|
178
185
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
179
186
|
return undefined;
|
|
180
187
|
}
|
|
181
188
|
|
|
182
|
-
let bundle: cc.AssetManager.Bundle =
|
|
189
|
+
let bundle: cc.AssetManager.Bundle =
|
|
190
|
+
await this.resMgr.loadBundle(bundleName);
|
|
183
191
|
|
|
184
192
|
if (!bundle) {
|
|
185
193
|
FW.Log.error(`加载bundle失败,请检查!`);
|
|
@@ -189,7 +197,8 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
189
197
|
|
|
190
198
|
if (this.assetsMap.has(key)) {
|
|
191
199
|
const assetData = this.assetsMap.get(key);
|
|
192
|
-
|
|
200
|
+
|
|
201
|
+
if (!assetData.loaded || !cc.isValid(assetData.asset)) {
|
|
193
202
|
this.assetsMap.delete(key);
|
|
194
203
|
} else {
|
|
195
204
|
return assetData;
|
|
@@ -206,7 +215,11 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
206
215
|
bundle.load(
|
|
207
216
|
path,
|
|
208
217
|
type,
|
|
209
|
-
(
|
|
218
|
+
(
|
|
219
|
+
finish: number,
|
|
220
|
+
total: number,
|
|
221
|
+
item: cc.AssetManager.RequestItem,
|
|
222
|
+
) => {
|
|
210
223
|
progress?.(finish, total, item);
|
|
211
224
|
},
|
|
212
225
|
(err: Error, asset: cc.Asset) => {
|
|
@@ -216,7 +229,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
216
229
|
}
|
|
217
230
|
assetData.loaded = true;
|
|
218
231
|
assetData.dependentBundle = bundleName;
|
|
219
|
-
assetData.uuid = asset[
|
|
232
|
+
assetData.uuid = asset["_uuid"];
|
|
220
233
|
assetData.autoRelease = autoRelease;
|
|
221
234
|
assetData.asset = asset;
|
|
222
235
|
assetData.user = assetProperty.user;
|
|
@@ -248,17 +261,18 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
248
261
|
const cb = assetProperty.cb;
|
|
249
262
|
const autoRelease = assetProperty.autoRelease;
|
|
250
263
|
|
|
251
|
-
if (!bundleName || bundleName ===
|
|
264
|
+
if (!bundleName || bundleName === "") {
|
|
252
265
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
253
266
|
return undefined;
|
|
254
267
|
}
|
|
255
268
|
|
|
256
|
-
if (!path || path ===
|
|
269
|
+
if (!path || path === "") {
|
|
257
270
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
258
271
|
return undefined;
|
|
259
272
|
}
|
|
260
273
|
|
|
261
|
-
const bundle: cc.AssetManager.Bundle =
|
|
274
|
+
const bundle: cc.AssetManager.Bundle =
|
|
275
|
+
await this.resMgr.loadBundle(bundleName);
|
|
262
276
|
|
|
263
277
|
if (!bundle) {
|
|
264
278
|
FW.Log.error(`加载bundle失败,请检查!`);
|
|
@@ -282,7 +296,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
282
296
|
const assetData = new FWAssetData();
|
|
283
297
|
assetData.loaded = true;
|
|
284
298
|
assetData.dependentBundle = bundleName;
|
|
285
|
-
assetData.uuid = asset[
|
|
299
|
+
assetData.uuid = asset["_uuid"];
|
|
286
300
|
assetData.autoRelease = autoRelease;
|
|
287
301
|
assetData.asset = asset;
|
|
288
302
|
assetData.type = type;
|
|
@@ -291,7 +305,7 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
291
305
|
const key = `${this.createAssetMapKey({
|
|
292
306
|
bundle: bundleName,
|
|
293
307
|
path: path,
|
|
294
|
-
})}/${asset.name}${type ? `_${type?.name}` :
|
|
308
|
+
})}/${asset.name}${type ? `_${type?.name}` : ""}`;
|
|
295
309
|
|
|
296
310
|
this.assetsMap.set(key, assetData);
|
|
297
311
|
|
|
@@ -318,18 +332,18 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
318
332
|
const bundleName = assetProperty.bundle || FW.Entry.bundleName;
|
|
319
333
|
const path = assetProperty.path;
|
|
320
334
|
|
|
321
|
-
if (!bundleName || bundleName ===
|
|
335
|
+
if (!bundleName || bundleName === "") {
|
|
322
336
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
323
337
|
return undefined;
|
|
324
338
|
}
|
|
325
339
|
|
|
326
|
-
if (!path || path ===
|
|
340
|
+
if (!path || path === "") {
|
|
327
341
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
328
342
|
return undefined;
|
|
329
343
|
}
|
|
330
344
|
|
|
331
345
|
if (!this.has(assetProperty)) {
|
|
332
|
-
FW.Log.error(
|
|
346
|
+
FW.Log.error("获取资源失败,请先加载!", assetProperty);
|
|
333
347
|
return undefined;
|
|
334
348
|
}
|
|
335
349
|
|
|
@@ -352,12 +366,12 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
352
366
|
const path = assetProperty.path;
|
|
353
367
|
const autoRelease = assetProperty.autoRelease;
|
|
354
368
|
|
|
355
|
-
if (!bundleName || bundleName ===
|
|
369
|
+
if (!bundleName || bundleName === "") {
|
|
356
370
|
FW.Log.error(`找不到bundle${bundleName},或者bundle未加载!`);
|
|
357
371
|
return undefined;
|
|
358
372
|
}
|
|
359
373
|
|
|
360
|
-
if (!path || path ===
|
|
374
|
+
if (!path || path === "") {
|
|
361
375
|
FW.Log.error(`找不到资源路径${path},请检查!`);
|
|
362
376
|
return undefined;
|
|
363
377
|
}
|
|
@@ -369,7 +383,12 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
369
383
|
const key = this.createAssetMapKey(assetProperty);
|
|
370
384
|
const assetData = this.assetsMap.get(key);
|
|
371
385
|
|
|
372
|
-
if (assetData.asset
|
|
386
|
+
if (!assetData || !assetData.asset) {
|
|
387
|
+
this.assetsMap.delete(key);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (assetData.asset.refCount <= 0 && autoRelease) {
|
|
373
392
|
this.resMgr.getBundle(bundleName)?.release(path);
|
|
374
393
|
this.assetsMap.delete(key);
|
|
375
394
|
}
|
|
@@ -403,10 +422,18 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
|
|
|
403
422
|
const bundleName = assetProperty.bundle || FW.Entry.bundleName;
|
|
404
423
|
const path = assetProperty.path;
|
|
405
424
|
const type = assetProperty.type;
|
|
406
|
-
|
|
425
|
+
|
|
426
|
+
let typeKey: string | undefined;
|
|
427
|
+
if (typeof type === "string") {
|
|
428
|
+
typeKey = type;
|
|
429
|
+
} else if (type) {
|
|
430
|
+
typeKey = (type as any).name;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (!typeKey) {
|
|
407
434
|
return `${bundleName}_${path}`;
|
|
408
435
|
}
|
|
409
|
-
return `${bundleName}_${path}_${
|
|
436
|
+
return `${bundleName}_${path}_${typeKey}`;
|
|
410
437
|
}
|
|
411
438
|
|
|
412
439
|
public onDestroy(): void {
|
|
@@ -217,7 +217,7 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
217
217
|
this.dataManager.removeFromRegistry(ctr.layerData?.controllerConstructor);
|
|
218
218
|
|
|
219
219
|
const index = this.stackManager.getStack().findIndex((v) => {
|
|
220
|
-
v.controller == ctr;
|
|
220
|
+
return v.controller == ctr;
|
|
221
221
|
});
|
|
222
222
|
if (index > -1) {
|
|
223
223
|
this.stackManager.getStack().splice(index, 1);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { FWManager } from
|
|
1
|
+
import { FWManager } from "./FWManager";
|
|
2
2
|
|
|
3
|
-
export default class FWPromiseManager
|
|
3
|
+
export default class FWPromiseManager
|
|
4
|
+
extends FWManager
|
|
5
|
+
implements FW.PromiseManager
|
|
6
|
+
{
|
|
4
7
|
private promiseRegistry: Map<number, FW.PromiseProxy<any>>;
|
|
5
8
|
private uniqueId: number = 0;
|
|
6
9
|
|
|
@@ -49,8 +52,11 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
49
52
|
const signal = {
|
|
50
53
|
aborted: isCancelled,
|
|
51
54
|
onabort: null as ((this: any, ev: Event) => any) | null,
|
|
52
|
-
addEventListener: (
|
|
53
|
-
|
|
55
|
+
addEventListener: (
|
|
56
|
+
type: string,
|
|
57
|
+
listener: (this: any, ev: Event) => any,
|
|
58
|
+
) => {
|
|
59
|
+
if (type === "abort") {
|
|
54
60
|
signal.onabort = listener;
|
|
55
61
|
}
|
|
56
62
|
},
|
|
@@ -72,13 +78,13 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
72
78
|
|
|
73
79
|
cancelPromiseResolve = () => {
|
|
74
80
|
if (signal.onabort) {
|
|
75
|
-
signal.onabort.call(signal, { type:
|
|
81
|
+
signal.onabort.call(signal, { type: "abort" } as Event);
|
|
76
82
|
}
|
|
77
83
|
abortListeners.forEach((listener) => {
|
|
78
84
|
try {
|
|
79
|
-
listener.call({ type:
|
|
85
|
+
listener.call({ type: "abort" }, { type: "abort" } as Event);
|
|
80
86
|
} catch (error) {
|
|
81
|
-
FW.Log.error(
|
|
87
|
+
FW.Log.error("Error in abort listener:", error);
|
|
82
88
|
}
|
|
83
89
|
});
|
|
84
90
|
};
|
|
@@ -91,14 +97,19 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
91
97
|
if (options.timeout && options.timeout > 0) {
|
|
92
98
|
timeoutPromise = new Promise<T>((_, timeoutReject) => {
|
|
93
99
|
timerSchedule = FW.Entry.timeMgr.scheduleOnce(() => {
|
|
94
|
-
const timeoutError = new Error(
|
|
100
|
+
const timeoutError = new Error(
|
|
101
|
+
`Promise ${id} timeout after ${options.timeout} ms`,
|
|
102
|
+
);
|
|
95
103
|
|
|
96
104
|
if (
|
|
97
105
|
retryCount < maxRetryTimes &&
|
|
98
|
-
(!options.retryCondition ||
|
|
106
|
+
(!options.retryCondition ||
|
|
107
|
+
options.retryCondition(timeoutError, retryCount))
|
|
99
108
|
) {
|
|
100
109
|
retryCount++;
|
|
101
|
-
FW.Log.debug(
|
|
110
|
+
FW.Log.debug(
|
|
111
|
+
`Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`,
|
|
112
|
+
);
|
|
102
113
|
|
|
103
114
|
if (retryInterval > 0) {
|
|
104
115
|
FW.Entry.timeMgr.scheduleOnce(() => {
|
|
@@ -110,7 +121,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
110
121
|
} else {
|
|
111
122
|
timeoutReject(timeoutError);
|
|
112
123
|
}
|
|
113
|
-
}, options.timeout);
|
|
124
|
+
}, options.timeout / 1000);
|
|
114
125
|
});
|
|
115
126
|
}
|
|
116
127
|
|
|
@@ -139,7 +150,8 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
139
150
|
|
|
140
151
|
if (
|
|
141
152
|
retryCount < maxRetryTimes &&
|
|
142
|
-
(!options.retryCondition ||
|
|
153
|
+
(!options.retryCondition ||
|
|
154
|
+
options.retryCondition(error, retryCount))
|
|
143
155
|
) {
|
|
144
156
|
retryCount++;
|
|
145
157
|
FW.Log.debug(
|
|
@@ -169,7 +181,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
169
181
|
status: FW.SystemDefine.FWPromiseStatus.PENDING,
|
|
170
182
|
abort: (reason?: any) => {
|
|
171
183
|
if (promiseProxy.status === FW.SystemDefine.FWPromiseStatus.PENDING) {
|
|
172
|
-
FW.Log.debug(reason ||
|
|
184
|
+
FW.Log.debug(reason || "promise cancelled");
|
|
173
185
|
cancelResolve?.();
|
|
174
186
|
promiseProxy.status = FW.SystemDefine.FWPromiseStatus.CANCELLED;
|
|
175
187
|
}
|
|
@@ -263,7 +275,10 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
263
275
|
value: value,
|
|
264
276
|
});
|
|
265
277
|
} catch (error) {
|
|
266
|
-
if (
|
|
278
|
+
if (
|
|
279
|
+
promiseProxy.status ===
|
|
280
|
+
FW.SystemDefine.FWPromiseStatus.CANCELLED
|
|
281
|
+
) {
|
|
267
282
|
result.cancelled.push(promiseProxy.id);
|
|
268
283
|
} else {
|
|
269
284
|
result.failed.push({
|
|
@@ -282,42 +297,45 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
282
297
|
cancelPromiseResolve = () => {
|
|
283
298
|
abortListeners.forEach((listener) => {
|
|
284
299
|
try {
|
|
285
|
-
listener.call({ type:
|
|
300
|
+
listener.call({ type: "abort" }, { type: "abort" } as Event);
|
|
286
301
|
} catch (error) {
|
|
287
|
-
FW.Log.error(
|
|
302
|
+
FW.Log.error("Error in abort listener:", error);
|
|
288
303
|
}
|
|
289
304
|
});
|
|
290
305
|
};
|
|
291
306
|
|
|
292
307
|
let timeoutPromise: Promise<FW.PromiseAllResult<T>> | null = null;
|
|
293
308
|
if (options.timeout && options.timeout > 0) {
|
|
294
|
-
timeoutPromise = new Promise<FW.PromiseAllResult<T>>(
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (
|
|
301
|
-
retryCount < maxRetryTimes &&
|
|
302
|
-
(!options.retryCondition || options.retryCondition(timeoutError, retryCount))
|
|
303
|
-
) {
|
|
304
|
-
retryCount++;
|
|
305
|
-
FW.Log.debug(
|
|
306
|
-
`All Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`,
|
|
309
|
+
timeoutPromise = new Promise<FW.PromiseAllResult<T>>(
|
|
310
|
+
(_, timeoutReject) => {
|
|
311
|
+
timerSchedule = FW.Entry.timeMgr.scheduleOnce(() => {
|
|
312
|
+
const timeoutError = new Error(
|
|
313
|
+
`All Promise ${id} timeout after ${options.timeout} ms`,
|
|
307
314
|
);
|
|
308
315
|
|
|
309
|
-
if (
|
|
310
|
-
|
|
316
|
+
if (
|
|
317
|
+
retryCount < maxRetryTimes &&
|
|
318
|
+
(!options.retryCondition ||
|
|
319
|
+
options.retryCondition(timeoutError, retryCount))
|
|
320
|
+
) {
|
|
321
|
+
retryCount++;
|
|
322
|
+
FW.Log.debug(
|
|
323
|
+
`All Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`,
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
if (retryInterval > 0) {
|
|
327
|
+
FW.Entry.timeMgr.scheduleOnce(() => {
|
|
328
|
+
createPromise().then(resolve, reject);
|
|
329
|
+
}, retryInterval);
|
|
330
|
+
} else {
|
|
311
331
|
createPromise().then(resolve, reject);
|
|
312
|
-
}
|
|
332
|
+
}
|
|
313
333
|
} else {
|
|
314
|
-
|
|
334
|
+
timeoutReject(timeoutError);
|
|
315
335
|
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}, options.timeout);
|
|
320
|
-
});
|
|
336
|
+
}, options.timeout / 1000);
|
|
337
|
+
},
|
|
338
|
+
);
|
|
321
339
|
}
|
|
322
340
|
|
|
323
341
|
const racePromises: Promise<FW.PromiseAllResult<T>>[] = [mainPromise];
|
|
@@ -327,7 +345,9 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
327
345
|
}
|
|
328
346
|
|
|
329
347
|
if (!isCancelled) {
|
|
330
|
-
const raceCancelPromise = cancelPromise as unknown as Promise<
|
|
348
|
+
const raceCancelPromise = cancelPromise as unknown as Promise<
|
|
349
|
+
FW.PromiseAllResult<T>
|
|
350
|
+
>;
|
|
331
351
|
racePromises.push(raceCancelPromise);
|
|
332
352
|
}
|
|
333
353
|
|
|
@@ -345,7 +365,8 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
345
365
|
|
|
346
366
|
if (
|
|
347
367
|
retryCount < maxRetryTimes &&
|
|
348
|
-
(!options.retryCondition ||
|
|
368
|
+
(!options.retryCondition ||
|
|
369
|
+
options.retryCondition(error, retryCount))
|
|
349
370
|
) {
|
|
350
371
|
retryCount++;
|
|
351
372
|
FW.Log.debug(
|
|
@@ -375,7 +396,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
375
396
|
status: FW.SystemDefine.FWPromiseStatus.PENDING,
|
|
376
397
|
abort: (reason?: any) => {
|
|
377
398
|
if (promiseProxy.status === FW.SystemDefine.FWPromiseStatus.PENDING) {
|
|
378
|
-
FW.Log.debug(reason ||
|
|
399
|
+
FW.Log.debug(reason || "all promise cancelled");
|
|
379
400
|
cancelResolve?.();
|
|
380
401
|
promiseProxy.status = FW.SystemDefine.FWPromiseStatus.CANCELLED;
|
|
381
402
|
}
|
|
@@ -413,7 +434,10 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
413
434
|
|
|
414
435
|
public cancel(id: number, reason?: any): boolean {
|
|
415
436
|
const promiseProxy = this.promiseRegistry.get(id);
|
|
416
|
-
if (
|
|
437
|
+
if (
|
|
438
|
+
promiseProxy &&
|
|
439
|
+
promiseProxy.status === FW.SystemDefine.FWPromiseStatus.PENDING
|
|
440
|
+
) {
|
|
417
441
|
promiseProxy.abort(reason);
|
|
418
442
|
return true;
|
|
419
443
|
}
|
package/manager/FWResManager.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FWSystemConfig } from
|
|
2
|
-
import { FWLodash } from
|
|
3
|
-
import { FWAssetManager } from
|
|
4
|
-
import { FWBundleManager } from
|
|
5
|
-
import { FWManager } from
|
|
1
|
+
import { FWSystemConfig } from "../config/FWSystemConfig";
|
|
2
|
+
import { FWLodash } from "../utils/FWLodash";
|
|
3
|
+
import { FWAssetManager } from "./FWAssetManager";
|
|
4
|
+
import { FWBundleManager } from "./FWBundleManager";
|
|
5
|
+
import { FWManager } from "./FWManager";
|
|
6
6
|
|
|
7
7
|
export class FWResManager extends FWManager implements FW.ResManager {
|
|
8
8
|
private bundleMgr: FW.BundleManager;
|
|
@@ -42,27 +42,31 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
42
42
|
const keys = Object.keys(preLoad);
|
|
43
43
|
|
|
44
44
|
if (keys.length > 0) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
const preloadRecursive = async (
|
|
46
|
+
obj: FW.LoadConfig | FW.AssetProperty,
|
|
47
|
+
) => {
|
|
48
|
+
for (const key of Object.keys(obj)) {
|
|
49
|
+
const value: any = (obj as any)[key];
|
|
50
|
+
|
|
51
|
+
if (value && typeof value.path === "string") {
|
|
52
|
+
const path: string = value.path;
|
|
53
|
+
const type: string = value.type;
|
|
54
|
+
const d: string = value.bundle || depend;
|
|
55
|
+
const priorityLoaded = value.priorityLoaded || false;
|
|
56
|
+
|
|
57
|
+
if (path && priorityLoaded) {
|
|
54
58
|
await this.assetMgr.load({
|
|
55
|
-
path
|
|
59
|
+
path,
|
|
56
60
|
bundle: d,
|
|
57
|
-
type
|
|
61
|
+
type,
|
|
58
62
|
});
|
|
59
63
|
}
|
|
60
|
-
} else {
|
|
61
|
-
|
|
64
|
+
} else if (value && typeof value === "object") {
|
|
65
|
+
await preloadRecursive(value);
|
|
62
66
|
}
|
|
63
|
-
}
|
|
67
|
+
}
|
|
64
68
|
};
|
|
65
|
-
|
|
69
|
+
await preloadRecursive(config.preLoad);
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
}
|
|
@@ -92,7 +96,10 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
92
96
|
return await this.assetMgr.loadSpineDataFromRemote(data);
|
|
93
97
|
}
|
|
94
98
|
|
|
95
|
-
async loadRemote<T extends cc.Asset = cc.Asset>(
|
|
99
|
+
async loadRemote<T extends cc.Asset = cc.Asset>(
|
|
100
|
+
url: string,
|
|
101
|
+
texture?: boolean,
|
|
102
|
+
): Promise<T> {
|
|
96
103
|
try {
|
|
97
104
|
const asset = await this.assetMgr.loadRemote(url);
|
|
98
105
|
if (texture) {
|
|
@@ -184,7 +191,10 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
184
191
|
* @param bundleName
|
|
185
192
|
* @returns
|
|
186
193
|
*/
|
|
187
|
-
getAssetData<T extends cc.Asset>(
|
|
194
|
+
getAssetData<T extends cc.Asset>(
|
|
195
|
+
assetProperty: FW.AssetProperty,
|
|
196
|
+
texture?: boolean,
|
|
197
|
+
) {
|
|
188
198
|
const res = this.assetMgr.get(assetProperty);
|
|
189
199
|
if (texture) {
|
|
190
200
|
return res;
|
|
@@ -196,7 +206,10 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
196
206
|
* @param assetProperty
|
|
197
207
|
* @returns
|
|
198
208
|
*/
|
|
199
|
-
getAsset<T extends cc.Asset>(
|
|
209
|
+
getAsset<T extends cc.Asset>(
|
|
210
|
+
assetProperty: FW.AssetProperty,
|
|
211
|
+
texture?: boolean,
|
|
212
|
+
): T {
|
|
200
213
|
const res = this.assetMgr.get(assetProperty);
|
|
201
214
|
if (texture) {
|
|
202
215
|
return res.asset as T;
|
package/manager/FWUiManager.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { searchChild } from
|
|
2
|
-
import { FWManager } from
|
|
1
|
+
import { searchChild } from "../expand/FWDecorator";
|
|
2
|
+
import { FWManager } from "./FWManager";
|
|
3
3
|
|
|
4
4
|
export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
5
5
|
private eventMap: Map<
|
|
@@ -22,7 +22,11 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
|
22
22
|
target.pauseSystemEvents(true);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
this.eventMap.forEach((
|
|
25
|
+
this.eventMap.forEach((evt) => {
|
|
26
|
+
if (evt.target === target) {
|
|
27
|
+
FW.Entry.evtMgr?.targetPause(evt.target);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
resumeEvent(target: FW.TargetType) {
|
|
@@ -32,7 +36,11 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
|
32
36
|
target.resumeSystemEvents(true);
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
this.eventMap.forEach((
|
|
39
|
+
this.eventMap.forEach((evt) => {
|
|
40
|
+
if (evt.target === target) {
|
|
41
|
+
FW.Entry.evtMgr?.targetResume(evt.target);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
unRegisterEvent(args: FW.RegisterArgs) {
|
|
@@ -112,7 +120,7 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
|
112
120
|
|
|
113
121
|
register(args: FW.RegisterArgs) {
|
|
114
122
|
if (!args.target) {
|
|
115
|
-
FW.Log.error(
|
|
123
|
+
FW.Log.error("注册事件失败,目标为空!");
|
|
116
124
|
return;
|
|
117
125
|
}
|
|
118
126
|
|
|
@@ -130,7 +138,10 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
|
130
138
|
|
|
131
139
|
if (!evt.enable) return;
|
|
132
140
|
|
|
133
|
-
if (
|
|
141
|
+
if (
|
|
142
|
+
Date.now() - evt.lastResponseTimestamp <
|
|
143
|
+
evt.responseInterval
|
|
144
|
+
) {
|
|
134
145
|
return;
|
|
135
146
|
}
|
|
136
147
|
|
|
@@ -139,7 +150,10 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
|
139
150
|
|
|
140
151
|
evt.lastResponseTimestamp = Date.now();
|
|
141
152
|
|
|
142
|
-
FW.Entry.evtMgr.dispatch(
|
|
153
|
+
FW.Entry.evtMgr.dispatch(
|
|
154
|
+
FW.EventDefine.SystemEvent.SYSTEM_EVENT_TIRGGER,
|
|
155
|
+
evt.target,
|
|
156
|
+
);
|
|
143
157
|
|
|
144
158
|
evt.cb?.bind(args.target)?.(e, c, evt.data);
|
|
145
159
|
},
|
|
@@ -169,7 +183,10 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
|
169
183
|
args9?: FW.EventManagerArgs,
|
|
170
184
|
args10?: FW.EventManagerArgs,
|
|
171
185
|
) => {
|
|
172
|
-
if (
|
|
186
|
+
if (
|
|
187
|
+
Date.now() - evt.lastResponseTimestamp <
|
|
188
|
+
(evt.responseInterval || 0)
|
|
189
|
+
) {
|
|
173
190
|
return;
|
|
174
191
|
}
|
|
175
192
|
evt.lastResponseTimestamp = Date.now();
|
package/package.json
CHANGED
package/service/http/FWHttp.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FWSystemConfig } from
|
|
1
|
+
import { FWSystemConfig } from "../../config/FWSystemConfig";
|
|
2
2
|
|
|
3
3
|
export class FWHttp extends FW.Service {
|
|
4
4
|
public initialize() {}
|
|
@@ -11,7 +11,13 @@ export class FWHttp extends FW.Service {
|
|
|
11
11
|
cb?: (response: string) => void,
|
|
12
12
|
tag?: string,
|
|
13
13
|
): Promise<string> {
|
|
14
|
-
return this.process(
|
|
14
|
+
return this.process(
|
|
15
|
+
url,
|
|
16
|
+
params,
|
|
17
|
+
cb,
|
|
18
|
+
tag,
|
|
19
|
+
FW.SystemDefine.FWHttpRequestType.GET,
|
|
20
|
+
);
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
protected async postMessage(
|
|
@@ -20,7 +26,13 @@ export class FWHttp extends FW.Service {
|
|
|
20
26
|
cb?: (response: string) => void,
|
|
21
27
|
tag?: string,
|
|
22
28
|
): Promise<string> {
|
|
23
|
-
return this.process(
|
|
29
|
+
return this.process(
|
|
30
|
+
url,
|
|
31
|
+
params,
|
|
32
|
+
cb,
|
|
33
|
+
tag,
|
|
34
|
+
FW.SystemDefine.FWHttpRequestType.POST,
|
|
35
|
+
);
|
|
24
36
|
}
|
|
25
37
|
|
|
26
38
|
private async process(
|
|
@@ -32,44 +44,58 @@ export class FWHttp extends FW.Service {
|
|
|
32
44
|
): Promise<string> {
|
|
33
45
|
let xhr: XMLHttpRequest;
|
|
34
46
|
|
|
35
|
-
const promiseProxy: FW.PromiseProxy<string> =
|
|
36
|
-
(
|
|
37
|
-
|
|
47
|
+
const promiseProxy: FW.PromiseProxy<string> =
|
|
48
|
+
FW.Entry.promiseMgr.execute<string>(
|
|
49
|
+
(resolve, reject, signal, reason) => {
|
|
50
|
+
xhr = new XMLHttpRequest();
|
|
51
|
+
|
|
52
|
+
xhr.onreadystatechange = () => {
|
|
53
|
+
if (xhr.readyState !== 4) return;
|
|
54
|
+
|
|
55
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
56
|
+
cb?.(xhr.response);
|
|
57
|
+
resolve(xhr.response);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
38
60
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
};
|
|
61
|
+
const errMsg = `http request failed, status: ${xhr.status}, url: ${url}`;
|
|
62
|
+
FW.Log.warn(errMsg);
|
|
63
|
+
reject(errMsg);
|
|
64
|
+
};
|
|
45
65
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
xhr.onerror = (err: any) => {
|
|
67
|
+
FW.Log.error("http request error:", err);
|
|
68
|
+
this.onError?.(err);
|
|
69
|
+
reject(`http request error:${err}`);
|
|
70
|
+
};
|
|
51
71
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
xhr.ontimeout = () => {
|
|
73
|
+
this.onTimeout?.();
|
|
74
|
+
reject(`http request timeout!`);
|
|
75
|
+
};
|
|
56
76
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
...FWSystemConfig.PromiseConfig.http,
|
|
62
|
-
retryCondition(error, retryCount) {
|
|
63
|
-
return error || xhr.readyState != 4 || (xhr.status !== 200 && retryCount < 3);
|
|
77
|
+
xhr.open(type as string, url, true);
|
|
78
|
+
xhr.send(params);
|
|
64
79
|
},
|
|
65
|
-
|
|
66
|
-
|
|
80
|
+
{
|
|
81
|
+
...FWSystemConfig.PromiseConfig.http,
|
|
82
|
+
retryCondition(error, retryCount) {
|
|
83
|
+
return (
|
|
84
|
+
!!error &&
|
|
85
|
+
retryCount < (FWSystemConfig.PromiseConfig.http.retryCount || 0)
|
|
86
|
+
);
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
);
|
|
67
90
|
|
|
68
91
|
promiseProxy.addAbortEventListener(() => {
|
|
69
92
|
xhr.abort();
|
|
70
93
|
});
|
|
71
94
|
|
|
72
|
-
return await this.invoke(
|
|
95
|
+
return await this.invoke(
|
|
96
|
+
promiseProxy.promise,
|
|
97
|
+
tag ? `http request ->${tag}` : "",
|
|
98
|
+
);
|
|
73
99
|
}
|
|
74
100
|
|
|
75
101
|
onError?(err: any);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FWSystemConfig } from
|
|
1
|
+
import { FWSystemConfig } from "../../config/FWSystemConfig";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* TODO 犹豫socket没有改版暂时已老的cmd字符串映射方式做,后期优化
|
|
@@ -106,10 +106,14 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
106
106
|
this.heartInternal = config?.heartInternal || defaultConfig.heartInternal;
|
|
107
107
|
this.heartTimeout = config?.heartTimeout || defaultConfig.heartTimeout;
|
|
108
108
|
this.heartWeakTime = config?.heartWeakTime || defaultConfig.heartWeakTime;
|
|
109
|
-
this.maxReconnectTimes =
|
|
110
|
-
|
|
111
|
-
this.
|
|
112
|
-
|
|
109
|
+
this.maxReconnectTimes =
|
|
110
|
+
config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
|
|
111
|
+
this.reconnectInternal =
|
|
112
|
+
config?.reconnectInternal || defaultConfig.reconnectInternal;
|
|
113
|
+
this.protocolSymbol =
|
|
114
|
+
config?.protocolSymbol || defaultConfig.protocolSymbol;
|
|
115
|
+
this.protocolPollingTime =
|
|
116
|
+
config?.protocolPollingTime || defaultConfig.protocolPollingTime;
|
|
113
117
|
|
|
114
118
|
this.promiseProxy = {
|
|
115
119
|
promise: undefined,
|
|
@@ -123,7 +127,7 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
123
127
|
|
|
124
128
|
return this.promiseProxy;
|
|
125
129
|
} catch (e) {
|
|
126
|
-
FW.Log.error(
|
|
130
|
+
FW.Log.error("创建socket失败:", e);
|
|
127
131
|
}
|
|
128
132
|
}
|
|
129
133
|
/**
|
|
@@ -201,16 +205,22 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
201
205
|
this.socket?.close();
|
|
202
206
|
this.socket = null;
|
|
203
207
|
|
|
204
|
-
this.createSocket(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
208
|
+
this.createSocket(
|
|
209
|
+
this.address,
|
|
210
|
+
this.tag,
|
|
211
|
+
this.socketSender,
|
|
212
|
+
this.socketHandle,
|
|
213
|
+
{
|
|
214
|
+
heartInternal: this.heartInternal,
|
|
215
|
+
heartTimeout: this.heartTimeout,
|
|
216
|
+
heartWeakTime: this.heartWeakTime,
|
|
217
|
+
maxReconnectTimes: this.maxReconnectTimes,
|
|
218
|
+
reconnectInternal: this.reconnectInternal,
|
|
219
|
+
protocolSymbol: this.protocolSymbol,
|
|
220
|
+
protocolPollingTime: this.protocolPollingTime,
|
|
221
|
+
certificate: this.certificate,
|
|
222
|
+
},
|
|
223
|
+
);
|
|
214
224
|
}
|
|
215
225
|
|
|
216
226
|
async send(msg: string) {
|
|
@@ -220,14 +230,15 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
220
230
|
const protocolKey = this.socketSender.getProtocolKey?.(msg);
|
|
221
231
|
if (protocolKey) {
|
|
222
232
|
const symbol = Symbol(protocolKey);
|
|
223
|
-
const registry =
|
|
233
|
+
const registry =
|
|
234
|
+
this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
|
|
224
235
|
const protocolPolling: FW.ProtocolPolling = {
|
|
225
236
|
msg: msg,
|
|
226
237
|
schedule: FW.Entry.timeMgr.schedule(
|
|
227
238
|
() => {
|
|
228
239
|
this.sendMessage(msg);
|
|
229
240
|
},
|
|
230
|
-
this.protocolPollingTime,
|
|
241
|
+
this.protocolPollingTime / 1000,
|
|
231
242
|
cc.macro.REPEAT_FOREVER,
|
|
232
243
|
this,
|
|
233
244
|
),
|
|
@@ -241,7 +252,7 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
241
252
|
|
|
242
253
|
/** 连接打开 */
|
|
243
254
|
private onSocketOpen() {
|
|
244
|
-
FW.Log.debug(
|
|
255
|
+
FW.Log.debug("on open!");
|
|
245
256
|
FW.Entry.timeMgr.unSchedule(this);
|
|
246
257
|
this.reconnectTimes = 0;
|
|
247
258
|
this.sendHeartTimestamp = 0;
|
|
@@ -285,16 +296,19 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
285
296
|
|
|
286
297
|
/** socket关闭 */
|
|
287
298
|
private onSocketClose() {
|
|
288
|
-
FW.Log.debug(
|
|
299
|
+
FW.Log.debug("on close!");
|
|
289
300
|
this.socketHandle?.onClose?.();
|
|
290
301
|
FW.Entry.timeMgr.scheduleOnce(
|
|
291
302
|
() => {
|
|
292
|
-
if (
|
|
293
|
-
|
|
303
|
+
if (
|
|
304
|
+
this.getReadyState() == WebSocket.CLOSING ||
|
|
305
|
+
this.getReadyState() == WebSocket.CLOSED
|
|
306
|
+
) {
|
|
307
|
+
FW.Log.debug("on close!");
|
|
294
308
|
this.reconnect();
|
|
295
309
|
}
|
|
296
310
|
},
|
|
297
|
-
this.reconnectInternal,
|
|
311
|
+
this.reconnectInternal / 1000,
|
|
298
312
|
this,
|
|
299
313
|
);
|
|
300
314
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
export default class FWResLoader {
|
|
2
|
+
/**
|
|
3
|
+
* 通过任务系统按帧加载资源
|
|
4
|
+
*/
|
|
5
|
+
public static threadLoad(options: {
|
|
6
|
+
assets: FW.AssetProperty[];
|
|
7
|
+
cb?: (progress: number) => void;
|
|
8
|
+
}): void {
|
|
9
|
+
const totalAssetsCount = options.assets.length;
|
|
10
|
+
let loadedAssetsCount = 0;
|
|
11
|
+
|
|
12
|
+
const task = FW.Entry.taskMgr.createTask({
|
|
13
|
+
frameBudget: 1 / 20,
|
|
14
|
+
tasksFrameCount: 5,
|
|
15
|
+
log: true,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const loadTask = async function* (): FW.TaskGenerator {
|
|
19
|
+
yield {
|
|
20
|
+
type: FW.EventDefine.TaskEvent.START,
|
|
21
|
+
progress: 0,
|
|
22
|
+
message: "资源加载开始",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
for (const asset of options.assets) {
|
|
26
|
+
try {
|
|
27
|
+
await FW.Entry.resMgr.loadAsset({
|
|
28
|
+
bundle: asset.bundle,
|
|
29
|
+
path: asset.path,
|
|
30
|
+
type: asset.type,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
loadedAssetsCount++;
|
|
34
|
+
|
|
35
|
+
const currentProgress = loadedAssetsCount / totalAssetsCount;
|
|
36
|
+
|
|
37
|
+
options.cb?.(currentProgress);
|
|
38
|
+
|
|
39
|
+
yield {
|
|
40
|
+
type: FW.EventDefine.TaskEvent.PROGRESS,
|
|
41
|
+
progress: currentProgress,
|
|
42
|
+
message: `资源加载中-> 资源路径:${asset.path} ,资源数:${loadedAssetsCount}/${totalAssetsCount},进度百分比:${currentProgress}`,
|
|
43
|
+
};
|
|
44
|
+
} catch (error) {
|
|
45
|
+
FW.Log.error(`加载资源失败: ${asset.path}`, error);
|
|
46
|
+
loadedAssetsCount++;
|
|
47
|
+
yield {
|
|
48
|
+
type: FW.EventDefine.TaskEvent.PROGRESS,
|
|
49
|
+
progress: loadedAssetsCount / totalAssetsCount,
|
|
50
|
+
message: `资源加载失败->: ${asset.path}`,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
yield {
|
|
56
|
+
type: FW.EventDefine.TaskEvent.COMPLETE,
|
|
57
|
+
progress: 1,
|
|
58
|
+
message: "资源加载完成",
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
task.start(loadTask);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 加载bundle并收集预加载资源
|
|
67
|
+
*/
|
|
68
|
+
public static async loadBundlesAndCollectAssets(
|
|
69
|
+
bundles: string[],
|
|
70
|
+
): Promise<{
|
|
71
|
+
priorityAssets: FW.AssetProperty[];
|
|
72
|
+
backStageAssets: FW.AssetProperty[];
|
|
73
|
+
}> {
|
|
74
|
+
const priorityAssets: FW.AssetProperty[] = [];
|
|
75
|
+
const backStageAssets: FW.AssetProperty[] = [];
|
|
76
|
+
|
|
77
|
+
for (const bundleName of bundles) {
|
|
78
|
+
await FW.Entry.resMgr.loadBundle(bundleName);
|
|
79
|
+
const assetsConfig = FW.Entry.getComponent<FW.AssetConfig>(
|
|
80
|
+
`${bundleName}${FW.SystemDefine.FWBindTag.CONFIG}`,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
if (!assetsConfig) continue;
|
|
84
|
+
|
|
85
|
+
const find = (o: any) => {
|
|
86
|
+
if (!o) return;
|
|
87
|
+
Object.keys(o).forEach((key) => {
|
|
88
|
+
const value: FW.AssetProperty | any = o[key];
|
|
89
|
+
const path: string = (value as any)?.path;
|
|
90
|
+
const priorityLoaded: boolean = (value as any)?.priorityLoaded;
|
|
91
|
+
if (path) {
|
|
92
|
+
(priorityLoaded ? priorityAssets : backStageAssets).push({
|
|
93
|
+
bundle: bundleName,
|
|
94
|
+
path,
|
|
95
|
+
});
|
|
96
|
+
} else if (typeof value === "object") {
|
|
97
|
+
find(value);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
find((assetsConfig as any).preLoad);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
priorityAssets,
|
|
107
|
+
backStageAssets,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 通过线程任务加载资源并返回完成Promise
|
|
113
|
+
*/
|
|
114
|
+
public static async loadAssetsWithThread(options: {
|
|
115
|
+
assets: FW.AssetProperty[];
|
|
116
|
+
cb?: (progress: number) => void;
|
|
117
|
+
}): Promise<void> {
|
|
118
|
+
const { assets, cb } = options;
|
|
119
|
+
if (!assets || assets.length === 0) {
|
|
120
|
+
cb?.(1);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return new Promise<void>((resolve) => {
|
|
125
|
+
let loadedCount = 0;
|
|
126
|
+
|
|
127
|
+
FWResLoader.threadLoad({
|
|
128
|
+
assets,
|
|
129
|
+
cb: (progress: number) => {
|
|
130
|
+
cb?.(progress);
|
|
131
|
+
if (++loadedCount >= assets.length) {
|
|
132
|
+
resolve();
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|