@ives_xxz/framework 2.1.18 → 2.1.20

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.
@@ -23,5 +23,6 @@ export class CCEvent {
23
23
  }
24
24
 
25
25
  export class SystemEvent {
26
- SYSTEM_RESTART = 0;
26
+ SYSTEM_RESTART = 'SYSTEM_RESTART';
27
+ SYSTEM_EVENT_TIRGGER = 'SYSTEM_EVENT_TIRGGER';
27
28
  }
@@ -1,4 +1,4 @@
1
- import { FWManager } from './FWManager';
1
+ import { FWManager } from "./FWManager";
2
2
 
3
3
  class FWAudioData {
4
4
  clip: cc.AudioClip;
@@ -9,10 +9,17 @@ class FWAudioData {
9
9
  }
10
10
 
11
11
  class FWAudioPoolItem {
12
- constructor(public audioId: number, public startTime: number, public tag?: string) {}
12
+ constructor(
13
+ public audioId: number,
14
+ public startTime: number,
15
+ public tag?: string
16
+ ) {}
13
17
  }
14
18
 
15
- export default class FWAudioManager extends FWManager implements FW.AudioManager {
19
+ export default class FWAudioManager
20
+ extends FWManager
21
+ implements FW.AudioManager
22
+ {
16
23
  musicVolume: number = 1;
17
24
  effectsVolume: number = 1;
18
25
  soundVolume: number = 1;
@@ -29,13 +36,21 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
29
36
  * 播放背景音乐
30
37
  */
31
38
  async playMusic(path: string, volume?: number, loop?: boolean): Promise<void>;
32
- async playMusic(music: cc.AudioClip, volume?: number, loop?: boolean): Promise<void>;
33
- async playMusic(assetProperty: FW.AssetProperty, volume?: number, loop?: boolean): Promise<void>;
39
+ async playMusic(
40
+ music: cc.AudioClip,
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>;
34
49
  async playMusic(): Promise<void> {
35
50
  try {
36
51
  const audioData = await this.processAudioArguments(
37
52
  arguments,
38
- FW.SystemDefine.FWAudioType.MUSIC,
53
+ FW.SystemDefine.FWAudioType.MUSIC
39
54
  );
40
55
  if (!audioData.clip) return;
41
56
 
@@ -48,7 +63,7 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
48
63
 
49
64
  FW.Log.debug(`播放背景音乐: ${this.getAudioName(audioData.clip)}`);
50
65
  } catch (e) {
51
- FW.Log.error('播放音乐失败:', e);
66
+ FW.Log.error("播放音乐失败:", e);
52
67
  }
53
68
  }
54
69
 
@@ -78,40 +93,41 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
78
93
  cb?: (id: number) => void,
79
94
  volume?: number,
80
95
  loop?: boolean,
81
- tag?: string,
96
+ tag?: string
82
97
  ): Promise<number>;
83
98
  async play(
84
99
  audio: cc.AudioClip,
85
100
  cb?: (id: number) => void,
86
101
  volume?: number,
87
102
  loop?: boolean,
88
- tag?: string,
103
+ tag?: string
89
104
  ): Promise<number>;
90
105
  async play(
91
106
  assetProperty: FW.AssetProperty,
92
107
  cb?: (id: number) => void,
93
108
  volume?: number,
94
109
  loop?: boolean,
95
- tag?: string,
110
+ tag?: string
96
111
  ): Promise<number>;
97
112
  async play(): Promise<number> {
113
+ if (this.audioPool.size >= this.maxConcurrentAudio) {
114
+ this.clearFinishedAudio();
115
+ if (this.audioPool.size >= this.maxConcurrentAudio) {
116
+ FW.Log.warn("音频池已满,无法播放新音频");
117
+ return -1;
118
+ }
119
+ }
120
+
121
+ const audioData = await this.processAudioArguments(
122
+ arguments,
123
+ FW.SystemDefine.FWAudioType.SOUND
124
+ );
125
+ if (!audioData.clip) return -1;
126
+
98
127
  try {
99
128
  return new Promise<number>(async (resolve, reject) => {
100
- if (this.audioPool.size >= this.maxConcurrentAudio) {
101
- this.clearFinishedAudio();
102
- if (this.audioPool.size >= this.maxConcurrentAudio) {
103
- FW.Log.warn('音频池已满,无法播放新音频');
104
- return -1;
105
- }
106
- }
107
-
108
- const audioData = await this.processAudioArguments(
109
- arguments,
110
- FW.SystemDefine.FWAudioType.SOUND,
111
- );
112
- if (!audioData.clip) return -1;
113
-
114
- const volume = (audioData.volume ?? this.soundVolume) * this.effectsVolume;
129
+ const volume =
130
+ (audioData.volume ?? this.soundVolume) * this.effectsVolume;
115
131
  const loop = audioData.loop ?? false;
116
132
  const tag = audioData.tag;
117
133
 
@@ -128,7 +144,7 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
128
144
  return id;
129
145
  });
130
146
  } catch (e) {
131
- FW.Log.error('播放音效失败:', e);
147
+ FW.Log.error("播放音效失败:", e);
132
148
  return -1;
133
149
  }
134
150
  }
@@ -146,24 +162,24 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
146
162
 
147
163
  pauseAll(): void {
148
164
  cc.audioEngine.pauseAll();
149
- FW.Log.debug('暂停所有音效');
165
+ FW.Log.debug("暂停所有音效");
150
166
  }
151
167
 
152
168
  resumeAll(): void {
153
169
  cc.audioEngine.resumeAll();
154
- FW.Log.debug('恢复所有音效');
170
+ FW.Log.debug("恢复所有音效");
155
171
  }
156
172
 
157
173
  stopAll(): void {
158
174
  cc.audioEngine.stopAll();
159
175
  this.audioPool.clear();
160
- FW.Log.debug('停止所有音效');
176
+ FW.Log.debug("停止所有音效");
161
177
  }
162
178
 
163
179
  /** 设置播放音效是否静音 */
164
180
  setSoundMute(mute: boolean): void {
165
181
  this.soundVolume = mute ? 0 : 1;
166
- FW.Log.debug(`音效${mute ? '静音' : '取消静音'}`);
182
+ FW.Log.debug(`音效${mute ? "静音" : "取消静音"}`);
167
183
  }
168
184
 
169
185
  /**
@@ -173,7 +189,7 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
173
189
  try {
174
190
  let clip: cc.AudioClip;
175
191
 
176
- if (typeof assetProperty === 'string') {
192
+ if (typeof assetProperty === "string") {
177
193
  clip = await FW.Entry.resMgr.loadAsset<cc.AudioClip>({
178
194
  path: assetProperty,
179
195
  bundle: FW.Entry.bundleName,
@@ -234,7 +250,7 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
234
250
  */
235
251
  private async processAudioArguments(
236
252
  args: IArguments,
237
- type: FW.SystemDefine.FWAudioType,
253
+ type: FW.SystemDefine.FWAudioType
238
254
  ): Promise<FWAudioData> {
239
255
  const audioData = new FWAudioData();
240
256
  const argsArray = Array.from(args);
@@ -263,7 +279,7 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
263
279
  * 标准化资源属性
264
280
  */
265
281
  private normalizeAssetProperty(input: any): FW.AssetProperty {
266
- if (typeof input === 'string') {
282
+ if (typeof input === "string") {
267
283
  return {
268
284
  path: input,
269
285
  bundle: FW.Entry.bundleName,
@@ -275,7 +291,9 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
275
291
  /**
276
292
  * 加载音频片段
277
293
  */
278
- private async loadAudioClip(assetProperty: FW.AssetProperty): Promise<cc.AudioClip> {
294
+ private async loadAudioClip(
295
+ assetProperty: FW.AssetProperty
296
+ ): Promise<cc.AudioClip> {
279
297
  try {
280
298
  return await FW.Entry.resMgr.loadAsset<cc.AudioClip>(assetProperty);
281
299
  } catch (e) {
@@ -287,17 +305,19 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
287
305
  * 生成缓存键
288
306
  */
289
307
  private getCacheKey(assetProperty: FW.AssetProperty): string {
290
- if (typeof assetProperty === 'string') {
308
+ if (typeof assetProperty === "string") {
291
309
  return `${FW.Entry.bundleName}_${assetProperty}`;
292
310
  }
293
- return `${assetProperty.bundle || FW.Entry.bundleName}_${assetProperty.path}`;
311
+ return `${assetProperty.bundle || FW.Entry.bundleName}_${
312
+ assetProperty.path
313
+ }`;
294
314
  }
295
315
 
296
316
  /**
297
317
  * 获取音频名称
298
318
  */
299
319
  private getAudioName(clip: cc.AudioClip): string {
300
- return clip.name || '未知音频';
320
+ return clip.name || "未知音频";
301
321
  }
302
322
 
303
323
  /**
@@ -325,7 +345,7 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
325
345
  this.clearFinishedAudio,
326
346
  this.cleanupInterval,
327
347
  cc.macro.REPEAT_FOREVER,
328
- this,
348
+ this
329
349
  );
330
350
  }
331
351
 
@@ -138,6 +138,9 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
138
138
  if (button && !button.interactable) return;
139
139
 
140
140
  evt.lastResponseTimestamp = Date.now();
141
+
142
+ FW.Entry.evtMgr.dispatch(FW.EventDefine.SystemEvent.SYSTEM_EVENT_TIRGGER, evt.target);
143
+
141
144
  evt.cb?.bind(args.target)?.(e, c, evt.data);
142
145
  },
143
146
  args.target,
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "2.1.18",
3
+ "version": "2.1.20",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
- "keywords": ["123456"],
6
+ "keywords": [
7
+ "123456"
8
+ ],
7
9
  "author": "ives",
8
10
  "license": "ISC"
9
11
  }
package/types/FW.d.ts CHANGED
@@ -2638,7 +2638,8 @@ declare namespace FW {
2638
2638
  }
2639
2639
 
2640
2640
  export class SystemEvent {
2641
- static SYSTEM_RESTART = 0;
2641
+ static SYSTEM_RESTART = 'SYSTEM_RESTART';
2642
+ static SYSTEM_EVENT_TIRGGER = 'SYSTEM_EVENT_TIRGGER';
2642
2643
  }
2643
2644
 
2644
2645
  export class CCEvent {