@ives_xxz/framework 1.0.5 → 1.0.7
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 +6 -2
- package/define/FWEventDefine.ts +1 -0
- package/log/FWLog.ts +73 -56
- package/manager/FWAssetManager.ts +7 -1
- package/manager/FWBundleManager.ts +3 -0
- package/manager/FWResManager.ts +1 -0
- package/manager/FWTaskManager.ts +1 -1
- package/manager/FWTimeManager.ts +1 -1
- package/package.json +1 -1
- package/service/socket/FWSocket.ts +15 -21
- package/service/socket/FWSocketSender.ts +3 -3
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 = {
|
|
@@ -881,13 +885,13 @@ declare namespace FW {
|
|
|
881
885
|
*/
|
|
882
886
|
load(assetProperty: AssetProperty): Promise<AssetData>;
|
|
883
887
|
|
|
884
|
-
loadDir(assetProperty:
|
|
888
|
+
loadDir(assetProperty: AssetProperty): Promise<FW.AssetData[]>;
|
|
885
889
|
|
|
886
890
|
/**
|
|
887
891
|
* 获取资源
|
|
888
892
|
* @param asset
|
|
889
893
|
*/
|
|
890
|
-
get(assetProperty:
|
|
894
|
+
get(assetProperty: AssetProperty): AssetData;
|
|
891
895
|
|
|
892
896
|
/**
|
|
893
897
|
* 释放资源
|
package/define/FWEventDefine.ts
CHANGED
package/log/FWLog.ts
CHANGED
|
@@ -26,83 +26,100 @@ class FWLog {
|
|
|
26
26
|
private constructor() {}
|
|
27
27
|
|
|
28
28
|
public get debug() {
|
|
29
|
-
|
|
30
|
-
window.console
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
if (cc.sys.isBrowser)
|
|
30
|
+
return window.console.log.bind(
|
|
31
|
+
window.console,
|
|
32
|
+
`%c[debug]:${FW.Entry.timeMgr.getTime()}`,
|
|
33
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
34
|
+
FWSystemDefine.FWLogType.DEBUG,
|
|
35
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
return console.log;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
get send() {
|
|
39
|
-
|
|
40
|
-
window.console
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
if (cc.sys.isBrowser)
|
|
43
|
+
return window.console.log.bind(
|
|
44
|
+
window.console,
|
|
45
|
+
`%c[sendMsg]:${FW.Entry.timeMgr.getTime()}`,
|
|
46
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
47
|
+
FWSystemDefine.FWLogType.SOCKET_SEND,
|
|
48
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
49
|
+
);
|
|
50
|
+
return console.log;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
get receive() {
|
|
49
|
-
|
|
50
|
-
window.console
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
if (cc.sys.isBrowser)
|
|
55
|
+
return window.console.log.bind(
|
|
56
|
+
window.console,
|
|
57
|
+
`%c[receiveMsg]:${FW.Entry.timeMgr.getTime()}`,
|
|
58
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
59
|
+
FWSystemDefine.FWLogType.SOCKET_RECEIVE,
|
|
60
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
61
|
+
);
|
|
62
|
+
return console.log;
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
get request() {
|
|
59
|
-
|
|
60
|
-
window.console
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
if (cc.sys.isBrowser)
|
|
67
|
+
return window.console.log.bind(
|
|
68
|
+
window.console,
|
|
69
|
+
`%c[request]:${FW.Entry.timeMgr.getTime()}`,
|
|
70
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
71
|
+
FWSystemDefine.FWLogType.REQUEST,
|
|
72
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
73
|
+
);
|
|
74
|
+
return console.log;
|
|
66
75
|
}
|
|
67
76
|
|
|
68
77
|
get response() {
|
|
69
|
-
|
|
70
|
-
window.console
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
if (cc.sys.isBrowser)
|
|
79
|
+
return window.console.log.bind(
|
|
80
|
+
window.console,
|
|
81
|
+
`%c[response]:${FW.Entry.timeMgr.getTime()}`,
|
|
82
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
83
|
+
FWSystemDefine.FWLogType.RESPONSE,
|
|
84
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
85
|
+
);
|
|
86
|
+
return console.log;
|
|
76
87
|
}
|
|
77
88
|
|
|
78
89
|
get system() {
|
|
79
|
-
|
|
80
|
-
window.console
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
if (cc.sys.isBrowser)
|
|
91
|
+
return window.console.log.bind(
|
|
92
|
+
window.console,
|
|
93
|
+
`%c[system]:${FW.Entry.timeMgr.getTime()}`,
|
|
94
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
95
|
+
FWSystemDefine.FWLogType.SYSTEM,
|
|
96
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
97
|
+
);
|
|
98
|
+
return console.log;
|
|
86
99
|
}
|
|
87
100
|
|
|
88
101
|
get warn() {
|
|
89
|
-
|
|
90
|
-
window.console
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
if (cc.sys.isBrowser)
|
|
103
|
+
return window.console.warn.bind(
|
|
104
|
+
window.console,
|
|
105
|
+
`%c[warn]:${FW.Entry.timeMgr.getTime()}`,
|
|
106
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
107
|
+
FWSystemDefine.FWLogType.WARN,
|
|
108
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
109
|
+
);
|
|
110
|
+
return console.warn;
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
get error() {
|
|
99
|
-
|
|
100
|
-
window.console
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
114
|
+
if (cc.sys.isBrowser)
|
|
115
|
+
return window.console.error.bind(
|
|
116
|
+
window.console,
|
|
117
|
+
`%c[error]:${FW.Entry.timeMgr.getTime()}`,
|
|
118
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
119
|
+
FWSystemDefine.FWLogType.ERROR,
|
|
120
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
121
|
+
);
|
|
122
|
+
return console.error;
|
|
106
123
|
}
|
|
107
124
|
}
|
|
108
125
|
|
|
@@ -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
|
}
|
package/manager/FWResManager.ts
CHANGED
package/manager/FWTaskManager.ts
CHANGED
package/manager/FWTimeManager.ts
CHANGED
|
@@ -69,7 +69,7 @@ export class FWTimeManager extends FWManager implements FW.TimeManager {
|
|
|
69
69
|
cb: () => void,
|
|
70
70
|
time?: number,
|
|
71
71
|
repeat?: number,
|
|
72
|
-
target?:
|
|
72
|
+
target?: FW.TargetType,
|
|
73
73
|
tag?: string,
|
|
74
74
|
): FW.TimerSchedule {
|
|
75
75
|
const timer = new FWTimer();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FWSystemConfig } from
|
|
2
|
-
import FWLog from
|
|
3
|
-
import FWSocketHandle from
|
|
4
|
-
import FWSocketSender from
|
|
1
|
+
import { FWSystemConfig } from '../../config/FWSystemConfig';
|
|
2
|
+
import FWLog from '../../log/FWLog';
|
|
3
|
+
import FWSocketHandle from './FWSocketHandle';
|
|
4
|
+
import FWSocketSender from './FWSocketSender';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* TODO 犹豫socket没有改版暂时已老的cmd字符串映射方式做,后期优化
|
|
@@ -67,7 +67,7 @@ export default class FWSocket implements FW.Socket {
|
|
|
67
67
|
tag: string,
|
|
68
68
|
sender: FW.SocketSender,
|
|
69
69
|
handle: FW.SocketHandle,
|
|
70
|
-
config: FW.SocketConfig
|
|
70
|
+
config: FW.SocketConfig,
|
|
71
71
|
): FW.SocketPromiseProxy {
|
|
72
72
|
FW.Entry.timeMgr.unSchedule(this);
|
|
73
73
|
|
|
@@ -94,12 +94,9 @@ export default class FWSocket implements FW.Socket {
|
|
|
94
94
|
this.heartInternal = config?.heartInternal || defaultConfig.heartInternal;
|
|
95
95
|
this.heartTimeout = config?.heartTimeout || defaultConfig.heartTimeout;
|
|
96
96
|
this.heartWeakTime = config?.heartWeakTime || defaultConfig.heartWeakTime;
|
|
97
|
-
this.maxReconnectTimes =
|
|
98
|
-
|
|
99
|
-
this.
|
|
100
|
-
config?.reconnectInternal || defaultConfig.reconnectInternal;
|
|
101
|
-
this.protocolSymbol =
|
|
102
|
-
config?.protocolSymbol || defaultConfig.protocolSymbol;
|
|
97
|
+
this.maxReconnectTimes = config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
|
|
98
|
+
this.reconnectInternal = config?.reconnectInternal || defaultConfig.reconnectInternal;
|
|
99
|
+
this.protocolSymbol = config?.protocolSymbol || defaultConfig.protocolSymbol;
|
|
103
100
|
|
|
104
101
|
this.promiseProxy = {
|
|
105
102
|
promise: undefined,
|
|
@@ -160,12 +157,10 @@ export default class FWSocket implements FW.Socket {
|
|
|
160
157
|
}
|
|
161
158
|
|
|
162
159
|
reconnect(force?: boolean) {
|
|
163
|
-
if (force)
|
|
164
|
-
this.reconnectTimes = 0;
|
|
165
|
-
}
|
|
160
|
+
if (force) this.reconnectTimes = 0;
|
|
166
161
|
|
|
167
162
|
FWLog.debug(
|
|
168
|
-
`socket reconnect : reconnectTimes->${this.reconnectTimes},maxReconnectTimes->${this.maxReconnectTimes}
|
|
163
|
+
`socket reconnect : reconnectTimes->${this.reconnectTimes},maxReconnectTimes->${this.maxReconnectTimes}`,
|
|
169
164
|
);
|
|
170
165
|
if (++this.reconnectTimes >= this.maxReconnectTimes) {
|
|
171
166
|
this.handle?.onTimeout?.();
|
|
@@ -192,8 +187,7 @@ export default class FWSocket implements FW.Socket {
|
|
|
192
187
|
const protocolKey = this.sender.getProtocolKey?.(msg);
|
|
193
188
|
if (protocolKey) {
|
|
194
189
|
const symbol = Symbol(protocolKey);
|
|
195
|
-
const registry =
|
|
196
|
-
this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
|
|
190
|
+
const registry = this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
|
|
197
191
|
this.protocolRegistry.set(protocolKey, registry.add(symbol));
|
|
198
192
|
this.protocolContainer.set(symbol, msg);
|
|
199
193
|
}
|
|
@@ -203,7 +197,7 @@ export default class FWSocket implements FW.Socket {
|
|
|
203
197
|
|
|
204
198
|
/** 连接打开 */
|
|
205
199
|
private onSocketOpen() {
|
|
206
|
-
FWLog.debug(
|
|
200
|
+
FWLog.debug('on open!');
|
|
207
201
|
FW.Entry.timeMgr.unSchedule(this);
|
|
208
202
|
this.reconnectTimes = 0;
|
|
209
203
|
this.sendHeartTimestamp = 0;
|
|
@@ -235,7 +229,7 @@ export default class FWSocket implements FW.Socket {
|
|
|
235
229
|
},
|
|
236
230
|
this.heartInternal / 1000,
|
|
237
231
|
cc.macro.REPEAT_FOREVER,
|
|
238
|
-
this
|
|
232
|
+
this,
|
|
239
233
|
);
|
|
240
234
|
}
|
|
241
235
|
|
|
@@ -258,11 +252,11 @@ export default class FWSocket implements FW.Socket {
|
|
|
258
252
|
FW.Entry.timeMgr.scheduleOnce(
|
|
259
253
|
() => {
|
|
260
254
|
if (!this.isReconnect) return;
|
|
261
|
-
FWLog.debug(
|
|
255
|
+
FWLog.debug('on close!');
|
|
262
256
|
this.reconnect();
|
|
263
257
|
},
|
|
264
258
|
this.reconnectInternal,
|
|
265
|
-
this
|
|
259
|
+
this,
|
|
266
260
|
);
|
|
267
261
|
}
|
|
268
262
|
/** 消息处理 */
|
|
@@ -9,11 +9,11 @@ export default class FWSocketSender implements FW.SocketSender {
|
|
|
9
9
|
initialize?();
|
|
10
10
|
onDestroy?();
|
|
11
11
|
sendHeart?();
|
|
12
|
+
onHeart?(msg: any): Promise<boolean>;
|
|
13
|
+
onBeforeSendingMessage?(msg: any): string;
|
|
14
|
+
getProtocolKey?(msg: any): string;
|
|
12
15
|
|
|
13
16
|
send(msg: any) {
|
|
14
17
|
FW.Entry.socketMgr.getSocket()?.send(msg);
|
|
15
18
|
}
|
|
16
|
-
onHeart?(msg: any): Promise<boolean>;
|
|
17
|
-
onBeforeSendingMessage?(msg: any): string;
|
|
18
|
-
getProtocolKey?(msg: any): string;
|
|
19
19
|
}
|