@eva/plugin-sound 2.0.1-beta.3 → 2.0.1-beta.31

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.
@@ -43,23 +43,52 @@ sound.utils.validateFormats({
43
43
  aac: 'audio/aac',
44
44
  });
45
45
  pixi_js.extensions.add(sound.soundAsset);
46
+ /**
47
+ * 音频系统
48
+ *
49
+ * SoundSystem 负责管理游戏中所有音频组件的加载和播放。
50
+ * 支持自动与游戏生命周期同步(暂停/恢复),
51
+ * 提供全局音频控制功能(全部暂停/恢复/停止)。
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const soundSystem = new SoundSystem({
56
+ * autoPauseAndStart: true,
57
+ * onError: (error) => console.error('Sound error:', error)
58
+ * });
59
+ *
60
+ * game.addSystem(soundSystem);
61
+ * ```
62
+ */
46
63
  let SoundSystem = class SoundSystem extends eva_js.System {
47
64
  constructor(obj) {
48
65
  super();
66
+ /** 是否与游戏生命周期同步暂停和启动 */
49
67
  this.autoPauseAndStart = true;
68
+ /** 管理的音频组件列表 */
50
69
  this.components = [];
70
+ /** 音频缓冲区缓存 */
51
71
  this.audioBufferCache = {};
52
72
  Object.assign(this, obj);
53
73
  if (obj === null || obj === void 0 ? void 0 : obj.useLegacy) {
54
74
  sound.sound.useLegacy = true;
55
75
  }
56
76
  }
77
+ /**
78
+ * 恢复播放所有被暂停的音频
79
+ */
57
80
  resumeAll() {
58
81
  sound.sound.resumeAll();
59
82
  }
83
+ /**
84
+ * 暂停所有正在播放的音频
85
+ */
60
86
  pauseAll() {
61
87
  sound.sound.pauseAll();
62
88
  }
89
+ /**
90
+ * 停止所有正在播放的音频
91
+ */
63
92
  stopAll() {
64
93
  sound.sound.stopAll();
65
94
  }
@@ -69,18 +98,32 @@ let SoundSystem = class SoundSystem extends eva_js.System {
69
98
  this.componentChanged(changed);
70
99
  }
71
100
  }
101
+ /**
102
+ * 游戏开始和游戏暂停后开始播放的时候调用。
103
+ *
104
+ * Called while the game to play when game pause.
105
+ */
72
106
  onResume() {
73
107
  if (!this.autoPauseAndStart) {
74
108
  return;
75
109
  }
76
110
  this.resumeAll();
77
111
  }
112
+ /**
113
+ * 游戏暂停的时候调用。
114
+ *
115
+ * Called while the game paused.
116
+ */
78
117
  onPause() {
79
118
  if (!this.autoPauseAndStart) {
80
119
  return;
81
120
  }
82
121
  this.pauseAll();
83
122
  }
123
+ /**
124
+ * System 被销毁的时候调用。
125
+ * Called while the system be destroyed.
126
+ */
84
127
  onDestroy() {
85
128
  this.components.forEach(component => {
86
129
  component.onDestroy();
@@ -121,6 +164,7 @@ let SoundSystem = class SoundSystem extends eva_js.System {
121
164
  });
122
165
  }
123
166
  };
167
+ /** 系统名称 */
124
168
  SoundSystem.systemName = 'SoundSystem';
125
169
  SoundSystem = __decorate([
126
170
  eva_js.decorators.componentObserver({
@@ -129,10 +173,30 @@ SoundSystem = __decorate([
129
173
  ], SoundSystem);
130
174
  var SoundSystem$1 = SoundSystem;
131
175
 
176
+ /**
177
+ * 音频组件
178
+ *
179
+ * Sound 组件用于在游戏对象上播放音频。
180
+ * 支持音频的播放、暂停、停止、音量控制、循环播放等功能。
181
+ * 基于 PixiJS Sound 库实现,提供了 Web Audio API 的完整功能。
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * const gameObject = new GameObject('bgm');
186
+ * gameObject.addComponent(new Sound({
187
+ * resource: 'background-music',
188
+ * autoplay: true,
189
+ * loop: true,
190
+ * volume: 0.5
191
+ * }));
192
+ * ```
193
+ */
132
194
  class Sound extends eva_js.Component {
133
195
  constructor() {
134
196
  super(...arguments);
197
+ /** 音频加载状态 */
135
198
  this.state = 'unloaded';
199
+ /** 音频配置参数 */
136
200
  this.config = {
137
201
  resource: '',
138
202
  autoplay: false,
@@ -142,12 +206,16 @@ class Sound extends eva_js.Component {
142
206
  seek: 0,
143
207
  speed: 1,
144
208
  };
209
+ /** 待执行的操作队列(用于资源加载前的操作缓存) */
145
210
  this.actionQueue = [];
211
+ /** 音频开始播放的时间 */
146
212
  this.startTime = 0;
147
213
  }
214
+ /** 获取音频系统上下文 */
148
215
  get systemContext() {
149
216
  return sound.sound.context.audioContext;
150
217
  }
218
+ /** 音频是否正在播放 */
151
219
  get playing() {
152
220
  if (!this.buffer)
153
221
  return false;
@@ -221,6 +289,7 @@ class Sound extends eva_js.Component {
221
289
  }
222
290
  }
223
291
  }
292
+ /** 组件名称 */
224
293
  Sound.componentName = 'Sound';
225
294
  var Sound$1 = Sound;
226
295
 
@@ -3,15 +3,42 @@ import { ComponentChanged } from '@eva/eva.js';
3
3
  import { Sound as Sound_2 } from '@pixi/sound';
4
4
  import { System } from '@eva/eva.js';
5
5
 
6
+ /**
7
+ * 音频组件
8
+ *
9
+ * Sound 组件用于在游戏对象上播放音频。
10
+ * 支持音频的播放、暂停、停止、音量控制、循环播放等功能。
11
+ * 基于 PixiJS Sound 库实现,提供了 Web Audio API 的完整功能。
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const gameObject = new GameObject('bgm');
16
+ * gameObject.addComponent(new Sound({
17
+ * resource: 'background-music',
18
+ * autoplay: true,
19
+ * loop: true,
20
+ * volume: 0.5
21
+ * }));
22
+ * ```
23
+ */
6
24
  export declare class Sound extends Component<SoundParams> {
25
+ /** 组件名称 */
7
26
  static componentName: string;
27
+ /** 获取音频系统上下文 */
8
28
  get systemContext(): AudioContext;
29
+ /** 音频系统目标节点 */
9
30
  systemDestination: GainNode;
31
+ /** 音频是否正在播放 */
10
32
  get playing(): boolean;
33
+ /** 音频加载状态 */
11
34
  state: 'unloaded' | 'loading' | 'loaded';
35
+ /** 音频配置参数 */
12
36
  config: SoundParams;
37
+ /** 待执行的操作队列(用于资源加载前的操作缓存) */
13
38
  private actionQueue;
39
+ /** 音频开始播放的时间 */
14
40
  startTime: number;
41
+ /** PixiJS Sound 缓冲区 */
15
42
  private buffer;
16
43
  get muted(): boolean;
17
44
  set muted(v: boolean);
@@ -38,19 +65,64 @@ declare interface SoundParams {
38
65
  onEnd?: () => void;
39
66
  }
40
67
 
68
+ /**
69
+ * 音频系统
70
+ *
71
+ * SoundSystem 负责管理游戏中所有音频组件的加载和播放。
72
+ * 支持自动与游戏生命周期同步(暂停/恢复),
73
+ * 提供全局音频控制功能(全部暂停/恢复/停止)。
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const soundSystem = new SoundSystem({
78
+ * autoPauseAndStart: true,
79
+ * onError: (error) => console.error('Sound error:', error)
80
+ * });
81
+ *
82
+ * game.addSystem(soundSystem);
83
+ * ```
84
+ */
41
85
  export declare class SoundSystem extends System {
86
+ /** 系统名称 */
42
87
  static systemName: string;
88
+ /** 是否与游戏生命周期同步暂停和启动 */
43
89
  private autoPauseAndStart;
90
+ /** 错误回调函数 */
44
91
  private onError;
92
+ /** 管理的音频组件列表 */
45
93
  private components;
94
+ /** 音频缓冲区缓存 */
46
95
  private audioBufferCache;
47
96
  constructor(obj?: SoundSystemParams);
97
+ /**
98
+ * 恢复播放所有被暂停的音频
99
+ */
48
100
  resumeAll(): void;
101
+ /**
102
+ * 暂停所有正在播放的音频
103
+ */
49
104
  pauseAll(): void;
105
+ /**
106
+ * 停止所有正在播放的音频
107
+ */
50
108
  stopAll(): void;
51
109
  update(): void;
110
+ /**
111
+ * 游戏开始和游戏暂停后开始播放的时候调用。
112
+ *
113
+ * Called while the game to play when game pause.
114
+ */
52
115
  onResume(): void;
116
+ /**
117
+ * 游戏暂停的时候调用。
118
+ *
119
+ * Called while the game paused.
120
+ */
53
121
  onPause(): void;
122
+ /**
123
+ * System 被销毁的时候调用。
124
+ * Called while the system be destroyed.
125
+ */
54
126
  onDestroy(): void;
55
127
  componentChanged(changed: ComponentChanged): Promise<void>;
56
128
  private add;
@@ -39,23 +39,52 @@ utils.validateFormats({
39
39
  aac: 'audio/aac',
40
40
  });
41
41
  extensions.add(soundAsset);
42
+ /**
43
+ * 音频系统
44
+ *
45
+ * SoundSystem 负责管理游戏中所有音频组件的加载和播放。
46
+ * 支持自动与游戏生命周期同步(暂停/恢复),
47
+ * 提供全局音频控制功能(全部暂停/恢复/停止)。
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const soundSystem = new SoundSystem({
52
+ * autoPauseAndStart: true,
53
+ * onError: (error) => console.error('Sound error:', error)
54
+ * });
55
+ *
56
+ * game.addSystem(soundSystem);
57
+ * ```
58
+ */
42
59
  let SoundSystem = class SoundSystem extends System {
43
60
  constructor(obj) {
44
61
  super();
62
+ /** 是否与游戏生命周期同步暂停和启动 */
45
63
  this.autoPauseAndStart = true;
64
+ /** 管理的音频组件列表 */
46
65
  this.components = [];
66
+ /** 音频缓冲区缓存 */
47
67
  this.audioBufferCache = {};
48
68
  Object.assign(this, obj);
49
69
  if (obj === null || obj === void 0 ? void 0 : obj.useLegacy) {
50
70
  sound.useLegacy = true;
51
71
  }
52
72
  }
73
+ /**
74
+ * 恢复播放所有被暂停的音频
75
+ */
53
76
  resumeAll() {
54
77
  sound.resumeAll();
55
78
  }
79
+ /**
80
+ * 暂停所有正在播放的音频
81
+ */
56
82
  pauseAll() {
57
83
  sound.pauseAll();
58
84
  }
85
+ /**
86
+ * 停止所有正在播放的音频
87
+ */
59
88
  stopAll() {
60
89
  sound.stopAll();
61
90
  }
@@ -65,18 +94,32 @@ let SoundSystem = class SoundSystem extends System {
65
94
  this.componentChanged(changed);
66
95
  }
67
96
  }
97
+ /**
98
+ * 游戏开始和游戏暂停后开始播放的时候调用。
99
+ *
100
+ * Called while the game to play when game pause.
101
+ */
68
102
  onResume() {
69
103
  if (!this.autoPauseAndStart) {
70
104
  return;
71
105
  }
72
106
  this.resumeAll();
73
107
  }
108
+ /**
109
+ * 游戏暂停的时候调用。
110
+ *
111
+ * Called while the game paused.
112
+ */
74
113
  onPause() {
75
114
  if (!this.autoPauseAndStart) {
76
115
  return;
77
116
  }
78
117
  this.pauseAll();
79
118
  }
119
+ /**
120
+ * System 被销毁的时候调用。
121
+ * Called while the system be destroyed.
122
+ */
80
123
  onDestroy() {
81
124
  this.components.forEach(component => {
82
125
  component.onDestroy();
@@ -117,6 +160,7 @@ let SoundSystem = class SoundSystem extends System {
117
160
  });
118
161
  }
119
162
  };
163
+ /** 系统名称 */
120
164
  SoundSystem.systemName = 'SoundSystem';
121
165
  SoundSystem = __decorate([
122
166
  decorators.componentObserver({
@@ -125,10 +169,30 @@ SoundSystem = __decorate([
125
169
  ], SoundSystem);
126
170
  var SoundSystem$1 = SoundSystem;
127
171
 
172
+ /**
173
+ * 音频组件
174
+ *
175
+ * Sound 组件用于在游戏对象上播放音频。
176
+ * 支持音频的播放、暂停、停止、音量控制、循环播放等功能。
177
+ * 基于 PixiJS Sound 库实现,提供了 Web Audio API 的完整功能。
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * const gameObject = new GameObject('bgm');
182
+ * gameObject.addComponent(new Sound({
183
+ * resource: 'background-music',
184
+ * autoplay: true,
185
+ * loop: true,
186
+ * volume: 0.5
187
+ * }));
188
+ * ```
189
+ */
128
190
  class Sound extends Component {
129
191
  constructor() {
130
192
  super(...arguments);
193
+ /** 音频加载状态 */
131
194
  this.state = 'unloaded';
195
+ /** 音频配置参数 */
132
196
  this.config = {
133
197
  resource: '',
134
198
  autoplay: false,
@@ -138,12 +202,16 @@ class Sound extends Component {
138
202
  seek: 0,
139
203
  speed: 1,
140
204
  };
205
+ /** 待执行的操作队列(用于资源加载前的操作缓存) */
141
206
  this.actionQueue = [];
207
+ /** 音频开始播放的时间 */
142
208
  this.startTime = 0;
143
209
  }
210
+ /** 获取音频系统上下文 */
144
211
  get systemContext() {
145
212
  return sound.context.audioContext;
146
213
  }
214
+ /** 音频是否正在播放 */
147
215
  get playing() {
148
216
  if (!this.buffer)
149
217
  return false;
@@ -217,6 +285,7 @@ class Sound extends Component {
217
285
  }
218
286
  }
219
287
  }
288
+ /** 组件名称 */
220
289
  Sound.componentName = 'Sound';
221
290
  var Sound$1 = Sound;
222
291
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-sound",
3
- "version": "2.0.1-beta.3",
3
+ "version": "2.0.1-beta.31",
4
4
  "description": "@eva/plugin-sound",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-sound.esm.js",
@@ -18,7 +18,7 @@
18
18
  "license": "MIT",
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
- "@eva/eva.js": "2.0.1-beta.3",
21
+ "@eva/eva.js": "2.0.1-beta.31",
22
22
  "eventemitter3": "^3.1.2",
23
23
  "pixi.js": "^8.8.1",
24
24
  "@pixi/sound": "^6.0.1"