@drincs/pixi-vn 1.8.4 → 1.8.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/dist/ContainerMemory-BjcfYRU7.d.cts +392 -0
- package/dist/ContainerMemory-BjcfYRU7.d.ts +392 -0
- package/dist/HistoryChoiceMenuOption-CEmjDDJH.d.cts +53 -0
- package/dist/HistoryChoiceMenuOption-CN7NkcxU.d.ts +53 -0
- package/dist/HistoryGameState-3ztYdv84.d.cts +12 -0
- package/dist/HistoryGameState-D4t2fY9x.d.ts +12 -0
- package/dist/HistoryStep-DtOryKAZ.d.cts +76 -0
- package/dist/HistoryStep-DtOryKAZ.d.ts +76 -0
- package/dist/OpenedLabel-DJby8qPc.d.ts +8 -0
- package/dist/OpenedLabel-t6PvSzaL.d.cts +8 -0
- package/dist/SoundManagerInterface-TgOPqm2L.d.cts +436 -0
- package/dist/SoundManagerInterface-TgOPqm2L.d.ts +436 -0
- package/dist/StepLabelType-CN97wZzm.d.cts +27 -0
- package/dist/StepLabelType-CN97wZzm.d.ts +27 -0
- package/dist/StorageGameState-BJy57o6K.d.ts +27 -0
- package/dist/StorageGameState-CtjNJpvE.d.cts +27 -0
- package/dist/{StoredClassModel-C9mQxPg-.d.cts → StoredClassModel-Bykjdn8S.d.cts} +1 -1
- package/dist/{StoredClassModel-upXPNQTp.d.ts → StoredClassModel-uMifeNzV.d.ts} +1 -1
- package/dist/canvas.cjs +2 -2
- package/dist/canvas.d.cts +54 -464
- package/dist/canvas.d.ts +54 -464
- package/dist/canvas.mjs +2 -2
- package/dist/characters.cjs +1 -1
- package/dist/characters.d.cts +5 -5
- package/dist/characters.d.ts +5 -5
- package/dist/characters.mjs +1 -1
- package/dist/{chunk-Z4GZCINS.mjs → chunk-3M6A7TU2.mjs} +1 -1
- package/dist/chunk-BQRPDCUT.mjs +1 -0
- package/dist/{chunk-YCWXA3OR.mjs → chunk-IFPF4NRX.mjs} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.d.cts +5 -114
- package/dist/core.d.ts +5 -114
- package/dist/core.mjs +1 -1
- package/dist/history.cjs +1 -1
- package/dist/history.d.cts +7 -11
- package/dist/history.d.ts +7 -11
- package/dist/history.mjs +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +20 -826
- package/dist/index.d.ts +20 -826
- package/dist/index.mjs +2 -2
- package/dist/motion.cjs +1 -1
- package/dist/motion.mjs +1 -1
- package/dist/narration.cjs +1 -1
- package/dist/narration.d.cts +57 -22
- package/dist/narration.d.ts +57 -22
- package/dist/narration.mjs +1 -1
- package/dist/pixi/index.d.cts +12 -0
- package/dist/sound.cjs +1 -1
- package/dist/sound.d.cts +4 -435
- package/dist/sound.d.ts +4 -435
- package/dist/sound.mjs +1 -1
- package/dist/storage.cjs +1 -1
- package/dist/storage.d.cts +4 -27
- package/dist/storage.d.ts +4 -27
- package/dist/storage.mjs +1 -1
- package/dist/vite-listener.d.cts +1 -1
- package/dist/vite-listener.d.ts +1 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/package.json +1 -1
- package/dist/HistoryChoiceMenuOption-CS41KG13.d.ts +0 -182
- package/dist/HistoryChoiceMenuOption-DdwePsOm.d.cts +0 -182
- package/dist/chunk-V34PMA2H.mjs +0 -1
package/dist/sound.d.ts
CHANGED
|
@@ -1,440 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { M as MediaInterface, b as MediaMemory, A as AudioChannelInterface, c as SoundManagerInterface } from './SoundManagerInterface-TgOPqm2L.js';
|
|
2
|
+
export { C as ChannelOptions, E as ExportedSound, a as ExportedSoundPlay, S as SoundGameState, d as SoundOptions, e as SoundPlay, f as SoundPlayOptions, g as SoundPlayOptionsWithChannel } from './SoundManagerInterface-TgOPqm2L.js';
|
|
2
3
|
import { C as CachedMap } from './CachedMap-DZLvJAnA.js';
|
|
4
|
+
import { Player, PlayerOptions, ToneAudioNode, ToneAudioBuffer } from 'tone';
|
|
3
5
|
import 'lru-cache';
|
|
4
6
|
|
|
5
|
-
interface MediaInterface extends Pick<Player, "blockTime" | "disposed" | "loaded" | "loop" | "loopEnd" | "loopStart" | "mute" | "now" | "playbackRate" | "reverse" | "restart" | "start" | "stop" | "chain" | "disconnect" | "volume" | "state"> {
|
|
6
|
-
/**
|
|
7
|
-
* Whether the sound is currently paused.
|
|
8
|
-
*/
|
|
9
|
-
paused: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated Use {@link mute} instead.
|
|
12
|
-
*/
|
|
13
|
-
muted: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated Use {@link playbackRate} instead.
|
|
16
|
-
*/
|
|
17
|
-
speed: number;
|
|
18
|
-
}
|
|
19
|
-
interface MediaMemory extends Partial<Omit<PlayerOptions, "url" | "volume">> {
|
|
20
|
-
/**
|
|
21
|
-
* The volume of this sound in the linear range [0, 1], where 0 is silence
|
|
22
|
-
* and 1 is full volume. Stored and restored in linear form; converted
|
|
23
|
-
* to/from Tone.js decibels internally.
|
|
24
|
-
*/
|
|
25
|
-
volume?: number;
|
|
26
|
-
elapsed: number | undefined;
|
|
27
|
-
paused: boolean;
|
|
28
|
-
delay?: number;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface SoundOptions extends Pick<Partial<PlayerOptions>, "loop" | "autostart" | "fadeIn" | "fadeOut" | "mute" | "loopEnd" | "loopStart" | "reverse" | "playbackRate"> {
|
|
32
|
-
/**
|
|
33
|
-
* The volume of this sound in the linear range [0, 1], where 0 is silence
|
|
34
|
-
* and 1 is full volume. This is converted to decibels internally before
|
|
35
|
-
* being passed to the Tone.js Player.
|
|
36
|
-
*/
|
|
37
|
-
volume?: number;
|
|
38
|
-
/**
|
|
39
|
-
* A collection of audio filters/effects to apply to this sound.
|
|
40
|
-
*
|
|
41
|
-
* Install "tone" for the full list of available filters.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* import * as Tone from "tone";
|
|
46
|
-
*
|
|
47
|
-
* const filters = [new Tone.FeedbackDelay("8n", 0.5)];
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
filters?: ToneAudioNode[];
|
|
51
|
-
/**
|
|
52
|
-
* @deprecated Use {@link playbackRate} instead.
|
|
53
|
-
*/
|
|
54
|
-
speed?: number;
|
|
55
|
-
/**
|
|
56
|
-
* @deprecated Use {@link mute} instead.
|
|
57
|
-
*/
|
|
58
|
-
muted?: boolean;
|
|
59
|
-
}
|
|
60
|
-
interface SoundPlayOptions extends SoundOptions {
|
|
61
|
-
/**
|
|
62
|
-
* The delay in seconds before playback starts. If specified, playback is
|
|
63
|
-
* scheduled to begin after the delay has elapsed rather than starting
|
|
64
|
-
* immediately in a paused state.
|
|
65
|
-
*/
|
|
66
|
-
delay?: number;
|
|
67
|
-
/**
|
|
68
|
-
* The offset in seconds from the start of the sound at which to begin playback.
|
|
69
|
-
*/
|
|
70
|
-
elapsed?: number;
|
|
71
|
-
}
|
|
72
|
-
interface SoundPlayOptionsWithChannel extends SoundPlayOptions {
|
|
73
|
-
/**
|
|
74
|
-
* The alias of the audio channel to play the sound on. If the channel does
|
|
75
|
-
* not exist it will be created automatically.
|
|
76
|
-
* Defaults to `SoundManagerInterface.defaultChannelAlias` ("general").
|
|
77
|
-
*/
|
|
78
|
-
channel?: string;
|
|
79
|
-
}
|
|
80
|
-
interface ChannelOptions extends Pick<SoundPlayOptions, "filters" | "muted" | "volume"> {
|
|
81
|
-
/**
|
|
82
|
-
* Whether this channel is a background channel.
|
|
83
|
-
* Background channels are special: media playing on them is not stopped
|
|
84
|
-
* when a scene changes, but continues in the background.
|
|
85
|
-
*/
|
|
86
|
-
background?: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* The stereo pan position for this channel in the range [-1, 1].
|
|
89
|
-
* -1 is full left, 0 is centre, 1 is full right.
|
|
90
|
-
* Defaults to 0.
|
|
91
|
-
*/
|
|
92
|
-
pan?: number;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
interface AudioChannelInterface {
|
|
96
|
-
/**
|
|
97
|
-
* The alias of the audio channel. This is used to reference the channel when playing sounds. The alias must be unique among all channels.
|
|
98
|
-
*/
|
|
99
|
-
readonly alias: string;
|
|
100
|
-
/**
|
|
101
|
-
* Plays a sound.
|
|
102
|
-
* @param alias The media and sound (asset) alias reference.
|
|
103
|
-
* @param options The options
|
|
104
|
-
* @return The sound instance,
|
|
105
|
-
* this cannot be reused after it is done playing. Returns a Promise if the sound
|
|
106
|
-
* has not yet loaded.
|
|
107
|
-
*/
|
|
108
|
-
play(alias: string, options?: SoundPlayOptions): Promise<MediaInterface>;
|
|
109
|
-
/**
|
|
110
|
-
* Plays a sound.
|
|
111
|
-
* @param mediaAlias The media alias reference.
|
|
112
|
-
* @param soundAlias The sound (asset) alias reference.
|
|
113
|
-
* @param options The options
|
|
114
|
-
* @return The sound instance,
|
|
115
|
-
* this cannot be reused after it is done playing. Returns a Promise if the sound
|
|
116
|
-
* has not yet loaded.
|
|
117
|
-
*/
|
|
118
|
-
play(mediaAlias: string, soundAlias: string, options?: SoundPlayOptions): Promise<MediaInterface>;
|
|
119
|
-
/**
|
|
120
|
-
* The stereo pan position for this channel in the range [-1, 1].
|
|
121
|
-
* -1 is full left, 0 is centre, 1 is full right.
|
|
122
|
-
*/
|
|
123
|
-
pan: number;
|
|
124
|
-
/**
|
|
125
|
-
* The volume of the audio channel, between 0 and 1. This is multiplied with the volume of each sound played through this channel.
|
|
126
|
-
*/
|
|
127
|
-
volume: number;
|
|
128
|
-
/**
|
|
129
|
-
* Whether the audio channel is muted. This is combined with the muted state of each sound played through this channel.
|
|
130
|
-
*/
|
|
131
|
-
muted: boolean;
|
|
132
|
-
/**
|
|
133
|
-
* The MediaInstances currently playing through this channel. This is read-only and cannot be modified directly. Use the play method to add new MediaInstances to this channel.
|
|
134
|
-
*/
|
|
135
|
-
readonly mediaInstances: MediaInterface[];
|
|
136
|
-
/**
|
|
137
|
-
* Whether this channel is a background channel.
|
|
138
|
-
* Background channels are special channels. Unlike normal channels, media connected to a background channel does not stop when a scene changes, but continues to play in the background.
|
|
139
|
-
*/
|
|
140
|
-
readonly background: boolean;
|
|
141
|
-
/**
|
|
142
|
-
* Stops all media currently playing through this channel.
|
|
143
|
-
* @return Instance for chaining.
|
|
144
|
-
*/
|
|
145
|
-
stopAll(): this;
|
|
146
|
-
/**
|
|
147
|
-
* Pauses any playing sounds.
|
|
148
|
-
* @return Instance for chaining.
|
|
149
|
-
*/
|
|
150
|
-
pauseAll(): this;
|
|
151
|
-
/**
|
|
152
|
-
* Resumes any sounds.
|
|
153
|
-
* @return Instance for chaining.
|
|
154
|
-
*/
|
|
155
|
-
resumeAll(): this;
|
|
156
|
-
/**
|
|
157
|
-
* Toggle muted property for all sounds.
|
|
158
|
-
* @return `true` if all sounds are muted.
|
|
159
|
-
*/
|
|
160
|
-
toggleMuteAll(): boolean;
|
|
161
|
-
/**
|
|
162
|
-
* Useful for inserting channel-wide audio effects such as reverb, delay or EQ.
|
|
163
|
-
*
|
|
164
|
-
* Install "tone" to use this method.
|
|
165
|
-
*
|
|
166
|
-
* @param nodes One or more Tone.js {@link ToneAudioNode} instances to chain in series.
|
|
167
|
-
* @return Instance for chaining.
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```ts
|
|
171
|
-
* import * as Tone from "tone";
|
|
172
|
-
*
|
|
173
|
-
* const channel = sound.findChannel("music");
|
|
174
|
-
*
|
|
175
|
-
* // Create a reverb effect and wait for its impulse response to be ready.
|
|
176
|
-
* const reverb = new Tone.Reverb({ decay: 2.5 });
|
|
177
|
-
*
|
|
178
|
-
* // Route the channel through the reverb to the master output.
|
|
179
|
-
* channel.chain(reverb);
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
chain(...nodes: ToneAudioNode[]): this;
|
|
183
|
-
/**
|
|
184
|
-
* **Advanced** — the raw `Tone.Param<"decibels">` for this channel's volume.
|
|
185
|
-
*
|
|
186
|
-
* Unlike the {@link volume} property (which uses a linear 0–1 scale), this
|
|
187
|
-
* Param works directly in **decibels** and exposes all Tone.js automation
|
|
188
|
-
* methods such as `rampTo`, `linearRampTo`, and `exponentialRampTo`.
|
|
189
|
-
*
|
|
190
|
-
* Use this when you need to smoothly automate volume over time instead of
|
|
191
|
-
* setting it instantly.
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* ```ts
|
|
195
|
-
* const channel = sound.findChannel("music");
|
|
196
|
-
*
|
|
197
|
-
* // Fade the volume from its current level to -12 dB over 3 seconds.
|
|
198
|
-
* channel.volumeParam.rampTo(-12, 3);
|
|
199
|
-
*
|
|
200
|
-
* // Fade to silence over 2 seconds.
|
|
201
|
-
* channel.volumeParam.rampTo(-Infinity, 2);
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
readonly volumeParam: Param<"decibels">;
|
|
205
|
-
/**
|
|
206
|
-
* **Advanced** — the raw `Tone.Param<"audioRange">` for this channel's
|
|
207
|
-
* stereo pan position.
|
|
208
|
-
*
|
|
209
|
-
* Unlike the {@link pan} property (which sets the value instantly), this
|
|
210
|
-
* Param exposes all Tone.js automation methods such as `rampTo`,
|
|
211
|
-
* `linearRampTo`, and `exponentialRampTo`.
|
|
212
|
-
*
|
|
213
|
-
* Use this when you need to smoothly automate panning over time instead of
|
|
214
|
-
* setting it instantly. Values range from -1 (full left) to 1 (full right).
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* ```ts
|
|
218
|
-
* const channel = sound.findChannel("music");
|
|
219
|
-
*
|
|
220
|
-
* // Gradually pan to the left over 3 seconds.
|
|
221
|
-
* channel.panParam.rampTo(-1, 3);
|
|
222
|
-
*
|
|
223
|
-
* // Return to centre over 2 seconds.
|
|
224
|
-
* channel.panParam.rampTo(0, 2);
|
|
225
|
-
* ```
|
|
226
|
-
*/
|
|
227
|
-
readonly panParam: Param<"audioRange">;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
type SoundFilterMemory = ({
|
|
231
|
-
filterType: "ReverbFilter";
|
|
232
|
-
} & Omit<Partial<ReverbOptions>, "context">) | ({
|
|
233
|
-
filterType: "FeedbackDelayFilter";
|
|
234
|
-
} & Omit<Partial<FeedbackDelayOptions>, "context">) | ({
|
|
235
|
-
filterType: "FreeverbFilter";
|
|
236
|
-
} & Omit<Partial<FreeverbOptions>, "context">) | ({
|
|
237
|
-
filterType: "DelayFilter";
|
|
238
|
-
} & Omit<Partial<DelayOptions>, "context">) | ({
|
|
239
|
-
filterType: "PingPongDelayFilter";
|
|
240
|
-
} & Omit<Partial<PingPongDelayOptions>, "context">) | ({
|
|
241
|
-
filterType: "GateFilter";
|
|
242
|
-
} & Omit<Partial<GateOptions>, "context">) | ({
|
|
243
|
-
filterType: "AutoFilterFilter";
|
|
244
|
-
} & Omit<Partial<AutoFilterOptions>, "context">) | ({
|
|
245
|
-
filterType: "BiquadFilterFilter";
|
|
246
|
-
} & Omit<Partial<BiquadFilterOptions>, "context">) | ({
|
|
247
|
-
filterType: "OnePoleFilterFilter";
|
|
248
|
-
} & Omit<Partial<OnePoleFilterOptions>, "context" | "frequency">) | ({
|
|
249
|
-
filterType: "FeedbackCombFilterFilter";
|
|
250
|
-
} & Omit<Partial<FeedbackCombFilterOptions>, "context">) | ({
|
|
251
|
-
filterType: "CustomFilter";
|
|
252
|
-
} & Omit<Partial<FilterOptions>, "context">) | ({
|
|
253
|
-
filterType: "ChorusFilter";
|
|
254
|
-
} & Omit<Partial<ChorusOptions>, "context">) | ({
|
|
255
|
-
filterType: "PhaserFilter";
|
|
256
|
-
} & Omit<Partial<PhaserOptions>, "context">) | ({
|
|
257
|
-
filterType: "TremoloFilter";
|
|
258
|
-
} & Omit<Partial<TremoloOptions>, "context">) | ({
|
|
259
|
-
filterType: "VibratoFilter";
|
|
260
|
-
} & Omit<Partial<VibratoOptions>, "context">) | ({
|
|
261
|
-
filterType: "CompressorFilter";
|
|
262
|
-
} & Omit<Partial<CompressorOptions>, "context">) | ({
|
|
263
|
-
filterType: "MidSideCompressorFilter";
|
|
264
|
-
} & Omit<Partial<MidSideCompressorOptions>, "context">) | ({
|
|
265
|
-
filterType: "MultibandCompressorFilter";
|
|
266
|
-
} & Omit<Partial<MultibandCompressorOptions>, "context">) | ({
|
|
267
|
-
filterType: "LimiterFilter";
|
|
268
|
-
} & Omit<Partial<LimiterOptions>, "context">) | ({
|
|
269
|
-
filterType: "GreaterThanFilter";
|
|
270
|
-
} & Omit<Partial<GreaterThanOptions>, "context">) | ({
|
|
271
|
-
filterType: "GreaterThanZeroFilter";
|
|
272
|
-
} & Omit<Partial<GreaterThanZeroOptions>, "context">) | ({
|
|
273
|
-
filterType: "DistortionFilter";
|
|
274
|
-
} & Omit<Partial<DistortionOptions>, "context">) | ({
|
|
275
|
-
filterType: "BitCrusherFilter";
|
|
276
|
-
} & Omit<Partial<BitCrusherOptions>, "context">) | ({
|
|
277
|
-
filterType: "Panner3DFilter";
|
|
278
|
-
} & Omit<Partial<Panner3DOptions>, "context">) | ({
|
|
279
|
-
filterType: "AutoPannerFilter";
|
|
280
|
-
} & Omit<Partial<AutoPannerOptions>, "context">) | ({
|
|
281
|
-
filterType: "StereoWidenerFilter";
|
|
282
|
-
} & Omit<Partial<StereoWidenerOptions>, "context">);
|
|
283
|
-
|
|
284
|
-
interface ExportedSound {
|
|
285
|
-
options: SoundOptions;
|
|
286
|
-
filters?: SoundFilterMemory[];
|
|
287
|
-
}
|
|
288
|
-
interface SoundPlay {
|
|
289
|
-
stepIndex: number;
|
|
290
|
-
paused: boolean;
|
|
291
|
-
options?: SoundPlayOptions | string;
|
|
292
|
-
}
|
|
293
|
-
interface ExportedSoundPlay extends SoundPlay {
|
|
294
|
-
sound: ExportedSound;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Interface exported sounds
|
|
298
|
-
*/
|
|
299
|
-
interface SoundGameState {
|
|
300
|
-
/**
|
|
301
|
-
* @deprecated
|
|
302
|
-
*/
|
|
303
|
-
soundsPlaying?: {
|
|
304
|
-
[key: string]: ExportedSoundPlay;
|
|
305
|
-
};
|
|
306
|
-
mediaInstances: {
|
|
307
|
-
[key: string]: {
|
|
308
|
-
channelAlias: string;
|
|
309
|
-
soundAlias: string;
|
|
310
|
-
stepCounter: number;
|
|
311
|
-
options: MediaMemory & {
|
|
312
|
-
filters?: SoundFilterMemory[];
|
|
313
|
-
delay?: number;
|
|
314
|
-
};
|
|
315
|
-
/**
|
|
316
|
-
* @deprecated Use options.paused instead.
|
|
317
|
-
*/
|
|
318
|
-
paused?: boolean;
|
|
319
|
-
};
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
interface SoundManagerInterface {
|
|
324
|
-
/** Master volume in the range [0, 1]. */
|
|
325
|
-
volumeAll: number;
|
|
326
|
-
/**
|
|
327
|
-
* @deprecated Global playback speed. This is not a well-supported feature and may be removed in a future release. Use individual sound speed options instead.
|
|
328
|
-
*/
|
|
329
|
-
speedAll: number;
|
|
330
|
-
/**
|
|
331
|
-
* The default channel alias used when playing a sound without specifying a
|
|
332
|
-
* channel. Defaults to `"general"`.
|
|
333
|
-
*/
|
|
334
|
-
defaultChannelAlias: string;
|
|
335
|
-
/**
|
|
336
|
-
* @deprecated Register sound assets directly via `PIXI.Assets` instead.
|
|
337
|
-
*/
|
|
338
|
-
add(alias: string, options: string): void;
|
|
339
|
-
/**
|
|
340
|
-
* Plays a sound.
|
|
341
|
-
* @param alias The media and sound (asset) alias reference.
|
|
342
|
-
* @param options The options.
|
|
343
|
-
* @returns The media instance (resolves immediately if already loaded).
|
|
344
|
-
*/
|
|
345
|
-
play(alias: string, options?: SoundPlayOptionsWithChannel): Promise<MediaInterface>;
|
|
346
|
-
play(mediaAlias: string, soundAlias: string, options?: SoundPlayOptionsWithChannel): Promise<MediaInterface>;
|
|
347
|
-
/**
|
|
348
|
-
* Plays a non-persistent ("transient") sound (e.g. UI / menu sounds).
|
|
349
|
-
* Transient playback is not tracked in save/export state.
|
|
350
|
-
*/
|
|
351
|
-
playTransient(alias: string, options?: Partial<PlayerOptions>): Promise<Player>;
|
|
352
|
-
/**
|
|
353
|
-
* Find a tracked media instance by alias.
|
|
354
|
-
*/
|
|
355
|
-
find(alias: string): MediaInterface | undefined;
|
|
356
|
-
/**
|
|
357
|
-
* Stop a tracked media instance and remove it from the manager.
|
|
358
|
-
*/
|
|
359
|
-
stop(alias: string): void;
|
|
360
|
-
/**
|
|
361
|
-
* Pause a tracked media instance.
|
|
362
|
-
*/
|
|
363
|
-
pause(alias: string): MediaInterface | undefined;
|
|
364
|
-
/**
|
|
365
|
-
* Resume a paused media instance.
|
|
366
|
-
*/
|
|
367
|
-
resume(alias: string): MediaInterface | undefined;
|
|
368
|
-
/** Duration in seconds of the loaded sound with the given alias. */
|
|
369
|
-
duration(alias: string): number;
|
|
370
|
-
/** Toggle mute on all sounds. Returns the new muted state. */
|
|
371
|
-
toggleMuteAll(): boolean;
|
|
372
|
-
/**
|
|
373
|
-
* Whether all sounds are currently muted. Note that individual channels or media instances may still be muted or unmuted; this is just the global master mute state.
|
|
374
|
-
*/
|
|
375
|
-
readonly muted: boolean;
|
|
376
|
-
/** Mute all sounds. */
|
|
377
|
-
muteAll(): this;
|
|
378
|
-
/** Unmute all sounds. */
|
|
379
|
-
unmuteAll(): this;
|
|
380
|
-
/** Stop all sounds. */
|
|
381
|
-
stopAll(): this;
|
|
382
|
-
/** Pause all sounds. */
|
|
383
|
-
pauseAll(): this;
|
|
384
|
-
/** Resume all sounds. */
|
|
385
|
-
resumeAll(): this;
|
|
386
|
-
/**
|
|
387
|
-
* Temporarily pause all currently-playing sounds (or just those in the given
|
|
388
|
-
* channel) without persisting the paused state. Useful for overlays / pause
|
|
389
|
-
* menus.
|
|
390
|
-
*
|
|
391
|
-
* Only sounds that are **actively playing** at the time of the call are paused;
|
|
392
|
-
* sounds that were already paused beforehand are left untouched so that they
|
|
393
|
-
* remain paused when {@link resumeUnsavedAll} is called later.
|
|
394
|
-
*
|
|
395
|
-
* When called without a channel argument all transient players started with
|
|
396
|
-
* {@link playTransient} are also stopped.
|
|
397
|
-
*/
|
|
398
|
-
pauseUnsavedAll(channel?: string): this;
|
|
399
|
-
/**
|
|
400
|
-
* Resume all sounds (or just those in the given channel) that were paused by
|
|
401
|
-
* the most recent call to {@link pauseUnsavedAll}. Sounds that were already
|
|
402
|
-
* paused before `pauseUnsavedAll` was called are **not** resumed.
|
|
403
|
-
*/
|
|
404
|
-
resumeUnsavedAll(channel?: string): this;
|
|
405
|
-
/**
|
|
406
|
-
* Stop all transient media instances started with {@link playTransient}.
|
|
407
|
-
*/
|
|
408
|
-
stopTransientAll(): this;
|
|
409
|
-
/** Load one or more sound assets. */
|
|
410
|
-
load(...alias: string[]): Promise<void>;
|
|
411
|
-
/** Trigger background loading of one or more sound assets. */
|
|
412
|
-
backgroundLoad(...alias: string[]): Promise<void>;
|
|
413
|
-
/** Trigger background loading of a sound bundle. */
|
|
414
|
-
backgroundLoadBundle(alias: string): Promise<void>;
|
|
415
|
-
/** Stop all sounds and clear internal state. */
|
|
416
|
-
clear(): void;
|
|
417
|
-
/**
|
|
418
|
-
* Add a new audio channel.
|
|
419
|
-
* Returns the created channel, or `undefined` if the alias already exists.
|
|
420
|
-
*/
|
|
421
|
-
addChannel(alias: string | string[], options?: ChannelOptions): AudioChannelInterface | undefined;
|
|
422
|
-
/**
|
|
423
|
-
* Find the channel for the given alias, creating it if it does not yet exist.
|
|
424
|
-
*/
|
|
425
|
-
findChannel(alias: string): AudioChannelInterface;
|
|
426
|
-
/** All registered audio channels. */
|
|
427
|
-
readonly channels: AudioChannelInterface[];
|
|
428
|
-
/**
|
|
429
|
-
* Export the current sound state, including currently playing sounds and their options, for saving or debugging purposes. This is not guaranteed to be stable across versions and may contain implementation details; it is not intended for use in general application code.
|
|
430
|
-
*/
|
|
431
|
-
export(): SoundGameState;
|
|
432
|
-
/**
|
|
433
|
-
* Restore a sound state exported by {@link export}. This will stop any currently playing sounds and replace them with the sounds specified in the exported state. This is not guaranteed to be stable across versions and may contain implementation details; it is not intended for use in general application code.
|
|
434
|
-
*/
|
|
435
|
-
restore(data: object): Promise<void>;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
7
|
type StopTime = Parameters<Player["stop"]>[0];
|
|
439
8
|
type StartTime = Parameters<Player["start"]>[0];
|
|
440
9
|
type StartOffset = Parameters<Player["start"]>[1];
|
|
@@ -497,4 +66,4 @@ declare namespace SoundRegistry {
|
|
|
497
66
|
*/
|
|
498
67
|
declare const sound: SoundManagerInterface;
|
|
499
68
|
|
|
500
|
-
export {
|
|
69
|
+
export { AudioChannelInterface, MediaInterface, SoundRegistry, sound };
|
package/dist/sound.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {i as i$1}from'./chunk-IWAXXFXE.mjs';import {e,d,f,g as g$1}from'./chunk-Z4GZCINS.mjs';import {GameUnifier,PixiError}from'@drincs/pixi-vn/core';import le from'@drincs/pixi-vn/pixi.js';import*as c from'tone';import {ToneAudioBuffer,Channel,Reverb,Time,PingPongDelay,FeedbackDelay,BitCrusher,Compressor,Delay,Distortion,FeedbackCombFilter,Freeverb,Gate,GreaterThan,GreaterThanZero,Limiter,MidSideCompressor,MultibandCompressor,Panner3D,Phaser,StereoWidener,AutoFilter,Chorus,Tremolo,Vibrato,AutoPanner,BiquadFilter,OnePoleFilter,Filter,Player,now}from'tone';var C;(s=>(s.mediaInstances=new Map,s.channels=new Map,s.transients=new Set,s.systemPausedAliases=new Set,s.bufferRegistry=new e({cacheSize:10})))(C||(C={}));var i=C;function T(a){return a.reduce((t,e)=>{switch(e.filterType){case "ReverbFilter":t.push(new Reverb({decay:e.decay,preDelay:e.preDelay,wet:e.wet}).toDestination());break;case "FeedbackDelayFilter":t.push(new FeedbackDelay({feedback:e.feedback,delayTime:e.delayTime,wet:e.wet}).toDestination());break;case "BitCrusherFilter":t.push(new BitCrusher({bits:e.bits}).toDestination());break;case "CompressorFilter":t.push(new Compressor({attack:e.attack,knee:e.knee,ratio:e.ratio,release:e.release,threshold:e.threshold}).toDestination());break;case "DelayFilter":t.push(new Delay({delayTime:e.delayTime,maxDelay:e.maxDelay}).toDestination());break;case "DistortionFilter":t.push(new Distortion({distortion:e.distortion,oversample:e.oversample,wet:e.wet}).toDestination());break;case "FeedbackCombFilterFilter":t.push(new FeedbackCombFilter({delayTime:e.delayTime,resonance:e.resonance}).toDestination());break;case "FreeverbFilter":t.push(new Freeverb({roomSize:e.roomSize,dampening:e.dampening,wet:e.wet}).toDestination());break;case "GateFilter":t.push(new Gate({threshold:e.threshold,smoothing:e.smoothing}).toDestination());break;case "GreaterThanFilter":t.push(new GreaterThan({value:e.value,convert:e.convert,maxValue:e.maxValue,minValue:e.minValue,units:e.units}).toDestination());break;case "GreaterThanZeroFilter":t.push(new GreaterThanZero);break;case "LimiterFilter":t.push(new Limiter({threshold:e.threshold}).toDestination());break;case "MidSideCompressorFilter":t.push(new MidSideCompressor({mid:e.mid,side:e.side}).toDestination());break;case "MultibandCompressorFilter":t.push(new MultibandCompressor({lowFrequency:e.lowFrequency,highFrequency:e.highFrequency,low:e.low,mid:e.mid,high:e.high}).toDestination());break;case "Panner3DFilter":t.push(new Panner3D({positionX:e.positionX,positionY:e.positionY,positionZ:e.positionZ,orientationX:e.orientationX,orientationY:e.orientationY,orientationZ:e.orientationZ,coneInnerAngle:e.coneInnerAngle,coneOuterAngle:e.coneOuterAngle,coneOuterGain:e.coneOuterGain,distanceModel:e.distanceModel,maxDistance:e.maxDistance,refDistance:e.refDistance,rolloffFactor:e.rolloffFactor,panningModel:e.panningModel}).toDestination());break;case "PhaserFilter":t.push(new Phaser({frequency:e.frequency,octaves:e.octaves,baseFrequency:e.baseFrequency,wet:e.wet,Q:e.Q,stages:e.stages}).toDestination());break;case "StereoWidenerFilter":t.push(new StereoWidener({width:e.width,wet:e.wet}).toDestination());break;case "PingPongDelayFilter":t.push(new PingPongDelay({wet:e.wet,delayTime:e.delayTime,feedback:e.feedback,maxDelay:e.maxDelay}).toDestination());break;case "AutoFilterFilter":t.push(new AutoFilter({frequency:e.frequency,depth:e.depth,baseFrequency:e.baseFrequency,octaves:e.octaves,filter:e.filter,wet:e.wet,type:e.type}).toDestination());break;case "BiquadFilterFilter":t.push(new BiquadFilter({frequency:e.frequency,detune:e.detune,Q:e.Q,type:e.type,gain:e.gain}).toDestination());break;case "OnePoleFilterFilter":t.push(new OnePoleFilter({type:e.type}).toDestination());break;case "CustomFilter":t.push(new Filter({frequency:e.frequency,Q:e.Q,type:e.type,detune:e.detune,gain:e.gain,rolloff:e.rolloff}).toDestination());break;case "ChorusFilter":t.push(new Chorus({frequency:e.frequency,delayTime:e.delayTime,depth:e.depth,type:e.type,spread:e.spread,feedback:e.feedback,wet:e.wet}).toDestination());break;case "TremoloFilter":t.push(new Tremolo({frequency:e.frequency,type:e.type,depth:e.depth,spread:e.spread,wet:e.wet}).toDestination());break;case "VibratoFilter":t.push(new Vibrato({maxDelay:e.maxDelay,frequency:e.frequency,depth:e.depth,type:e.type,wet:e.wet}).toDestination());break;case "AutoPannerFilter":t.push(new AutoPanner({frequency:e.frequency,type:e.type,depth:e.depth,channelCount:e.channelCount,wet:e.wet}).toDestination());break}return t},[])}function se(a){if(a)return Array.from(a).reduce((t,e)=>(e instanceof Reverb?t.push({filterType:"ReverbFilter",wet:e.wet.value,decay:Time(e.decay).toSeconds(),preDelay:Time(e.preDelay).toSeconds()}):e instanceof PingPongDelay?t.push({filterType:"PingPongDelayFilter",wet:e.wet.value,delayTime:e.delayTime.value,feedback:e.feedback.value}):e instanceof FeedbackDelay?t.push({filterType:"FeedbackDelayFilter",feedback:e.feedback.value,delayTime:e.delayTime.value,wet:e.wet.value}):e instanceof BitCrusher?t.push({filterType:"BitCrusherFilter",bits:e.bits.value,wet:e.wet.value}):e instanceof Compressor?t.push({filterType:"CompressorFilter",attack:e.attack.value,knee:e.knee.value,ratio:e.ratio.value,release:e.release.value,threshold:e.threshold.value}):e instanceof Delay?t.push({filterType:"DelayFilter",delayTime:e.delayTime.value,maxDelay:e.maxDelay}):e instanceof Distortion?t.push({filterType:"DistortionFilter",distortion:e.distortion,oversample:e.oversample,wet:e.wet.value}):e instanceof FeedbackCombFilter?t.push({filterType:"FeedbackCombFilterFilter",delayTime:e.delayTime.value,resonance:e.resonance.value}):e instanceof Freeverb?t.push({filterType:"FreeverbFilter",roomSize:e.roomSize.value,dampening:e.dampening,wet:e.wet.value}):e instanceof Gate?t.push({filterType:"GateFilter",threshold:e.threshold,smoothing:e.smoothing}):e instanceof GreaterThan?t.push({filterType:"GreaterThanFilter",value:e.comparator.value,convert:e.convert,maxValue:e.maxValue,minValue:e.minValue}):e instanceof GreaterThanZero?t.push({filterType:"GreaterThanZeroFilter"}):e instanceof Limiter?t.push({filterType:"LimiterFilter",threshold:e.threshold.value}):e instanceof MidSideCompressor?t.push({filterType:"MidSideCompressorFilter",mid:{attack:e.mid.attack.value,knee:e.mid.knee.value,ratio:e.mid.ratio.value,release:e.mid.release.value,threshold:e.mid.threshold.value},side:{attack:e.side.attack.value,knee:e.side.knee.value,ratio:e.side.ratio.value,release:e.side.release.value,threshold:e.side.threshold.value}}):e instanceof MultibandCompressor?t.push({filterType:"MultibandCompressorFilter",lowFrequency:e.lowFrequency.value,highFrequency:e.highFrequency.value,low:{attack:e.low.attack.value,knee:e.low.knee.value,ratio:e.low.ratio.value,release:e.low.release.value,threshold:e.low.threshold.value},mid:{attack:e.mid.attack.value,knee:e.mid.knee.value,ratio:e.mid.ratio.value,release:e.mid.release.value,threshold:e.mid.threshold.value},high:{attack:e.high.attack.value,knee:e.high.knee.value,ratio:e.high.ratio.value,release:e.high.release.value,threshold:e.high.threshold.value}}):e instanceof Panner3D?t.push({filterType:"Panner3DFilter",positionX:e.positionX.value,positionY:e.positionY.value,positionZ:e.positionZ.value,orientationX:e.orientationX.value,orientationY:e.orientationY.value,orientationZ:e.orientationZ.value,coneInnerAngle:e.coneInnerAngle,coneOuterAngle:e.coneOuterAngle,coneOuterGain:e.coneOuterGain,distanceModel:e.distanceModel,maxDistance:e.maxDistance,refDistance:e.refDistance,rolloffFactor:e.rolloffFactor,panningModel:e.panningModel}):e instanceof Phaser?t.push({filterType:"PhaserFilter",frequency:e.frequency.value,octaves:e.octaves,baseFrequency:e.baseFrequency,wet:e.wet.value,Q:e.Q.value}):e instanceof StereoWidener?t.push({filterType:"StereoWidenerFilter",width:e.width.value,wet:e.wet.value}):e instanceof AutoFilter?t.push({filterType:"AutoFilterFilter",type:e.type,frequency:e.frequency.value,depth:e.depth.value,baseFrequency:e.baseFrequency,octaves:e.octaves,filter:{Q:e.filter.Q.value,type:e.filter.type,rolloff:e.filter.rolloff},wet:e.wet.value}):e instanceof Chorus?t.push({filterType:"ChorusFilter",type:e.type,frequency:e.frequency.value,delayTime:e.delayTime,depth:e.depth,spread:e.spread,feedback:e.feedback.value,wet:e.wet.value}):e instanceof Tremolo?t.push({filterType:"TremoloFilter",type:e.type,frequency:e.frequency.value,depth:e.depth.value,spread:e.spread,wet:e.wet.value}):e instanceof Vibrato?t.push({filterType:"VibratoFilter",type:e.type,frequency:e.frequency.value,depth:e.depth.value,wet:e.wet.value}):e instanceof AutoPanner?t.push({filterType:"AutoPannerFilter",type:e.type,frequency:e.frequency.value,depth:e.depth.value,channelCount:e.channelCount,wet:e.wet.value}):e instanceof BiquadFilter?t.push({filterType:"BiquadFilterFilter",type:e.type,frequency:e.frequency.value,detune:e.detune.value,Q:e.Q.value,gain:e.gain.value}):e instanceof OnePoleFilter?t.push({filterType:"OnePoleFilterFilter",type:e.type}):e instanceof Filter?t.push({filterType:"CustomFilter",type:e.type,frequency:e.frequency.value,Q:e.Q.value,detune:e.detune.value,gain:e.gain.value,rolloff:e.rolloff}):f.warn(`Unsupported filter type for serialisation: ${e?.constructor?.name??e}, please report this to the developers if you encounter it.`),t),[])}function K(a){return a instanceof Reverb||a instanceof FeedbackDelay||a instanceof PingPongDelay||a instanceof BitCrusher||a instanceof Compressor||a instanceof Delay||a instanceof Distortion||a instanceof FeedbackCombFilter||a instanceof Freeverb||a instanceof Gate||a instanceof GreaterThan||a instanceof GreaterThanZero||a instanceof Limiter||a instanceof MidSideCompressor||a instanceof MultibandCompressor||a instanceof Panner3D||a instanceof Phaser||a instanceof StereoWidener||a instanceof AutoFilter||a instanceof Chorus||a instanceof Vibrato||a instanceof Tremolo||a instanceof AutoPanner||a instanceof BiquadFilter||a instanceof OnePoleFilter||a instanceof Filter}function h(a){return a<=0?-1/0:20*Math.log10(a)}function g(a){return a<=-1/0?0:10**(a/20)}async function P(a){if(i.bufferRegistry.has(a))return;let t=a;try{let e=le.Assets.resolver.resolve(a);e?.src&&(t=e.src);}catch{}try{let e=await ToneAudioBuffer.load(t),n=new ToneAudioBuffer(e);i.bufferRegistry.set(a,n);}catch(e){f.warn(`Failed to load audio buffer for "${a}" (url: "${t}"): ${e instanceof Error?e.message:e}`),i.bufferRegistry.set(a,new ToneAudioBuffer);}}var v=class extends Player{constructor(e,n,r,s,o={},l){super(o);d(this,"alias",e);d(this,"channelAlias",n);d(this,"soundAlias",r);d(this,"stepCounter",s);d(this,"delay",l);d(this,"options");d(this,"filters",new Set);d(this,"pausedAt");d(this,"playStartTime",now());this.options=o,this.playStartTime=now()+(l??0);}get memory(){let e=Math.max(0,this.pausedAt?this.pausedAt-this.playStartTime:now()-this.playStartTime),n=this.paused;return n&&i.systemPausedAliases.has(this.alias)&&(n=false),{...this.options,fadeIn:this.fadeIn,loop:this.loop,loopEnd:this.loopEnd,loopStart:this.loopStart,mute:this.mute,playbackRate:this.playbackRate,reverse:this.reverse,volume:g(this.volume.value),autostart:!this.paused,elapsed:e,paused:n,delay:this.delay}}set memory(e){this.paused=e.paused,this.loop!==(e.loop||false)&&(this.loop=e.loop||false),this.volume.value!==h(e.volume??1)&&(this.volume.value=h(e.volume??1)),this.mute!==(e.mute||false)&&(this.mute=e.mute||false),this.playbackRate!==(e.playbackRate??1)&&(this.playbackRate=e.playbackRate??1),this.reverse!==(e.reverse||false)&&(this.reverse=e.reverse||false),this.fadeIn!==(e.fadeIn||0)&&(this.fadeIn=e.fadeIn||0),this.loopStart!==(e.loopStart||0)&&(this.loopStart=e.loopStart||0),this.loopEnd!==(e.loopEnd||0)&&(this.loopEnd=e.loopEnd||0);}get paused(){return typeof this.pausedAt=="number"}set paused(e){let n=this.state;if(e)this.pausedAt=now(),n==="started"&&super.stop();else {let r;typeof this.pausedAt=="number"&&(r=this.pausedAt-this.playStartTime,this.pausedAt=void 0),n==="stopped"&&(this.delay?this.start(`+${this.delay}`,r):this.start(void 0,r));}}get muted(){return this.mute}set muted(e){this.mute=e;}get speed(){return this.playbackRate}set speed(e){this.playbackRate=e;}stop(e){return i.mediaInstances.delete(this.alias),super.stop(e)}start(e,n,r){let s=now(),o=s;if(typeof e=="number")o=e;else if(typeof e=="string"&&e.startsWith("+")){let m=Number(e.slice(1));Number.isNaN(m)||(o=s+m);}let l=typeof n=="number"?n:0;return this.playStartTime=o-l,super.start(e,n,r)}chain(...e){return e.forEach(n=>{K(n)&&(n.toDestination(),this.filters.add(n));}),super.chain(...e)}disconnect(e){return K(e)&&(e.disconnect(),this.filters.delete(e)),super.disconnect(e)}};var F=class{constructor(t,e={}){d(this,"alias",t);d(this,"toneChannel");d(this,"background");this.background=e.background??false,this.toneChannel=new Channel({volume:h(e.volume??1),mute:e.muted??false,pan:e.pan??0}).toDestination(),e.filters&&this.toneChannel.chain(...e.filters);}get volume(){return g(this.toneChannel.volume.value)}set volume(t){this.toneChannel.volume.value=h(t);}get volumeParam(){return this.toneChannel.volume}get pan(){return this.toneChannel.pan.value}set pan(t){this.toneChannel.pan.value=t;}get panParam(){return this.toneChannel.pan}get muted(){return this.toneChannel.mute}set muted(t){this.toneChannel.mute=t;}pauseAll(){for(let t of i.mediaInstances.values())t.channelAlias===this.alias&&!t.paused&&(t.paused=true);return this}resumeAll(){for(let t of i.mediaInstances.values())t.channelAlias===this.alias&&t.paused&&(t.paused=false);return this}chain(...t){return this.toneChannel.chain(...t),this}_createPlayer(t,e,n={}){let r=i.bufferRegistry.get(e);if(!r)throw new PixiError("unregistered_asset",`Sound buffer for alias "${e}" is not loaded. Call sound.load() first.`);let{delay:s,elapsed:o,filters:l=[],muted:m,autostart:y=true,speed:p,volume:A,...f$1}=n;m!==void 0&&(f.warn(`MediaInstance "${t}" is being created with muted=${m}. This will override the channel's muted state (${this.muted}).`),f$1.mute=m),p!==void 0&&(f.warn(`MediaInstance "${t}" is being created with speed=${p}. This will override the default playback speed of 1.`),f$1.playbackRate=p);let O=new v(t,this.alias,e,GameUnifier.stepCounter,{...f$1,volume:A!==void 0?h(A):void 0,url:r},s).chain(...l,this.toneChannel),ne=o!==void 0?Math.max(0,o):void 0;return y&&(s?O.start(`+${s}`,ne):O.start(void 0,ne)),O}async play(t,e,n){let r,s;if(typeof e=="string"?(r=t,s=e):(r=t,s=t,n=e),i.mediaInstances.has(r)){let l=i.mediaInstances.get(r);l&&(l.stop(),n={...l.memory,...n,filters:[...l.filters,...n?.filters||[]]});}await P(s);let o=this._createPlayer(r,s,n);return i.mediaInstances.set(r,o),o}toggleMuteAll(){return this.muted=!this.muted,this.muted}get mediaInstances(){return Array.from(i.mediaInstances.values()).reduce((t,e)=>(e.channelAlias===this.alias&&t.push(e),t),[])}stopAll(){let t=[];for(let[e,n]of i.mediaInstances.entries())n.channelAlias===this.alias&&(n.stop(),t.push(e));return t.forEach(e=>{i.mediaInstances.delete(e);}),this}};var w=class{constructor(){d(this,"_speedAll",1);d(this,"_defaultChannelAlias",i$1);}get volumeAll(){return g(c.getDestination().volume.value)}set volumeAll(t){c.getDestination().volume.value=h(t);}get speedAll(){return this._speedAll}set speedAll(t){this._speedAll=t;for(let e of i.mediaInstances.values())e.speed=t;}get defaultChannelAlias(){return this._defaultChannelAlias}set defaultChannelAlias(t){this._defaultChannelAlias=t;}add(t,e){if(!i.bufferRegistry.has(t)){let n=new c.ToneAudioBuffer(e);i.bufferRegistry.set(t,n);}}pauseAll(){for(let t of i.mediaInstances.values())t.paused||(t.paused=true);return this}resumeAll(){for(let t of i.mediaInstances.values())t.paused&&(t.paused=false);return this}get muted(){return c.getDestination().mute}toggleMuteAll(){let t=!c.getDestination().mute;return c.getDestination().mute=t,t}muteAll(){return c.getDestination().mute=true,this}unmuteAll(){return c.getDestination().mute=false,this}stopAll(){for(let t of i.mediaInstances.values())t.stop();return i.mediaInstances.clear(),this}pauseUnsavedAll(t){for(let[e,n]of i.mediaInstances.entries())t&&n.channelAlias!==t||n.paused||(n.paused=true,i.systemPausedAliases.add(e));if(!t){for(let e of i.transients)e.stop();i.transients.clear();}return this}resumeUnsavedAll(t){let e=[];for(let n of i.systemPausedAliases){let r=i.mediaInstances.get(n);if(!r){e.push(n);continue}t&&r.channelAlias!==t||(r.paused=false,e.push(n));}for(let n of e)i.systemPausedAliases.delete(n);return this}stopTransientAll(){for(let t of i.transients)t.stop();return i.transients.clear(),this}async play(t,e,n){let r,s;typeof e=="string"?(r=t,s=e):(r=t,s=t,n=e),i.bufferRegistry.has(s)||await this.load(s);let{channel:o=this.defaultChannelAlias,...l}=n??{};return await this.findChannel(o).play(r,s,l)}async playTransient(t,e){i.bufferRegistry.has(t)||await this.load(t);let n=i.bufferRegistry.get(t);if(!n)throw new PixiError("unregistered_asset",`Sound buffer for alias "${t}" is not loaded. Call sound.load() first.`);let{autostart:r=true,...s}=e??{},o=new c.Player({...s,url:n}).toDestination();return r&&o.start(),i.transients.add(o),o.onstop=()=>{o.dispose(),i.transients.delete(o);},o}find(t){return i.mediaInstances.get(t)}stop(t){let e=this.find(t);e?(e.stop(),i.mediaInstances.delete(t)):f.warn(`No media instance found with alias ${t} to stop.`);}pause(t){let e=this.find(t);if(!e){f.warn(`No media instance found with alias ${t} to pause.`);return}return e.paused=true,e}resume(t){let e=this.find(t);if(!e){f.warn(`No media instance found with alias ${t} to resume.`);return}return e.paused=false,e}duration(t){return i.bufferRegistry.get(t)?.duration??0}async load(...t){let e=t.map(P);await Promise.all(e);}backgroundLoad(...t){return this.load(...t).catch(e=>{f.error("Error background-loading sound",e);})}backgroundLoadBundle(t){let e=le.Assets.backgroundLoadBundle(t);return e.then(async()=>{try{let n=await le.Assets.loadBundle(t),r=[];for(let s in n)i.bufferRegistry.has(s)||r.push(this.load(s));await Promise.all(r);}catch(n){f.error("Error loading sound bundle",n);}}).catch(n=>{f.error("Error background-loading sound bundle",n);}),e}clear(){this.stopAll();}addChannel(t,e={}){if(typeof t!="string"){t.forEach(r=>{let s={...e,filters:e.filters?[...e.filters]:e.filters};this.addChannel(r,s);});return}if(i.channels.has(t)){f.warn(`Channel with alias ${t} already exists.`);return}let n=new F(t,e);return i.channels.set(t,n),n}findChannel(t){let e=i.channels.get(t);return e||this.addChannel(t)}get channels(){return Array.from(i.channels.values())}export(){let t=Array.from(i.mediaInstances.entries()).reduce((e,[n,r])=>(e[n]={channelAlias:r.channelAlias,soundAlias:r.soundAlias,stepCounter:r.stepCounter,paused:r.paused,options:{...r.memory,filters:se(r.filters)}},e),{});return {mediaInstances:g$1(t)}}async restore(t){try{if(Object.hasOwn(t,"soundsPlaying")){let e=t.soundsPlaying;if(e){let n=Object.keys(e).map(async r=>{await this.load(r),await this.play(r);});await Promise.all(n);}}if(Object.hasOwn(t,"mediaInstances")){let e=t.mediaInstances;if(e){let n=new Set,r=Object.values(e).map(async({soundAlias:o,channelAlias:l})=>(n.add(l),await this.load(o)));await Promise.all(r),this.channels.forEach(o=>{(!o.background||!n.has(o.alias))&&o.stopAll();});let s=Object.keys(e).map(async o=>{let l=e[o],m=this.findChannel(l.channelAlias),y=l.options.paused??l.paused??!1;if(m.background)if(l.stepCounter===GameUnifier.stepCounter||!this.find(o)){let p=await m.play(o,l.soundAlias,{...l.options,autostart:!y,filters:T(l.options.filters||[]),delay:l.options.delay});p.paused=y;}else {let p=i.mediaInstances.get(o);if(!p){f.warn(`No media instance found with alias ${o} while restoring background state.`);return}p.memory={...l.options,paused:y},[...p.filters].forEach(f=>{p.disconnect(f),f.dispose();}),p.chain(...T(l.options.filters||[]));}else {let p=await m.play(o,l.soundAlias,{...l.options,autostart:!y,filters:T(l.options.filters||[]),delay:l.options.delay});p.paused=y;}});await Promise.all(s);}}}catch(e){f.error("Error importing data",e);}}};var te=new w;GameUnifier.addOnPreContinue(async()=>{try{i.channels.forEach(a=>{a.background||a.stopAll();});}catch{}});if(typeof document<"u"){let a=false;document.addEventListener("visibilitychange",()=>{document.hidden?te.muted||(te.muteAll(),a=true):a&&(te.unmuteAll(),a=false);});}export{i as SoundRegistry,te as sound};
|
|
1
|
+
import {i as i$1}from'./chunk-IWAXXFXE.mjs';import {e,d,f,g as g$1}from'./chunk-3M6A7TU2.mjs';import {GameUnifier,PixiError}from'@drincs/pixi-vn/core';import le from'@drincs/pixi-vn/pixi.js';import*as c from'tone';import {ToneAudioBuffer,Channel,Reverb,Time,PingPongDelay,FeedbackDelay,BitCrusher,Compressor,Delay,Distortion,FeedbackCombFilter,Freeverb,Gate,GreaterThan,GreaterThanZero,Limiter,MidSideCompressor,MultibandCompressor,Panner3D,Phaser,StereoWidener,AutoFilter,Chorus,Tremolo,Vibrato,AutoPanner,BiquadFilter,OnePoleFilter,Filter,Player,now}from'tone';var re;(s=>(s.mediaInstances=new Map,s.channels=new Map,s.transients=new Set,s.systemPausedAliases=new Set,s.bufferRegistry=new e({cacheSize:10})))(re||={});var i=re;function T(a){return a.reduce((t,e)=>{switch(e.filterType){case "ReverbFilter":t.push(new Reverb({decay:e.decay,preDelay:e.preDelay,wet:e.wet}).toDestination());break;case "FeedbackDelayFilter":t.push(new FeedbackDelay({feedback:e.feedback,delayTime:e.delayTime,wet:e.wet}).toDestination());break;case "BitCrusherFilter":t.push(new BitCrusher({bits:e.bits}).toDestination());break;case "CompressorFilter":t.push(new Compressor({attack:e.attack,knee:e.knee,ratio:e.ratio,release:e.release,threshold:e.threshold}).toDestination());break;case "DelayFilter":t.push(new Delay({delayTime:e.delayTime,maxDelay:e.maxDelay}).toDestination());break;case "DistortionFilter":t.push(new Distortion({distortion:e.distortion,oversample:e.oversample,wet:e.wet}).toDestination());break;case "FeedbackCombFilterFilter":t.push(new FeedbackCombFilter({delayTime:e.delayTime,resonance:e.resonance}).toDestination());break;case "FreeverbFilter":t.push(new Freeverb({roomSize:e.roomSize,dampening:e.dampening,wet:e.wet}).toDestination());break;case "GateFilter":t.push(new Gate({threshold:e.threshold,smoothing:e.smoothing}).toDestination());break;case "GreaterThanFilter":t.push(new GreaterThan({value:e.value,convert:e.convert,maxValue:e.maxValue,minValue:e.minValue,units:e.units}).toDestination());break;case "GreaterThanZeroFilter":t.push(new GreaterThanZero);break;case "LimiterFilter":t.push(new Limiter({threshold:e.threshold}).toDestination());break;case "MidSideCompressorFilter":t.push(new MidSideCompressor({mid:e.mid,side:e.side}).toDestination());break;case "MultibandCompressorFilter":t.push(new MultibandCompressor({lowFrequency:e.lowFrequency,highFrequency:e.highFrequency,low:e.low,mid:e.mid,high:e.high}).toDestination());break;case "Panner3DFilter":t.push(new Panner3D({positionX:e.positionX,positionY:e.positionY,positionZ:e.positionZ,orientationX:e.orientationX,orientationY:e.orientationY,orientationZ:e.orientationZ,coneInnerAngle:e.coneInnerAngle,coneOuterAngle:e.coneOuterAngle,coneOuterGain:e.coneOuterGain,distanceModel:e.distanceModel,maxDistance:e.maxDistance,refDistance:e.refDistance,rolloffFactor:e.rolloffFactor,panningModel:e.panningModel}).toDestination());break;case "PhaserFilter":t.push(new Phaser({frequency:e.frequency,octaves:e.octaves,baseFrequency:e.baseFrequency,wet:e.wet,Q:e.Q,stages:e.stages}).toDestination());break;case "StereoWidenerFilter":t.push(new StereoWidener({width:e.width,wet:e.wet}).toDestination());break;case "PingPongDelayFilter":t.push(new PingPongDelay({wet:e.wet,delayTime:e.delayTime,feedback:e.feedback,maxDelay:e.maxDelay}).toDestination());break;case "AutoFilterFilter":t.push(new AutoFilter({frequency:e.frequency,depth:e.depth,baseFrequency:e.baseFrequency,octaves:e.octaves,filter:e.filter,wet:e.wet,type:e.type}).toDestination());break;case "BiquadFilterFilter":t.push(new BiquadFilter({frequency:e.frequency,detune:e.detune,Q:e.Q,type:e.type,gain:e.gain}).toDestination());break;case "OnePoleFilterFilter":t.push(new OnePoleFilter({type:e.type}).toDestination());break;case "CustomFilter":t.push(new Filter({frequency:e.frequency,Q:e.Q,type:e.type,detune:e.detune,gain:e.gain,rolloff:e.rolloff}).toDestination());break;case "ChorusFilter":t.push(new Chorus({frequency:e.frequency,delayTime:e.delayTime,depth:e.depth,type:e.type,spread:e.spread,feedback:e.feedback,wet:e.wet}).toDestination());break;case "TremoloFilter":t.push(new Tremolo({frequency:e.frequency,type:e.type,depth:e.depth,spread:e.spread,wet:e.wet}).toDestination());break;case "VibratoFilter":t.push(new Vibrato({maxDelay:e.maxDelay,frequency:e.frequency,depth:e.depth,type:e.type,wet:e.wet}).toDestination());break;case "AutoPannerFilter":t.push(new AutoPanner({frequency:e.frequency,type:e.type,depth:e.depth,channelCount:e.channelCount,wet:e.wet}).toDestination());break}return t},[])}function se(a){if(a)return Array.from(a).reduce((t,e)=>(e instanceof Reverb?t.push({filterType:"ReverbFilter",wet:e.wet.value,decay:Time(e.decay).toSeconds(),preDelay:Time(e.preDelay).toSeconds()}):e instanceof PingPongDelay?t.push({filterType:"PingPongDelayFilter",wet:e.wet.value,delayTime:e.delayTime.value,feedback:e.feedback.value}):e instanceof FeedbackDelay?t.push({filterType:"FeedbackDelayFilter",feedback:e.feedback.value,delayTime:e.delayTime.value,wet:e.wet.value}):e instanceof BitCrusher?t.push({filterType:"BitCrusherFilter",bits:e.bits.value,wet:e.wet.value}):e instanceof Compressor?t.push({filterType:"CompressorFilter",attack:e.attack.value,knee:e.knee.value,ratio:e.ratio.value,release:e.release.value,threshold:e.threshold.value}):e instanceof Delay?t.push({filterType:"DelayFilter",delayTime:e.delayTime.value,maxDelay:e.maxDelay}):e instanceof Distortion?t.push({filterType:"DistortionFilter",distortion:e.distortion,oversample:e.oversample,wet:e.wet.value}):e instanceof FeedbackCombFilter?t.push({filterType:"FeedbackCombFilterFilter",delayTime:e.delayTime.value,resonance:e.resonance.value}):e instanceof Freeverb?t.push({filterType:"FreeverbFilter",roomSize:e.roomSize.value,dampening:e.dampening,wet:e.wet.value}):e instanceof Gate?t.push({filterType:"GateFilter",threshold:e.threshold,smoothing:e.smoothing}):e instanceof GreaterThan?t.push({filterType:"GreaterThanFilter",value:e.comparator.value,convert:e.convert,maxValue:e.maxValue,minValue:e.minValue}):e instanceof GreaterThanZero?t.push({filterType:"GreaterThanZeroFilter"}):e instanceof Limiter?t.push({filterType:"LimiterFilter",threshold:e.threshold.value}):e instanceof MidSideCompressor?t.push({filterType:"MidSideCompressorFilter",mid:{attack:e.mid.attack.value,knee:e.mid.knee.value,ratio:e.mid.ratio.value,release:e.mid.release.value,threshold:e.mid.threshold.value},side:{attack:e.side.attack.value,knee:e.side.knee.value,ratio:e.side.ratio.value,release:e.side.release.value,threshold:e.side.threshold.value}}):e instanceof MultibandCompressor?t.push({filterType:"MultibandCompressorFilter",lowFrequency:e.lowFrequency.value,highFrequency:e.highFrequency.value,low:{attack:e.low.attack.value,knee:e.low.knee.value,ratio:e.low.ratio.value,release:e.low.release.value,threshold:e.low.threshold.value},mid:{attack:e.mid.attack.value,knee:e.mid.knee.value,ratio:e.mid.ratio.value,release:e.mid.release.value,threshold:e.mid.threshold.value},high:{attack:e.high.attack.value,knee:e.high.knee.value,ratio:e.high.ratio.value,release:e.high.release.value,threshold:e.high.threshold.value}}):e instanceof Panner3D?t.push({filterType:"Panner3DFilter",positionX:e.positionX.value,positionY:e.positionY.value,positionZ:e.positionZ.value,orientationX:e.orientationX.value,orientationY:e.orientationY.value,orientationZ:e.orientationZ.value,coneInnerAngle:e.coneInnerAngle,coneOuterAngle:e.coneOuterAngle,coneOuterGain:e.coneOuterGain,distanceModel:e.distanceModel,maxDistance:e.maxDistance,refDistance:e.refDistance,rolloffFactor:e.rolloffFactor,panningModel:e.panningModel}):e instanceof Phaser?t.push({filterType:"PhaserFilter",frequency:e.frequency.value,octaves:e.octaves,baseFrequency:e.baseFrequency,wet:e.wet.value,Q:e.Q.value}):e instanceof StereoWidener?t.push({filterType:"StereoWidenerFilter",width:e.width.value,wet:e.wet.value}):e instanceof AutoFilter?t.push({filterType:"AutoFilterFilter",type:e.type,frequency:e.frequency.value,depth:e.depth.value,baseFrequency:e.baseFrequency,octaves:e.octaves,filter:{Q:e.filter.Q.value,type:e.filter.type,rolloff:e.filter.rolloff},wet:e.wet.value}):e instanceof Chorus?t.push({filterType:"ChorusFilter",type:e.type,frequency:e.frequency.value,delayTime:e.delayTime,depth:e.depth,spread:e.spread,feedback:e.feedback.value,wet:e.wet.value}):e instanceof Tremolo?t.push({filterType:"TremoloFilter",type:e.type,frequency:e.frequency.value,depth:e.depth.value,spread:e.spread,wet:e.wet.value}):e instanceof Vibrato?t.push({filterType:"VibratoFilter",type:e.type,frequency:e.frequency.value,depth:e.depth.value,wet:e.wet.value}):e instanceof AutoPanner?t.push({filterType:"AutoPannerFilter",type:e.type,frequency:e.frequency.value,depth:e.depth.value,channelCount:e.channelCount,wet:e.wet.value}):e instanceof BiquadFilter?t.push({filterType:"BiquadFilterFilter",type:e.type,frequency:e.frequency.value,detune:e.detune.value,Q:e.Q.value,gain:e.gain.value}):e instanceof OnePoleFilter?t.push({filterType:"OnePoleFilterFilter",type:e.type}):e instanceof Filter?t.push({filterType:"CustomFilter",type:e.type,frequency:e.frequency.value,Q:e.Q.value,detune:e.detune.value,gain:e.gain.value,rolloff:e.rolloff}):f.warn(`Unsupported filter type for serialisation: ${e?.constructor?.name??e}, please report this to the developers if you encounter it.`),t),[])}function J(a){return a instanceof Reverb||a instanceof FeedbackDelay||a instanceof PingPongDelay||a instanceof BitCrusher||a instanceof Compressor||a instanceof Delay||a instanceof Distortion||a instanceof FeedbackCombFilter||a instanceof Freeverb||a instanceof Gate||a instanceof GreaterThan||a instanceof GreaterThanZero||a instanceof Limiter||a instanceof MidSideCompressor||a instanceof MultibandCompressor||a instanceof Panner3D||a instanceof Phaser||a instanceof StereoWidener||a instanceof AutoFilter||a instanceof Chorus||a instanceof Vibrato||a instanceof Tremolo||a instanceof AutoPanner||a instanceof BiquadFilter||a instanceof OnePoleFilter||a instanceof Filter}function h(a){return a<=0?-1/0:20*Math.log10(a)}function g(a){return a<=-1/0?0:10**(a/20)}async function P(a){if(i.bufferRegistry.has(a))return;let t=a;try{let e=le.Assets.resolver.resolve(a);e?.src&&(t=e.src);}catch{}try{let e=await ToneAudioBuffer.load(t),n=new ToneAudioBuffer(e);i.bufferRegistry.set(a,n);}catch(e){f.warn(`Failed to load audio buffer for "${a}" (url: "${t}"): ${e instanceof Error?e.message:e}`),i.bufferRegistry.set(a,new ToneAudioBuffer);}}var v=class extends Player{constructor(e,n,r,s,o={},l){super(o);d(this,"alias",e);d(this,"channelAlias",n);d(this,"soundAlias",r);d(this,"stepCounter",s);d(this,"delay",l);d(this,"options");d(this,"filters",new Set);d(this,"pausedAt");d(this,"playStartTime",now());this.options=o,this.playStartTime=now()+(l??0);}get memory(){let e=Math.max(0,this.pausedAt?this.pausedAt-this.playStartTime:now()-this.playStartTime),n=this.paused;return n&&i.systemPausedAliases.has(this.alias)&&(n=false),{...this.options,fadeIn:this.fadeIn,loop:this.loop,loopEnd:this.loopEnd,loopStart:this.loopStart,mute:this.mute,playbackRate:this.playbackRate,reverse:this.reverse,volume:g(this.volume.value),autostart:!this.paused,elapsed:e,paused:n,delay:this.delay}}set memory(e){this.paused=e.paused,this.loop!==(e.loop||false)&&(this.loop=e.loop||false),this.volume.value!==h(e.volume??1)&&(this.volume.value=h(e.volume??1)),this.mute!==(e.mute||false)&&(this.mute=e.mute||false),this.playbackRate!==(e.playbackRate??1)&&(this.playbackRate=e.playbackRate??1),this.reverse!==(e.reverse||false)&&(this.reverse=e.reverse||false),this.fadeIn!==(e.fadeIn||0)&&(this.fadeIn=e.fadeIn||0),this.loopStart!==(e.loopStart||0)&&(this.loopStart=e.loopStart||0),this.loopEnd!==(e.loopEnd||0)&&(this.loopEnd=e.loopEnd||0);}get paused(){return typeof this.pausedAt=="number"}set paused(e){let n=this.state;if(e)this.pausedAt=now(),n==="started"&&super.stop();else {let r;typeof this.pausedAt=="number"&&(r=this.pausedAt-this.playStartTime,this.pausedAt=void 0),n==="stopped"&&(this.delay?this.start(`+${this.delay}`,r):this.start(void 0,r));}}get muted(){return this.mute}set muted(e){this.mute=e;}get speed(){return this.playbackRate}set speed(e){this.playbackRate=e;}stop(e){return i.mediaInstances.delete(this.alias),super.stop(e)}start(e,n,r){let s=now(),o=s;if(typeof e=="number")o=e;else if(typeof e=="string"&&e.startsWith("+")){let m=Number(e.slice(1));Number.isNaN(m)||(o=s+m);}let l=typeof n=="number"?n:0;return this.playStartTime=o-l,super.start(e,n,r)}chain(...e){return e.forEach(n=>{J(n)&&(n.toDestination(),this.filters.add(n));}),super.chain(...e)}disconnect(e){return J(e)&&(e.disconnect(),this.filters.delete(e)),super.disconnect(e)}};var F=class{constructor(t,e={}){d(this,"alias",t);d(this,"toneChannel");d(this,"background");this.background=e.background??false,this.toneChannel=new Channel({volume:h(e.volume??1),mute:e.muted??false,pan:e.pan??0}).toDestination(),e.filters&&this.toneChannel.chain(...e.filters);}get volume(){return g(this.toneChannel.volume.value)}set volume(t){this.toneChannel.volume.value=h(t);}get volumeParam(){return this.toneChannel.volume}get pan(){return this.toneChannel.pan.value}set pan(t){this.toneChannel.pan.value=t;}get panParam(){return this.toneChannel.pan}get muted(){return this.toneChannel.mute}set muted(t){this.toneChannel.mute=t;}pauseAll(){for(let t of i.mediaInstances.values())t.channelAlias===this.alias&&!t.paused&&(t.paused=true);return this}resumeAll(){for(let t of i.mediaInstances.values())t.channelAlias===this.alias&&t.paused&&(t.paused=false);return this}chain(...t){return this.toneChannel.chain(...t),this}_createPlayer(t,e,n={}){let r=i.bufferRegistry.get(e);if(!r)throw new PixiError("unregistered_asset",`Sound buffer for alias "${e}" is not loaded. Call sound.load() first.`);let{delay:s,elapsed:o,filters:l=[],muted:m,autostart:y=true,speed:p,volume:A,...f$1}=n;m!==void 0&&(f.warn(`MediaInstance "${t}" is being created with muted=${m}. This will override the channel's muted state (${this.muted}).`),f$1.mute=m),p!==void 0&&(f.warn(`MediaInstance "${t}" is being created with speed=${p}. This will override the default playback speed of 1.`),f$1.playbackRate=p);let O=new v(t,this.alias,e,GameUnifier.stepCounter,{...f$1,volume:A!==void 0?h(A):void 0,url:r},s).chain(...l,this.toneChannel),te=o!==void 0?Math.max(0,o):void 0;return y&&(s?O.start(`+${s}`,te):O.start(void 0,te)),O}async play(t,e,n){let r,s;if(typeof e=="string"?(r=t,s=e):(r=t,s=t,n=e),i.mediaInstances.has(r)){let l=i.mediaInstances.get(r);l&&(l.stop(),n={...l.memory,...n,filters:[...l.filters,...n?.filters||[]]});}await P(s);let o=this._createPlayer(r,s,n);return i.mediaInstances.set(r,o),o}toggleMuteAll(){return this.muted=!this.muted,this.muted}get mediaInstances(){return Array.from(i.mediaInstances.values()).reduce((t,e)=>(e.channelAlias===this.alias&&t.push(e),t),[])}stopAll(){let t=[];for(let[e,n]of i.mediaInstances.entries())n.channelAlias===this.alias&&(n.stop(),t.push(e));return t.forEach(e=>{i.mediaInstances.delete(e);}),this}};var w=class{constructor(){d(this,"_speedAll",1);d(this,"_defaultChannelAlias",i$1);}get volumeAll(){return g(c.getDestination().volume.value)}set volumeAll(t){c.getDestination().volume.value=h(t);}get speedAll(){return this._speedAll}set speedAll(t){this._speedAll=t;for(let e of i.mediaInstances.values())e.speed=t;}get defaultChannelAlias(){return this._defaultChannelAlias}set defaultChannelAlias(t){this._defaultChannelAlias=t;}add(t,e){if(!i.bufferRegistry.has(t)){let n=new c.ToneAudioBuffer(e);i.bufferRegistry.set(t,n);}}pauseAll(){for(let t of i.mediaInstances.values())t.paused||(t.paused=true);return this}resumeAll(){for(let t of i.mediaInstances.values())t.paused&&(t.paused=false);return this}get muted(){return c.getDestination().mute}toggleMuteAll(){let t=!c.getDestination().mute;return c.getDestination().mute=t,t}muteAll(){return c.getDestination().mute=true,this}unmuteAll(){return c.getDestination().mute=false,this}stopAll(){for(let t of i.mediaInstances.values())t.stop();return i.mediaInstances.clear(),this}pauseUnsavedAll(t){for(let[e,n]of i.mediaInstances.entries())t&&n.channelAlias!==t||n.paused||(n.paused=true,i.systemPausedAliases.add(e));if(!t){for(let e of i.transients)e.stop();i.transients.clear();}return this}resumeUnsavedAll(t){let e=[];for(let n of i.systemPausedAliases){let r=i.mediaInstances.get(n);if(!r){e.push(n);continue}t&&r.channelAlias!==t||(r.paused=false,e.push(n));}for(let n of e)i.systemPausedAliases.delete(n);return this}stopTransientAll(){for(let t of i.transients)t.stop();return i.transients.clear(),this}async play(t,e,n){let r,s;typeof e=="string"?(r=t,s=e):(r=t,s=t,n=e),i.bufferRegistry.has(s)||await this.load(s);let{channel:o=this.defaultChannelAlias,...l}=n??{};return await this.findChannel(o).play(r,s,l)}async playTransient(t,e){i.bufferRegistry.has(t)||await this.load(t);let n=i.bufferRegistry.get(t);if(!n)throw new PixiError("unregistered_asset",`Sound buffer for alias "${t}" is not loaded. Call sound.load() first.`);let{autostart:r=true,...s}=e??{},o=new c.Player({...s,url:n}).toDestination();return r&&o.start(),i.transients.add(o),o.onstop=()=>{o.dispose(),i.transients.delete(o);},o}find(t){return i.mediaInstances.get(t)}stop(t){let e=this.find(t);e?(e.stop(),i.mediaInstances.delete(t)):f.warn(`No media instance found with alias ${t} to stop.`);}pause(t){let e=this.find(t);if(!e){f.warn(`No media instance found with alias ${t} to pause.`);return}return e.paused=true,e}resume(t){let e=this.find(t);if(!e){f.warn(`No media instance found with alias ${t} to resume.`);return}return e.paused=false,e}duration(t){return i.bufferRegistry.get(t)?.duration??0}async load(...t){let e=t.map(P);await Promise.all(e);}backgroundLoad(...t){return this.load(...t).catch(e=>{f.error("Error background-loading sound",e);})}backgroundLoadBundle(t){let e=le.Assets.backgroundLoadBundle(t);return e.then(async()=>{try{let n=await le.Assets.loadBundle(t),r=[];for(let s in n)i.bufferRegistry.has(s)||r.push(this.load(s));await Promise.all(r);}catch(n){f.error("Error loading sound bundle",n);}}).catch(n=>{f.error("Error background-loading sound bundle",n);}),e}clear(){this.stopAll();}addChannel(t,e={}){if(typeof t!="string"){t.forEach(r=>{let s={...e,filters:e.filters?[...e.filters]:e.filters};this.addChannel(r,s);});return}if(i.channels.has(t)){f.warn(`Channel with alias ${t} already exists.`);return}let n=new F(t,e);return i.channels.set(t,n),n}findChannel(t){let e=i.channels.get(t);return e||this.addChannel(t)}get channels(){return Array.from(i.channels.values())}export(){let t=Array.from(i.mediaInstances.entries()).reduce((e,[n,r])=>(e[n]={channelAlias:r.channelAlias,soundAlias:r.soundAlias,stepCounter:r.stepCounter,paused:r.paused,options:{...r.memory,filters:se(r.filters)}},e),{});return {mediaInstances:g$1(t)}}async restore(t){try{if(Object.hasOwn(t,"soundsPlaying")){let e=t.soundsPlaying;if(e){let n=Object.keys(e).map(async r=>{await this.load(r),await this.play(r);});await Promise.all(n);}}if(Object.hasOwn(t,"mediaInstances")){let e=t.mediaInstances;if(e){let n=new Set,r=Object.values(e).map(async({soundAlias:o,channelAlias:l})=>(n.add(l),await this.load(o)));await Promise.all(r),this.channels.forEach(o=>{(!o.background||!n.has(o.alias))&&o.stopAll();});let s=Object.keys(e).map(async o=>{let l=e[o],m=this.findChannel(l.channelAlias),y=l.options.paused??l.paused??!1;if(m.background)if(l.stepCounter===GameUnifier.stepCounter||!this.find(o)){let p=await m.play(o,l.soundAlias,{...l.options,autostart:!y,filters:T(l.options.filters||[]),delay:l.options.delay});p.paused=y;}else {let p=i.mediaInstances.get(o);if(!p){f.warn(`No media instance found with alias ${o} while restoring background state.`);return}p.memory={...l.options,paused:y},[...p.filters].forEach(f=>{p.disconnect(f),f.dispose();}),p.chain(...T(l.options.filters||[]));}else {let p=await m.play(o,l.soundAlias,{...l.options,autostart:!y,filters:T(l.options.filters||[]),delay:l.options.delay});p.paused=y;}});await Promise.all(s);}}}catch(e){f.error("Error importing data",e);}}};var ee=new w;GameUnifier.addOnPreContinue(async()=>{try{i.channels.forEach(a=>{a.background||a.stopAll();});}catch{}});if(typeof document<"u"){let a=false;document.addEventListener("visibilitychange",()=>{document.hidden?ee.muted||(ee.muteAll(),a=true):a&&(ee.unmuteAll(),a=false);});}export{i as SoundRegistry,ee as sound};
|