@ives_xxz/framework 2.3.9 → 2.3.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.
- package/manager/FWAudioManager.ts +27 -43
- package/package.json +1 -1
- package/service/socket/FWSocket.ts +8 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FWManager } from
|
|
1
|
+
import { FWManager } from './FWManager';
|
|
2
2
|
|
|
3
3
|
class FWAudioData {
|
|
4
4
|
clip: cc.AudioClip;
|
|
@@ -12,20 +12,17 @@ class FWAudioPoolItem {
|
|
|
12
12
|
constructor(
|
|
13
13
|
public audioId: number,
|
|
14
14
|
public startTime: number,
|
|
15
|
-
public tag?: string
|
|
15
|
+
public tag?: string,
|
|
16
16
|
) {}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export default class FWAudioManager
|
|
20
|
-
extends FWManager
|
|
21
|
-
implements FW.AudioManager
|
|
22
|
-
{
|
|
19
|
+
export default class FWAudioManager extends FWManager implements FW.AudioManager {
|
|
23
20
|
musicVolume: number = 1;
|
|
24
21
|
effectsVolume: number = 1;
|
|
25
22
|
soundVolume: number = 1;
|
|
26
23
|
|
|
27
24
|
private audioPool: Map<number, FWAudioPoolItem> = new Map();
|
|
28
|
-
private maxConcurrentAudio: number =
|
|
25
|
+
private maxConcurrentAudio: number = 1000;
|
|
29
26
|
private cleanupInterval: number = 5;
|
|
30
27
|
|
|
31
28
|
public initialize(): void {
|
|
@@ -36,21 +33,13 @@ export default class FWAudioManager
|
|
|
36
33
|
* 播放背景音乐
|
|
37
34
|
*/
|
|
38
35
|
async playMusic(path: string, volume?: number, loop?: boolean): Promise<void>;
|
|
39
|
-
async playMusic(
|
|
40
|
-
|
|
41
|
-
volume?: number,
|
|
42
|
-
loop?: boolean
|
|
43
|
-
): Promise<void>;
|
|
44
|
-
async playMusic(
|
|
45
|
-
assetProperty: FW.AssetProperty,
|
|
46
|
-
volume?: number,
|
|
47
|
-
loop?: boolean
|
|
48
|
-
): Promise<void>;
|
|
36
|
+
async playMusic(music: cc.AudioClip, volume?: number, loop?: boolean): Promise<void>;
|
|
37
|
+
async playMusic(assetProperty: FW.AssetProperty, volume?: number, loop?: boolean): Promise<void>;
|
|
49
38
|
async playMusic(): Promise<void> {
|
|
50
39
|
try {
|
|
51
40
|
const audioData = await this.processAudioArguments(
|
|
52
41
|
arguments,
|
|
53
|
-
FW.SystemDefine.FWAudioType.MUSIC
|
|
42
|
+
FW.SystemDefine.FWAudioType.MUSIC,
|
|
54
43
|
);
|
|
55
44
|
if (!audioData.clip) return;
|
|
56
45
|
|
|
@@ -63,7 +52,7 @@ export default class FWAudioManager
|
|
|
63
52
|
|
|
64
53
|
FW.Log.debug(`播放背景音乐: ${this.getAudioName(audioData.clip)}`);
|
|
65
54
|
} catch (e) {
|
|
66
|
-
FW.Log.error(
|
|
55
|
+
FW.Log.error('播放音乐失败:', e);
|
|
67
56
|
}
|
|
68
57
|
}
|
|
69
58
|
|
|
@@ -93,41 +82,40 @@ export default class FWAudioManager
|
|
|
93
82
|
cb?: (id: number) => void,
|
|
94
83
|
volume?: number,
|
|
95
84
|
loop?: boolean,
|
|
96
|
-
tag?: string
|
|
85
|
+
tag?: string,
|
|
97
86
|
): Promise<number>;
|
|
98
87
|
async play(
|
|
99
88
|
audio: cc.AudioClip,
|
|
100
89
|
cb?: (id: number) => void,
|
|
101
90
|
volume?: number,
|
|
102
91
|
loop?: boolean,
|
|
103
|
-
tag?: string
|
|
92
|
+
tag?: string,
|
|
104
93
|
): Promise<number>;
|
|
105
94
|
async play(
|
|
106
95
|
assetProperty: FW.AssetProperty,
|
|
107
96
|
cb?: (id: number) => void,
|
|
108
97
|
volume?: number,
|
|
109
98
|
loop?: boolean,
|
|
110
|
-
tag?: string
|
|
99
|
+
tag?: string,
|
|
111
100
|
): Promise<number>;
|
|
112
101
|
async play(): Promise<number> {
|
|
113
102
|
if (this.audioPool.size >= this.maxConcurrentAudio) {
|
|
114
103
|
this.clearFinishedAudio();
|
|
115
104
|
if (this.audioPool.size >= this.maxConcurrentAudio) {
|
|
116
|
-
FW.Log.warn(
|
|
105
|
+
FW.Log.warn('音频池已满,无法播放新音频');
|
|
117
106
|
return -1;
|
|
118
107
|
}
|
|
119
108
|
}
|
|
120
109
|
|
|
121
110
|
const audioData = await this.processAudioArguments(
|
|
122
111
|
arguments,
|
|
123
|
-
FW.SystemDefine.FWAudioType.SOUND
|
|
112
|
+
FW.SystemDefine.FWAudioType.SOUND,
|
|
124
113
|
);
|
|
125
114
|
if (!audioData.clip) return -1;
|
|
126
115
|
|
|
127
116
|
try {
|
|
128
117
|
return new Promise<number>(async (resolve, reject) => {
|
|
129
|
-
const volume =
|
|
130
|
-
(audioData.volume ?? this.soundVolume) * this.effectsVolume;
|
|
118
|
+
const volume = (audioData.volume ?? this.soundVolume) * this.effectsVolume;
|
|
131
119
|
const loop = audioData.loop ?? false;
|
|
132
120
|
const tag = audioData.tag;
|
|
133
121
|
|
|
@@ -144,7 +132,7 @@ export default class FWAudioManager
|
|
|
144
132
|
return id;
|
|
145
133
|
});
|
|
146
134
|
} catch (e) {
|
|
147
|
-
FW.Log.error(
|
|
135
|
+
FW.Log.error('播放音效失败:', e);
|
|
148
136
|
return -1;
|
|
149
137
|
}
|
|
150
138
|
}
|
|
@@ -162,24 +150,24 @@ export default class FWAudioManager
|
|
|
162
150
|
|
|
163
151
|
pauseAll(): void {
|
|
164
152
|
cc.audioEngine.pauseAll();
|
|
165
|
-
FW.Log.debug(
|
|
153
|
+
FW.Log.debug('暂停所有音效');
|
|
166
154
|
}
|
|
167
155
|
|
|
168
156
|
resumeAll(): void {
|
|
169
157
|
cc.audioEngine.resumeAll();
|
|
170
|
-
FW.Log.debug(
|
|
158
|
+
FW.Log.debug('恢复所有音效');
|
|
171
159
|
}
|
|
172
160
|
|
|
173
161
|
stopAll(): void {
|
|
174
162
|
cc.audioEngine.stopAll();
|
|
175
163
|
this.audioPool.clear();
|
|
176
|
-
FW.Log.debug(
|
|
164
|
+
FW.Log.debug('停止所有音效');
|
|
177
165
|
}
|
|
178
166
|
|
|
179
167
|
/** 设置播放音效是否静音 */
|
|
180
168
|
setSoundMute(mute: boolean): void {
|
|
181
169
|
this.soundVolume = mute ? 0 : 1;
|
|
182
|
-
FW.Log.debug(`音效${mute ?
|
|
170
|
+
FW.Log.debug(`音效${mute ? '静音' : '取消静音'}`);
|
|
183
171
|
}
|
|
184
172
|
|
|
185
173
|
/**
|
|
@@ -189,7 +177,7 @@ export default class FWAudioManager
|
|
|
189
177
|
try {
|
|
190
178
|
let clip: cc.AudioClip;
|
|
191
179
|
|
|
192
|
-
if (typeof assetProperty ===
|
|
180
|
+
if (typeof assetProperty === 'string') {
|
|
193
181
|
clip = await FW.Entry.resMgr.loadAsset<cc.AudioClip>({
|
|
194
182
|
path: assetProperty,
|
|
195
183
|
bundle: FW.Entry.bundleName,
|
|
@@ -250,7 +238,7 @@ export default class FWAudioManager
|
|
|
250
238
|
*/
|
|
251
239
|
private async processAudioArguments(
|
|
252
240
|
args: IArguments,
|
|
253
|
-
type: FW.SystemDefine.FWAudioType
|
|
241
|
+
type: FW.SystemDefine.FWAudioType,
|
|
254
242
|
): Promise<FWAudioData> {
|
|
255
243
|
const audioData = new FWAudioData();
|
|
256
244
|
const argsArray = Array.from(args);
|
|
@@ -279,7 +267,7 @@ export default class FWAudioManager
|
|
|
279
267
|
* 标准化资源属性
|
|
280
268
|
*/
|
|
281
269
|
private normalizeAssetProperty(input: any): FW.AssetProperty {
|
|
282
|
-
if (typeof input ===
|
|
270
|
+
if (typeof input === 'string') {
|
|
283
271
|
return {
|
|
284
272
|
path: input,
|
|
285
273
|
bundle: FW.Entry.bundleName,
|
|
@@ -291,9 +279,7 @@ export default class FWAudioManager
|
|
|
291
279
|
/**
|
|
292
280
|
* 加载音频片段
|
|
293
281
|
*/
|
|
294
|
-
private async loadAudioClip(
|
|
295
|
-
assetProperty: FW.AssetProperty
|
|
296
|
-
): Promise<cc.AudioClip> {
|
|
282
|
+
private async loadAudioClip(assetProperty: FW.AssetProperty): Promise<cc.AudioClip> {
|
|
297
283
|
try {
|
|
298
284
|
return await FW.Entry.resMgr.loadAsset<cc.AudioClip>(assetProperty);
|
|
299
285
|
} catch (e) {
|
|
@@ -305,19 +291,17 @@ export default class FWAudioManager
|
|
|
305
291
|
* 生成缓存键
|
|
306
292
|
*/
|
|
307
293
|
private getCacheKey(assetProperty: FW.AssetProperty): string {
|
|
308
|
-
if (typeof assetProperty ===
|
|
294
|
+
if (typeof assetProperty === 'string') {
|
|
309
295
|
return `${FW.Entry.bundleName}_${assetProperty}`;
|
|
310
296
|
}
|
|
311
|
-
return `${assetProperty.bundle || FW.Entry.bundleName}_${
|
|
312
|
-
assetProperty.path
|
|
313
|
-
}`;
|
|
297
|
+
return `${assetProperty.bundle || FW.Entry.bundleName}_${assetProperty.path}`;
|
|
314
298
|
}
|
|
315
299
|
|
|
316
300
|
/**
|
|
317
301
|
* 获取音频名称
|
|
318
302
|
*/
|
|
319
303
|
private getAudioName(clip: cc.AudioClip): string {
|
|
320
|
-
return clip.name ||
|
|
304
|
+
return clip.name || '未知音频';
|
|
321
305
|
}
|
|
322
306
|
|
|
323
307
|
/**
|
|
@@ -345,7 +329,7 @@ export default class FWAudioManager
|
|
|
345
329
|
this.clearFinishedAudio,
|
|
346
330
|
this.cleanupInterval,
|
|
347
331
|
cc.macro.REPEAT_FOREVER,
|
|
348
|
-
this
|
|
332
|
+
this,
|
|
349
333
|
);
|
|
350
334
|
}
|
|
351
335
|
|
package/package.json
CHANGED
|
@@ -294,10 +294,14 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
294
294
|
private onSocketClose() {
|
|
295
295
|
FW.Log.debug('on close!');
|
|
296
296
|
this.socketHandle?.onClose?.();
|
|
297
|
-
|
|
298
|
-
this.socket
|
|
299
|
-
|
|
300
|
-
|
|
297
|
+
|
|
298
|
+
if (this.socket) {
|
|
299
|
+
this.socket.onclose = null;
|
|
300
|
+
this.socket.onerror = null;
|
|
301
|
+
this.socket.onmessage = null;
|
|
302
|
+
this.socket.onopen = null;
|
|
303
|
+
}
|
|
304
|
+
|
|
301
305
|
FW.Entry.timeMgr.scheduleOnce(
|
|
302
306
|
() => {
|
|
303
307
|
if (
|