@combos-fun/plugin-sound 0.0.33 → 0.0.34
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/plugin-sound.cjs.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var tslib = require('tslib');
|
|
4
4
|
var engine = require('@combos-fun/engine');
|
|
5
|
+
var inspectorDecorator = require('@combos-fun/inspector-decorator');
|
|
5
6
|
|
|
6
7
|
let SoundSystem$1 = class SoundSystem extends engine.System {
|
|
7
8
|
static { this.systemName = 'SoundSystem'; }
|
|
@@ -252,7 +253,7 @@ var SoundSystem = SoundSystem$1;
|
|
|
252
253
|
/** Auto-generated by scripts/build-package.mjs — do not edit. */
|
|
253
254
|
Object.assign(SoundSystem, {
|
|
254
255
|
packageName: "@combos-fun/plugin-sound",
|
|
255
|
-
packageVersion: "0.0.
|
|
256
|
+
packageVersion: "0.0.34",
|
|
256
257
|
});
|
|
257
258
|
|
|
258
259
|
class Sound extends engine.Component {
|
|
@@ -290,6 +291,27 @@ class Sound extends engine.Component {
|
|
|
290
291
|
this.config.volume = v;
|
|
291
292
|
this.applyGain();
|
|
292
293
|
}
|
|
294
|
+
get loop() {
|
|
295
|
+
return this.config.loop ?? false;
|
|
296
|
+
}
|
|
297
|
+
set loop(v) {
|
|
298
|
+
this.config.loop = v;
|
|
299
|
+
if (this.sourceNode) {
|
|
300
|
+
this.sourceNode.loop = v;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
get autoplay() {
|
|
304
|
+
return this.config.autoplay ?? false;
|
|
305
|
+
}
|
|
306
|
+
set autoplay(v) {
|
|
307
|
+
this.config.autoplay = v;
|
|
308
|
+
}
|
|
309
|
+
get resource() {
|
|
310
|
+
return this.config.resource ?? '';
|
|
311
|
+
}
|
|
312
|
+
set resource(v) {
|
|
313
|
+
this.config.resource = v;
|
|
314
|
+
}
|
|
293
315
|
/**
|
|
294
316
|
* Apply the effective gain (`muted ? 0 : volume`) to the gain node.
|
|
295
317
|
*
|
|
@@ -416,6 +438,54 @@ class Sound extends engine.Component {
|
|
|
416
438
|
this.playing = false;
|
|
417
439
|
}
|
|
418
440
|
}
|
|
441
|
+
tslib.__decorate([
|
|
442
|
+
inspectorDecorator.Field({
|
|
443
|
+
type: 'boolean',
|
|
444
|
+
group: 'Sound',
|
|
445
|
+
label: 'Muted',
|
|
446
|
+
description: 'Silence this sound without changing its volume setting.',
|
|
447
|
+
editor: 'toggle',
|
|
448
|
+
})
|
|
449
|
+
], Sound.prototype, "muted", null);
|
|
450
|
+
tslib.__decorate([
|
|
451
|
+
inspectorDecorator.Field({
|
|
452
|
+
type: 'number',
|
|
453
|
+
min: 0,
|
|
454
|
+
max: 1,
|
|
455
|
+
step: 0.01,
|
|
456
|
+
group: 'Sound',
|
|
457
|
+
label: 'Volume',
|
|
458
|
+
description: 'Loudness of this sound from 0 (silent) to 1 (full).',
|
|
459
|
+
editor: 'volume-slider',
|
|
460
|
+
})
|
|
461
|
+
], Sound.prototype, "volume", null);
|
|
462
|
+
tslib.__decorate([
|
|
463
|
+
inspectorDecorator.Field({
|
|
464
|
+
type: 'boolean',
|
|
465
|
+
group: 'Sound',
|
|
466
|
+
label: 'Loop',
|
|
467
|
+
description: 'Replay the sound continuously when it reaches the end.',
|
|
468
|
+
editor: 'toggle',
|
|
469
|
+
})
|
|
470
|
+
], Sound.prototype, "loop", null);
|
|
471
|
+
tslib.__decorate([
|
|
472
|
+
inspectorDecorator.Field({
|
|
473
|
+
type: 'boolean',
|
|
474
|
+
group: 'Sound',
|
|
475
|
+
label: 'Autoplay',
|
|
476
|
+
description: 'Start playing automatically once the audio has loaded.',
|
|
477
|
+
editor: 'toggle',
|
|
478
|
+
})
|
|
479
|
+
], Sound.prototype, "autoplay", null);
|
|
480
|
+
tslib.__decorate([
|
|
481
|
+
inspectorDecorator.Field({
|
|
482
|
+
type: 'string',
|
|
483
|
+
group: 'Sound',
|
|
484
|
+
label: 'Resource',
|
|
485
|
+
description: 'Audio resource id used by the sound system.',
|
|
486
|
+
editor: 'text',
|
|
487
|
+
})
|
|
488
|
+
], Sound.prototype, "resource", null);
|
|
419
489
|
|
|
420
490
|
exports.Sound = Sound;
|
|
421
491
|
exports.SoundSystem = SoundSystem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-sound.cjs.js","sources":["../lib/SoundSystem.ts","../lib/__combosPackageMeta.gen.ts","../lib/Sound.ts"],"sourcesContent":["import { System, decorators, ComponentChanged, OBSERVER_TYPE, resource } from '@combos-fun/engine';\nimport SoundComponent from './Sound';\n\ninterface SoundSystemParams {\n autoPauseAndStart?: boolean;\n onError?: (error: any) => void;\n}\n\n@decorators.componentObserver({\n Sound: [],\n})\nclass SoundSystem extends System {\n static systemName = 'SoundSystem';\n\n private ctx: AudioContext;\n\n private gainNode: GainNode;\n\n /** Whether to pause/resume in sync with the game. */\n private autoPauseAndStart = true;\n\n private onError: (error: any) => void;\n\n private components: SoundComponent[] = [];\n\n private pausedComponents: SoundComponent[] = [];\n\n private audioBufferCache = {};\n\n private decodeAudioPromiseMap = {};\n\n /** Desired mute/volume are the source of truth; the gain node is derived. */\n private _muted = false;\n\n private _volume = 1;\n\n get muted(): boolean {\n return this._muted;\n }\n\n set muted(v: boolean) {\n this._muted = v;\n this.applyGain();\n }\n\n get volume(): number {\n return this._volume;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this._volume = v;\n this.applyGain();\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * Assigns `gain.value` directly rather than `setValueAtTime`: `.value` updates\n * the AudioParam's intrinsic value synchronously, so the `muted` / `volume`\n * getters reflect the change immediately. `setValueAtTime` only schedules an\n * event on the automation timeline and leaves `.value` stale until the next\n * render quantum, which made `muted` report the pre-change value.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this._muted ? 0 : this._volume;\n }\n\n get audioLocked(): boolean {\n if (!this.ctx) {\n return true;\n }\n return this.ctx.state !== 'running';\n }\n\n constructor(obj?: SoundSystemParams) {\n super();\n Object.assign(this, obj);\n }\n\n /**\n * Resume playback of all paused audio.\n */\n resumeAll() {\n const handleResume = () => {\n this.pausedComponents.forEach(component => {\n component.play();\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n };\n this.ctx.resume().then(handleResume, handleResume);\n }\n\n /**\n * Pause all currently playing audio.\n */\n pauseAll() {\n this.components.forEach(component => {\n if (component.playing) {\n this.pausedComponents.push(component);\n component.pause();\n }\n });\n this.ctx.suspend().then();\n }\n\n /**\n * Stop all currently playing audio.\n */\n stopAll() {\n this.components.forEach(component => {\n if (component.playing) {\n component.stop();\n }\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n this.ctx.suspend().then();\n }\n\n /**\n * System init: configure params before the game starts.\n */\n init() {\n this.setupAudioContext();\n }\n\n update() {\n const changes = this.componentObserver.clear();\n for (const changed of changes) {\n this.componentChanged(changed);\n }\n }\n\n /**\n * Called when the game starts or resumes playing after a pause.\n */\n onResume() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.resumeAll();\n }\n\n /**\n * Called when the game is paused.\n */\n onPause() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.pauseAll();\n }\n\n /**\n * Called when the system is destroyed.\n */\n onDestroy() {\n this.components.forEach(component => {\n component.onDestroy();\n });\n this.components = [];\n if (this.ctx) {\n this.gainNode.disconnect();\n this.gainNode = null;\n this.ctx.close();\n this.ctx = null;\n }\n }\n\n async componentChanged(changed: ComponentChanged) {\n if (changed.componentName !== 'Sound') return;\n\n if (changed.type === OBSERVER_TYPE.ADD) {\n this.add(changed);\n }\n }\n\n private setupAudioContext() {\n try {\n const AudioContext = window.AudioContext || (window as any).webkitAudioContext;\n this.ctx = new AudioContext();\n } catch (error) {\n console.error(error);\n if (this.onError) {\n this.onError(error);\n }\n }\n\n if (!this.ctx) {\n return;\n }\n this.gainNode =\n typeof this.ctx.createGain === 'undefined' ? (this.ctx as any).createGainNode() : this.ctx.createGain();\n this.applyGain();\n this.gainNode.connect(this.ctx.destination);\n this.unlockAudio();\n }\n\n private unlockAudio() {\n if (!this.ctx || !this.audioLocked) {\n return;\n }\n\n const unlock = () => {\n if (this.ctx) {\n const removeListenerFn = () => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n document.body.removeEventListener('click', unlock);\n };\n this.ctx.resume().then(removeListenerFn, removeListenerFn);\n }\n };\n document.body.addEventListener('touchstart', unlock);\n document.body.addEventListener('touchend', unlock);\n document.body.addEventListener('click', unlock);\n }\n\n private async add(changed: ComponentChanged) {\n const component = changed.component as SoundComponent;\n this.components.push(component);\n try {\n const { config } = component;\n component.state = 'loading';\n\n const audio = await resource.getResource(config.resource);\n if (!this.audioBufferCache[audio.name] && audio?.data?.audio) {\n this.audioBufferCache[audio.name] = await this.decodeAudioData(audio.data.audio, audio.name);\n }\n if (this.audioBufferCache[audio.name]) {\n component.systemContext = this.ctx;\n component.systemDestination = this.gainNode;\n component.onload(this.audioBufferCache[audio.name]);\n }\n } catch (error) {\n if (this.onError) {\n this.onError(error);\n }\n }\n }\n\n private decodeAudioData(arraybuffer: ArrayBuffer, name: string) {\n if (this.decodeAudioPromiseMap[name]) {\n return this.decodeAudioPromiseMap[name];\n }\n\n const promise = new Promise<AudioBuffer>((resolve, reject) => {\n if (!this.ctx) {\n reject(new Error('No audio support'));\n }\n\n const success = (decodedData: AudioBuffer) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n if (decodedData) {\n resolve(decodedData);\n } else {\n reject(new Error(`Error decoding audio ${name}`));\n }\n };\n\n const error = (err: DOMException) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n reject(new Error(`${err}. arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n };\n\n const promise = this.ctx.decodeAudioData(arraybuffer, success, error)\n if (promise instanceof Promise) {\n promise.catch((err) => {\n reject(new Error(`catch ${err}, arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n });\n }\n });\n\n this.decodeAudioPromiseMap[name] = promise;\n return promise;\n }\n}\n\nexport default SoundSystem;\n","/** Auto-generated by scripts/build-package.mjs — do not edit. */\n\nimport SoundSystem from './SoundSystem';\n\nObject.assign(SoundSystem, {\n packageName: \"@combos-fun/plugin-sound\",\n packageVersion: \"0.0.33\",\n});\n","import { Component } from '@combos-fun/engine';\n\nexport interface SoundParams {\n resource: string;\n autoplay?: boolean;\n muted?: boolean;\n volume?: number;\n loop?: boolean;\n seek?: number;\n duration?: number;\n onEnd?: () => void;\n}\n\nclass Sound extends Component<SoundParams> {\n static componentName = 'Sound';\n\n systemContext: AudioContext;\n\n systemDestination: GainNode;\n\n playing: boolean;\n\n state: 'unloaded' | 'loading' | 'loaded' = 'unloaded';\n\n config: SoundParams = {\n resource: '',\n autoplay: false,\n muted: false,\n volume: 1,\n loop: false,\n seek: 0,\n };\n\n private buffer: AudioBuffer;\n\n private sourceNode: AudioBufferSourceNode;\n\n private gainNode: GainNode;\n\n private paused: boolean;\n\n private playTime: number = 0;\n\n private startTime: number = 0;\n\n private duration: number = 0;\n\n private actionQueue: (() => void)[] = [];\n\n private endedListener: () => void;\n\n get muted(): boolean {\n return this.config.muted ?? false;\n }\n\n set muted(v: boolean) {\n this.config.muted = v;\n this.applyGain();\n }\n\n get volume(): number {\n return this.config.volume ?? 1;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this.config.volume = v;\n this.applyGain();\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * `config` is the source of truth and the gain is assigned via `gain.value`\n * (updates the AudioParam intrinsic value synchronously) so the `muted` /\n * `volume` getters — and anything reading them back, e.g. the scene-edit\n * volume slider — reflect the change immediately. `setValueAtTime` only\n * schedules on the automation timeline and leaves `.value` stale.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this.config.muted ? 0 : (this.config.volume ?? 1);\n }\n\n init(obj?: SoundParams) {\n if (!obj) {\n return;\n }\n\n Object.assign(this.config, obj);\n if (this.config.autoplay) {\n this.actionQueue.push(this.play.bind(this));\n }\n }\n\n play() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.play.bind(this));\n }\n this.destroySource();\n this.createSource();\n\n if (!this.sourceNode) {\n return;\n }\n const when = this.systemContext.currentTime;\n const offset = this.config.seek;\n const duration = this.config.duration;\n\n this.sourceNode.start(0, offset, duration);\n\n this.startTime = when;\n this.playTime = when - offset;\n this.paused = false;\n this.playing = true;\n this.resetConfig();\n this.endedListener = () => {\n if (!this.sourceNode) {\n return;\n }\n if (this.config.onEnd) {\n this.config.onEnd();\n }\n // Release resources once non-interactive playback finishes.\n if (this.playing) {\n this.destroySource();\n }\n };\n this.sourceNode.addEventListener('ended', this.endedListener);\n }\n\n pause() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.pause.bind(this));\n }\n if (this.paused || !this.playing) {\n return;\n }\n this.paused = true;\n this.playing = false;\n this.config.seek = this.getCurrentTime();\n this.destroySource();\n }\n\n stop() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.stop.bind(this));\n }\n if (!this.paused && !this.playing) {\n return;\n }\n this.playing = false;\n this.paused = false;\n this.destroySource();\n this.resetConfig();\n }\n\n onload(buffer: AudioBuffer) {\n this.state = 'loaded';\n this.buffer = buffer;\n this.duration = this.buffer.duration;\n this.actionQueue.forEach(action => action());\n this.actionQueue.length = 0;\n }\n\n onDestroy() {\n this.actionQueue.length = 0;\n this.destroySource();\n }\n\n private resetConfig() {\n this.config.seek = 0;\n }\n\n private getCurrentTime() {\n if (this.config.loop && this.duration > 0) {\n return (this.systemContext.currentTime - this.playTime) % this.duration;\n }\n\n return this.systemContext.currentTime - this.playTime;\n }\n\n private createSource() {\n if (!this.systemContext || this.state !== 'loaded') {\n return;\n }\n this.sourceNode = this.systemContext.createBufferSource();\n this.sourceNode.buffer = this.buffer;\n this.sourceNode.loop = this.config.loop;\n\n if (!this.gainNode) {\n this.gainNode = this.systemContext.createGain();\n this.gainNode.connect(this.systemDestination);\n Object.assign(this, this.config);\n }\n this.sourceNode.connect(this.gainNode);\n }\n\n private destroySource() {\n if (!this.sourceNode) return;\n this.sourceNode.removeEventListener('ended', this.endedListener);\n this.sourceNode.stop();\n this.sourceNode.disconnect();\n this.sourceNode = null;\n\n this.startTime = 0;\n this.playTime = 0;\n this.playing = false;\n }\n}\n\nexport default Sound;\n"],"names":["SoundSystem","System","OBSERVER_TYPE","resource","__decorate","decorators","Component"],"mappings":";;;;;AAWA,IAAMA,aAAW,GAAjB,MAAM,WAAY,SAAQC,aAAM,CAAA;aACvB,IAAA,CAAA,UAAU,GAAG,aAAH,CAAiB;AAwBlC,IAAA,IAAI,KAAK,GAAA;QACP,OAAO,IAAI,CAAC,MAAM;IACpB;IAEA,IAAI,KAAK,CAAC,CAAU,EAAA;AAClB,QAAA,IAAI,CAAC,MAAM,GAAG,CAAC;QACf,IAAI,CAAC,SAAS,EAAE;IAClB;AAEA,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,IAAI,MAAM,CAAC,CAAS,EAAA;AAClB,QAAA,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAC3C;QACF;AACA,QAAA,IAAI,CAAC,OAAO,GAAG,CAAC;QAChB,IAAI,CAAC,SAAS,EAAE;IAClB;AAEA;;;;;;;;AAQG;IACK,SAAS,GAAA;AACf,QAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB;QACF;QACA,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,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a,CAAC;AAChE,QAAA,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;AACtB,QAAA,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE;AAC5B,QAAA,IAAI,CAAC,UAAU,GAAG,IAAI;AAEtB,QAAA,IAAI,CAAC,SAAS,GAAG,CAAC;AAClB,QAAA,IAAI,CAAC,QAAQ,GAAG,CAAC;AACjB,QAAA,IAAI,CAAC,OAAO,GAAG,KAAK;IACtB;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin-sound.cjs.js","sources":["../lib/SoundSystem.ts","../lib/__combosPackageMeta.gen.ts","../lib/Sound.ts"],"sourcesContent":["import { System, decorators, ComponentChanged, OBSERVER_TYPE, resource } from '@combos-fun/engine';\nimport SoundComponent from './Sound';\n\ninterface SoundSystemParams {\n autoPauseAndStart?: boolean;\n onError?: (error: any) => void;\n}\n\n@decorators.componentObserver({\n Sound: [],\n})\nclass SoundSystem extends System {\n static systemName = 'SoundSystem';\n\n private ctx: AudioContext;\n\n private gainNode: GainNode;\n\n /** Whether to pause/resume in sync with the game. */\n private autoPauseAndStart = true;\n\n private onError: (error: any) => void;\n\n private components: SoundComponent[] = [];\n\n private pausedComponents: SoundComponent[] = [];\n\n private audioBufferCache = {};\n\n private decodeAudioPromiseMap = {};\n\n /** Desired mute/volume are the source of truth; the gain node is derived. */\n private _muted = false;\n\n private _volume = 1;\n\n get muted(): boolean {\n return this._muted;\n }\n\n set muted(v: boolean) {\n this._muted = v;\n this.applyGain();\n }\n\n get volume(): number {\n return this._volume;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this._volume = v;\n this.applyGain();\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * Assigns `gain.value` directly rather than `setValueAtTime`: `.value` updates\n * the AudioParam's intrinsic value synchronously, so the `muted` / `volume`\n * getters reflect the change immediately. `setValueAtTime` only schedules an\n * event on the automation timeline and leaves `.value` stale until the next\n * render quantum, which made `muted` report the pre-change value.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this._muted ? 0 : this._volume;\n }\n\n get audioLocked(): boolean {\n if (!this.ctx) {\n return true;\n }\n return this.ctx.state !== 'running';\n }\n\n constructor(obj?: SoundSystemParams) {\n super();\n Object.assign(this, obj);\n }\n\n /**\n * Resume playback of all paused audio.\n */\n resumeAll() {\n const handleResume = () => {\n this.pausedComponents.forEach(component => {\n component.play();\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n };\n this.ctx.resume().then(handleResume, handleResume);\n }\n\n /**\n * Pause all currently playing audio.\n */\n pauseAll() {\n this.components.forEach(component => {\n if (component.playing) {\n this.pausedComponents.push(component);\n component.pause();\n }\n });\n this.ctx.suspend().then();\n }\n\n /**\n * Stop all currently playing audio.\n */\n stopAll() {\n this.components.forEach(component => {\n if (component.playing) {\n component.stop();\n }\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n this.ctx.suspend().then();\n }\n\n /**\n * System init: configure params before the game starts.\n */\n init() {\n this.setupAudioContext();\n }\n\n update() {\n const changes = this.componentObserver.clear();\n for (const changed of changes) {\n this.componentChanged(changed);\n }\n }\n\n /**\n * Called when the game starts or resumes playing after a pause.\n */\n onResume() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.resumeAll();\n }\n\n /**\n * Called when the game is paused.\n */\n onPause() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.pauseAll();\n }\n\n /**\n * Called when the system is destroyed.\n */\n onDestroy() {\n this.components.forEach(component => {\n component.onDestroy();\n });\n this.components = [];\n if (this.ctx) {\n this.gainNode.disconnect();\n this.gainNode = null;\n this.ctx.close();\n this.ctx = null;\n }\n }\n\n async componentChanged(changed: ComponentChanged) {\n if (changed.componentName !== 'Sound') return;\n\n if (changed.type === OBSERVER_TYPE.ADD) {\n this.add(changed);\n }\n }\n\n private setupAudioContext() {\n try {\n const AudioContext = window.AudioContext || (window as any).webkitAudioContext;\n this.ctx = new AudioContext();\n } catch (error) {\n console.error(error);\n if (this.onError) {\n this.onError(error);\n }\n }\n\n if (!this.ctx) {\n return;\n }\n this.gainNode =\n typeof this.ctx.createGain === 'undefined' ? (this.ctx as any).createGainNode() : this.ctx.createGain();\n this.applyGain();\n this.gainNode.connect(this.ctx.destination);\n this.unlockAudio();\n }\n\n private unlockAudio() {\n if (!this.ctx || !this.audioLocked) {\n return;\n }\n\n const unlock = () => {\n if (this.ctx) {\n const removeListenerFn = () => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n document.body.removeEventListener('click', unlock);\n };\n this.ctx.resume().then(removeListenerFn, removeListenerFn);\n }\n };\n document.body.addEventListener('touchstart', unlock);\n document.body.addEventListener('touchend', unlock);\n document.body.addEventListener('click', unlock);\n }\n\n private async add(changed: ComponentChanged) {\n const component = changed.component as SoundComponent;\n this.components.push(component);\n try {\n const { config } = component;\n component.state = 'loading';\n\n const audio = await resource.getResource(config.resource);\n if (!this.audioBufferCache[audio.name] && audio?.data?.audio) {\n this.audioBufferCache[audio.name] = await this.decodeAudioData(audio.data.audio, audio.name);\n }\n if (this.audioBufferCache[audio.name]) {\n component.systemContext = this.ctx;\n component.systemDestination = this.gainNode;\n component.onload(this.audioBufferCache[audio.name]);\n }\n } catch (error) {\n if (this.onError) {\n this.onError(error);\n }\n }\n }\n\n private decodeAudioData(arraybuffer: ArrayBuffer, name: string) {\n if (this.decodeAudioPromiseMap[name]) {\n return this.decodeAudioPromiseMap[name];\n }\n\n const promise = new Promise<AudioBuffer>((resolve, reject) => {\n if (!this.ctx) {\n reject(new Error('No audio support'));\n }\n\n const success = (decodedData: AudioBuffer) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n if (decodedData) {\n resolve(decodedData);\n } else {\n reject(new Error(`Error decoding audio ${name}`));\n }\n };\n\n const error = (err: DOMException) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n reject(new Error(`${err}. arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n };\n\n const promise = this.ctx.decodeAudioData(arraybuffer, success, error)\n if (promise instanceof Promise) {\n promise.catch((err) => {\n reject(new Error(`catch ${err}, arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n });\n }\n });\n\n this.decodeAudioPromiseMap[name] = promise;\n return promise;\n }\n}\n\nexport default SoundSystem;\n","/** Auto-generated by scripts/build-package.mjs — do not edit. */\n\nimport SoundSystem from './SoundSystem';\n\nObject.assign(SoundSystem, {\n packageName: \"@combos-fun/plugin-sound\",\n packageVersion: \"0.0.34\",\n});\n","import { Component } from '@combos-fun/engine';\nimport { Field } from '@combos-fun/inspector-decorator';\n\nexport interface SoundParams {\n resource: string;\n autoplay?: boolean;\n muted?: boolean;\n volume?: number;\n loop?: boolean;\n seek?: number;\n duration?: number;\n onEnd?: () => void;\n}\n\nclass Sound extends Component<SoundParams> {\n static componentName = 'Sound';\n\n systemContext: AudioContext;\n\n systemDestination: GainNode;\n\n playing: boolean;\n\n state: 'unloaded' | 'loading' | 'loaded' = 'unloaded';\n\n config: SoundParams = {\n resource: '',\n autoplay: false,\n muted: false,\n volume: 1,\n loop: false,\n seek: 0,\n };\n\n private buffer: AudioBuffer;\n\n private sourceNode: AudioBufferSourceNode;\n\n private gainNode: GainNode;\n\n private paused: boolean;\n\n private playTime: number = 0;\n\n private startTime: number = 0;\n\n private duration: number = 0;\n\n private actionQueue: (() => void)[] = [];\n\n private endedListener: () => void;\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Muted',\n description: 'Silence this sound without changing its volume setting.',\n editor: 'toggle',\n })\n get muted(): boolean {\n return this.config.muted ?? false;\n }\n\n set muted(v: boolean) {\n this.config.muted = v;\n this.applyGain();\n }\n\n @Field({\n type: 'number',\n min: 0,\n max: 1,\n step: 0.01,\n group: 'Sound',\n label: 'Volume',\n description: 'Loudness of this sound from 0 (silent) to 1 (full).',\n editor: 'volume-slider',\n })\n get volume(): number {\n return this.config.volume ?? 1;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this.config.volume = v;\n this.applyGain();\n }\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Loop',\n description: 'Replay the sound continuously when it reaches the end.',\n editor: 'toggle',\n })\n get loop(): boolean {\n return this.config.loop ?? false;\n }\n\n set loop(v: boolean) {\n this.config.loop = v;\n if (this.sourceNode) {\n this.sourceNode.loop = v;\n }\n }\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Autoplay',\n description: 'Start playing automatically once the audio has loaded.',\n editor: 'toggle',\n })\n get autoplay(): boolean {\n return this.config.autoplay ?? false;\n }\n\n set autoplay(v: boolean) {\n this.config.autoplay = v;\n }\n\n @Field({\n type: 'string',\n group: 'Sound',\n label: 'Resource',\n description: 'Audio resource id used by the sound system.',\n editor: 'text',\n })\n get resource(): string {\n return this.config.resource ?? '';\n }\n\n set resource(v: string) {\n this.config.resource = v;\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * `config` is the source of truth and the gain is assigned via `gain.value`\n * (updates the AudioParam intrinsic value synchronously) so the `muted` /\n * `volume` getters — and anything reading them back, e.g. the scene-edit\n * volume slider — reflect the change immediately. `setValueAtTime` only\n * schedules on the automation timeline and leaves `.value` stale.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this.config.muted ? 0 : (this.config.volume ?? 1);\n }\n\n init(obj?: SoundParams) {\n if (!obj) {\n return;\n }\n\n Object.assign(this.config, obj);\n if (this.config.autoplay) {\n this.actionQueue.push(this.play.bind(this));\n }\n }\n\n play() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.play.bind(this));\n }\n this.destroySource();\n this.createSource();\n\n if (!this.sourceNode) {\n return;\n }\n const when = this.systemContext.currentTime;\n const offset = this.config.seek;\n const duration = this.config.duration;\n\n this.sourceNode.start(0, offset, duration);\n\n this.startTime = when;\n this.playTime = when - offset;\n this.paused = false;\n this.playing = true;\n this.resetConfig();\n this.endedListener = () => {\n if (!this.sourceNode) {\n return;\n }\n if (this.config.onEnd) {\n this.config.onEnd();\n }\n // Release resources once non-interactive playback finishes.\n if (this.playing) {\n this.destroySource();\n }\n };\n this.sourceNode.addEventListener('ended', this.endedListener);\n }\n\n pause() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.pause.bind(this));\n }\n if (this.paused || !this.playing) {\n return;\n }\n this.paused = true;\n this.playing = false;\n this.config.seek = this.getCurrentTime();\n this.destroySource();\n }\n\n stop() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.stop.bind(this));\n }\n if (!this.paused && !this.playing) {\n return;\n }\n this.playing = false;\n this.paused = false;\n this.destroySource();\n this.resetConfig();\n }\n\n onload(buffer: AudioBuffer) {\n this.state = 'loaded';\n this.buffer = buffer;\n this.duration = this.buffer.duration;\n this.actionQueue.forEach(action => action());\n this.actionQueue.length = 0;\n }\n\n onDestroy() {\n this.actionQueue.length = 0;\n this.destroySource();\n }\n\n private resetConfig() {\n this.config.seek = 0;\n }\n\n private getCurrentTime() {\n if (this.config.loop && this.duration > 0) {\n return (this.systemContext.currentTime - this.playTime) % this.duration;\n }\n\n return this.systemContext.currentTime - this.playTime;\n }\n\n private createSource() {\n if (!this.systemContext || this.state !== 'loaded') {\n return;\n }\n this.sourceNode = this.systemContext.createBufferSource();\n this.sourceNode.buffer = this.buffer;\n this.sourceNode.loop = this.config.loop;\n\n if (!this.gainNode) {\n this.gainNode = this.systemContext.createGain();\n this.gainNode.connect(this.systemDestination);\n Object.assign(this, this.config);\n }\n this.sourceNode.connect(this.gainNode);\n }\n\n private destroySource() {\n if (!this.sourceNode) return;\n this.sourceNode.removeEventListener('ended', this.endedListener);\n this.sourceNode.stop();\n this.sourceNode.disconnect();\n this.sourceNode = null;\n\n this.startTime = 0;\n this.playTime = 0;\n this.playing = false;\n }\n}\n\nexport default Sound;\n"],"names":["SoundSystem","System","OBSERVER_TYPE","resource","__decorate","decorators","Component","Field"],"mappings":";;;;;;AAWA,IAAMA,aAAW,GAAjB,MAAM,WAAY,SAAQC,aAAM,CAAA;aACvB,IAAA,CAAA,UAAU,GAAG,aAAH,CAAiB;AAwBlC,IAAA,IAAI,KAAK,GAAA;QACP,OAAO,IAAI,CAAC,MAAM;IACpB;IAEA,IAAI,KAAK,CAAC,CAAU,EAAA;AAClB,QAAA,IAAI,CAAC,MAAM,GAAG,CAAC;QACf,IAAI,CAAC,SAAS,EAAE;IAClB;AAEA,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,IAAI,MAAM,CAAC,CAAS,EAAA;AAClB,QAAA,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAC3C;QACF;AACA,QAAA,IAAI,CAAC,OAAO,GAAG,CAAC;QAChB,IAAI,CAAC,SAAS,EAAE;IAClB;AAEA;;;;;;;;AAQG;IACK,SAAS,GAAA;AACf,QAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB;QACF;QACA,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO;IAC3D;AAEA,IAAA,IAAI,WAAW,GAAA;AACb,QAAA,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;AACb,YAAA,OAAO,IAAI;QACb;AACA,QAAA,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,SAAS;IACrC;AAEA,IAAA,WAAA,CAAY,GAAuB,EAAA;AACjC,QAAA,KAAK,EAAE;;QA9DD,IAAA,CAAA,iBAAiB,GAAG,IAAI;QAIxB,IAAA,CAAA,UAAU,GAAqB,EAAE;QAEjC,IAAA,CAAA,gBAAgB,GAAqB,EAAE;QAEvC,IAAA,CAAA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A;AAPC,IAAAG,wBAAK,CAAC;AACL,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,KAAK,EAAE,OAAO;AACd,QAAA,KAAK,EAAE,MAAM;AACb,QAAA,WAAW,EAAE,wDAAwD;AACrE,QAAA,MAAM,EAAE,QAAQ;KACjB;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,MAAA,EAAA,IAAA,CAAA;AAgBDH,gBAAA,CAAA;AAPC,IAAAG,wBAAK,CAAC;AACL,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,KAAK,EAAE,OAAO;AACd,QAAA,KAAK,EAAE,UAAU;AACjB,QAAA,WAAW,EAAE,wDAAwD;AACrE,QAAA,MAAM,EAAE,QAAQ;KACjB;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;AAaDH,gBAAA,CAAA;AAPC,IAAAG,wBAAK,CAAC;AACL,QAAA,IAAI,EAAE,QAAQ;AACd,QAAA,KAAK,EAAE,OAAO;AACd,QAAA,KAAK,EAAE,UAAU;AACjB,QAAA,WAAW,EAAE,6CAA6C;AAC1D,QAAA,MAAM,EAAE,MAAM;KACf;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("tslib"),e=require("@combos-fun/engine");let s=class extends e.System{static{this.systemName="SoundSystem"}get muted(){return this._muted}set muted(t){this._muted=t,this.applyGain()}get volume(){return this._volume}set volume(t){"number"!=typeof t||t<0||t>1||(this._volume=t,this.applyGain())}applyGain(){this.gainNode&&(this.gainNode.gain.value=this._muted?0:this._volume)}get audioLocked(){return!this.ctx||"running"!==this.ctx.state}constructor(t){super(),this.autoPauseAndStart=!0,this.components=[],this.pausedComponents=[],this.audioBufferCache={},this.decodeAudioPromiseMap={},this._muted=!1,this._volume=1,Object.assign(this,t)}resumeAll(){const t=()=>{this.pausedComponents.forEach(t=>{t.play()}),this.pausedComponents=[]};this.ctx.resume().then(t,t)}pauseAll(){this.components.forEach(t=>{t.playing&&(this.pausedComponents.push(t),t.pause())}),this.ctx.suspend().then()}stopAll(){this.components.forEach(t=>{t.playing&&t.stop()}),this.pausedComponents=[],this.ctx.suspend().then()}init(){this.setupAudioContext()}update(){const t=this.componentObserver.clear();for(const e of t)this.componentChanged(e)}onResume(){this.autoPauseAndStart&&this.resumeAll()}onPause(){this.autoPauseAndStart&&this.pauseAll()}onDestroy(){this.components.forEach(t=>{t.onDestroy()}),this.components=[],this.ctx&&(this.gainNode.disconnect(),this.gainNode=null,this.ctx.close(),this.ctx=null)}async componentChanged(t){"Sound"===t.componentName&&t.type===e.OBSERVER_TYPE.ADD&&this.add(t)}setupAudioContext(){try{const t=window.AudioContext||window.webkitAudioContext;this.ctx=new t}catch(t){console.error(t),this.onError&&this.onError(t)}this.ctx&&(this.gainNode=void 0===this.ctx.createGain?this.ctx.createGainNode():this.ctx.createGain(),this.applyGain(),this.gainNode.connect(this.ctx.destination),this.unlockAudio())}unlockAudio(){if(!this.ctx||!this.audioLocked)return;const t=()=>{if(this.ctx){const e=()=>{document.body.removeEventListener("touchstart",t),document.body.removeEventListener("touchend",t),document.body.removeEventListener("click",t)};this.ctx.resume().then(e,e)}};document.body.addEventListener("touchstart",t),document.body.addEventListener("touchend",t),document.body.addEventListener("click",t)}async add(t){const
|
|
1
|
+
"use strict";var t=require("tslib"),e=require("@combos-fun/engine"),o=require("@combos-fun/inspector-decorator");let s=class extends e.System{static{this.systemName="SoundSystem"}get muted(){return this._muted}set muted(t){this._muted=t,this.applyGain()}get volume(){return this._volume}set volume(t){"number"!=typeof t||t<0||t>1||(this._volume=t,this.applyGain())}applyGain(){this.gainNode&&(this.gainNode.gain.value=this._muted?0:this._volume)}get audioLocked(){return!this.ctx||"running"!==this.ctx.state}constructor(t){super(),this.autoPauseAndStart=!0,this.components=[],this.pausedComponents=[],this.audioBufferCache={},this.decodeAudioPromiseMap={},this._muted=!1,this._volume=1,Object.assign(this,t)}resumeAll(){const t=()=>{this.pausedComponents.forEach(t=>{t.play()}),this.pausedComponents=[]};this.ctx.resume().then(t,t)}pauseAll(){this.components.forEach(t=>{t.playing&&(this.pausedComponents.push(t),t.pause())}),this.ctx.suspend().then()}stopAll(){this.components.forEach(t=>{t.playing&&t.stop()}),this.pausedComponents=[],this.ctx.suspend().then()}init(){this.setupAudioContext()}update(){const t=this.componentObserver.clear();for(const e of t)this.componentChanged(e)}onResume(){this.autoPauseAndStart&&this.resumeAll()}onPause(){this.autoPauseAndStart&&this.pauseAll()}onDestroy(){this.components.forEach(t=>{t.onDestroy()}),this.components=[],this.ctx&&(this.gainNode.disconnect(),this.gainNode=null,this.ctx.close(),this.ctx=null)}async componentChanged(t){"Sound"===t.componentName&&t.type===e.OBSERVER_TYPE.ADD&&this.add(t)}setupAudioContext(){try{const t=window.AudioContext||window.webkitAudioContext;this.ctx=new t}catch(t){console.error(t),this.onError&&this.onError(t)}this.ctx&&(this.gainNode=void 0===this.ctx.createGain?this.ctx.createGainNode():this.ctx.createGain(),this.applyGain(),this.gainNode.connect(this.ctx.destination),this.unlockAudio())}unlockAudio(){if(!this.ctx||!this.audioLocked)return;const t=()=>{if(this.ctx){const e=()=>{document.body.removeEventListener("touchstart",t),document.body.removeEventListener("touchend",t),document.body.removeEventListener("click",t)};this.ctx.resume().then(e,e)}};document.body.addEventListener("touchstart",t),document.body.addEventListener("touchend",t),document.body.addEventListener("click",t)}async add(t){const o=t.component;this.components.push(o);try{const{config:t}=o;o.state="loading";const s=await e.resource.getResource(t.resource);!this.audioBufferCache[s.name]&&s?.data?.audio&&(this.audioBufferCache[s.name]=await this.decodeAudioData(s.data.audio,s.name)),this.audioBufferCache[s.name]&&(o.systemContext=this.ctx,o.systemDestination=this.gainNode,o.onload(this.audioBufferCache[s.name]))}catch(t){this.onError&&this.onError(t)}}decodeAudioData(t,e){if(this.decodeAudioPromiseMap[e])return this.decodeAudioPromiseMap[e];const o=new Promise((o,s)=>{this.ctx||s(new Error("No audio support"));const i=this.ctx.decodeAudioData(t,t=>{this.decodeAudioPromiseMap[e]&&delete this.decodeAudioPromiseMap[e],t?o(t):s(new Error(`Error decoding audio ${e}`))},o=>{this.decodeAudioPromiseMap[e]&&delete this.decodeAudioPromiseMap[e],s(new Error(`${o}. arrayBuffer byteLength: ${t?t.byteLength:0}`))});i instanceof Promise&&i.catch(e=>{s(new Error(`catch ${e}, arrayBuffer byteLength: ${t?t.byteLength:0}`))})});return this.decodeAudioPromiseMap[e]=o,o}};s=t.__decorate([e.decorators.componentObserver({Sound:[]})],s);var i=s;Object.assign(i,{packageName:"@combos-fun/plugin-sound",packageVersion:"0.0.34"});class n extends e.Component{constructor(){super(...arguments),this.state="unloaded",this.config={resource:"",autoplay:!1,muted:!1,volume:1,loop:!1,seek:0},this.playTime=0,this.startTime=0,this.duration=0,this.actionQueue=[]}static{this.componentName="Sound"}get muted(){return this.config.muted??!1}set muted(t){this.config.muted=t,this.applyGain()}get volume(){return this.config.volume??1}set volume(t){"number"!=typeof t||t<0||t>1||(this.config.volume=t,this.applyGain())}get loop(){return this.config.loop??!1}set loop(t){this.config.loop=t,this.sourceNode&&(this.sourceNode.loop=t)}get autoplay(){return this.config.autoplay??!1}set autoplay(t){this.config.autoplay=t}get resource(){return this.config.resource??""}set resource(t){this.config.resource=t}applyGain(){this.gainNode&&(this.gainNode.gain.value=this.config.muted?0:this.config.volume??1)}init(t){t&&(Object.assign(this.config,t),this.config.autoplay&&this.actionQueue.push(this.play.bind(this)))}play(){if("loaded"!==this.state&&this.actionQueue.push(this.play.bind(this)),this.destroySource(),this.createSource(),!this.sourceNode)return;const t=this.systemContext.currentTime,e=this.config.seek,o=this.config.duration;this.sourceNode.start(0,e,o),this.startTime=t,this.playTime=t-e,this.paused=!1,this.playing=!0,this.resetConfig(),this.endedListener=()=>{this.sourceNode&&(this.config.onEnd&&this.config.onEnd(),this.playing&&this.destroySource())},this.sourceNode.addEventListener("ended",this.endedListener)}pause(){"loaded"!==this.state&&this.actionQueue.push(this.pause.bind(this)),!this.paused&&this.playing&&(this.paused=!0,this.playing=!1,this.config.seek=this.getCurrentTime(),this.destroySource())}stop(){"loaded"!==this.state&&this.actionQueue.push(this.stop.bind(this)),(this.paused||this.playing)&&(this.playing=!1,this.paused=!1,this.destroySource(),this.resetConfig())}onload(t){this.state="loaded",this.buffer=t,this.duration=this.buffer.duration,this.actionQueue.forEach(t=>t()),this.actionQueue.length=0}onDestroy(){this.actionQueue.length=0,this.destroySource()}resetConfig(){this.config.seek=0}getCurrentTime(){return this.config.loop&&this.duration>0?(this.systemContext.currentTime-this.playTime)%this.duration:this.systemContext.currentTime-this.playTime}createSource(){this.systemContext&&"loaded"===this.state&&(this.sourceNode=this.systemContext.createBufferSource(),this.sourceNode.buffer=this.buffer,this.sourceNode.loop=this.config.loop,this.gainNode||(this.gainNode=this.systemContext.createGain(),this.gainNode.connect(this.systemDestination),Object.assign(this,this.config)),this.sourceNode.connect(this.gainNode))}destroySource(){this.sourceNode&&(this.sourceNode.removeEventListener("ended",this.endedListener),this.sourceNode.stop(),this.sourceNode.disconnect(),this.sourceNode=null,this.startTime=0,this.playTime=0,this.playing=!1)}}t.__decorate([o.Field({type:"boolean",group:"Sound",label:"Muted",description:"Silence this sound without changing its volume setting.",editor:"toggle"})],n.prototype,"muted",null),t.__decorate([o.Field({type:"number",min:0,max:1,step:.01,group:"Sound",label:"Volume",description:"Loudness of this sound from 0 (silent) to 1 (full).",editor:"volume-slider"})],n.prototype,"volume",null),t.__decorate([o.Field({type:"boolean",group:"Sound",label:"Loop",description:"Replay the sound continuously when it reaches the end.",editor:"toggle"})],n.prototype,"loop",null),t.__decorate([o.Field({type:"boolean",group:"Sound",label:"Autoplay",description:"Start playing automatically once the audio has loaded.",editor:"toggle"})],n.prototype,"autoplay",null),t.__decorate([o.Field({type:"string",group:"Sound",label:"Resource",description:"Audio resource id used by the sound system.",editor:"text"})],n.prototype,"resource",null),exports.Sound=n,exports.SoundSystem=i;
|
package/dist/plugin-sound.d.ts
CHANGED
|
@@ -100,6 +100,12 @@ declare class Sound extends Component<SoundParams> {
|
|
|
100
100
|
set muted(v: boolean);
|
|
101
101
|
get volume(): number;
|
|
102
102
|
set volume(v: number);
|
|
103
|
+
get loop(): boolean;
|
|
104
|
+
set loop(v: boolean);
|
|
105
|
+
get autoplay(): boolean;
|
|
106
|
+
set autoplay(v: boolean);
|
|
107
|
+
get resource(): string;
|
|
108
|
+
set resource(v: string);
|
|
103
109
|
/**
|
|
104
110
|
* Apply the effective gain (`muted ? 0 : volume`) to the gain node.
|
|
105
111
|
*
|
package/dist/plugin-sound.esm.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
2
|
import { System, OBSERVER_TYPE, resource, decorators, Component } from '@combos-fun/engine';
|
|
3
|
+
import { Field } from '@combos-fun/inspector-decorator';
|
|
3
4
|
|
|
4
5
|
let SoundSystem = class SoundSystem extends System {
|
|
5
6
|
static { this.systemName = 'SoundSystem'; }
|
|
@@ -250,7 +251,7 @@ var SoundSystem$1 = SoundSystem;
|
|
|
250
251
|
/** Auto-generated by scripts/build-package.mjs — do not edit. */
|
|
251
252
|
Object.assign(SoundSystem$1, {
|
|
252
253
|
packageName: "@combos-fun/plugin-sound",
|
|
253
|
-
packageVersion: "0.0.
|
|
254
|
+
packageVersion: "0.0.34",
|
|
254
255
|
});
|
|
255
256
|
|
|
256
257
|
class Sound extends Component {
|
|
@@ -288,6 +289,27 @@ class Sound extends Component {
|
|
|
288
289
|
this.config.volume = v;
|
|
289
290
|
this.applyGain();
|
|
290
291
|
}
|
|
292
|
+
get loop() {
|
|
293
|
+
return this.config.loop ?? false;
|
|
294
|
+
}
|
|
295
|
+
set loop(v) {
|
|
296
|
+
this.config.loop = v;
|
|
297
|
+
if (this.sourceNode) {
|
|
298
|
+
this.sourceNode.loop = v;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
get autoplay() {
|
|
302
|
+
return this.config.autoplay ?? false;
|
|
303
|
+
}
|
|
304
|
+
set autoplay(v) {
|
|
305
|
+
this.config.autoplay = v;
|
|
306
|
+
}
|
|
307
|
+
get resource() {
|
|
308
|
+
return this.config.resource ?? '';
|
|
309
|
+
}
|
|
310
|
+
set resource(v) {
|
|
311
|
+
this.config.resource = v;
|
|
312
|
+
}
|
|
291
313
|
/**
|
|
292
314
|
* Apply the effective gain (`muted ? 0 : volume`) to the gain node.
|
|
293
315
|
*
|
|
@@ -414,6 +436,54 @@ class Sound extends Component {
|
|
|
414
436
|
this.playing = false;
|
|
415
437
|
}
|
|
416
438
|
}
|
|
439
|
+
__decorate([
|
|
440
|
+
Field({
|
|
441
|
+
type: 'boolean',
|
|
442
|
+
group: 'Sound',
|
|
443
|
+
label: 'Muted',
|
|
444
|
+
description: 'Silence this sound without changing its volume setting.',
|
|
445
|
+
editor: 'toggle',
|
|
446
|
+
})
|
|
447
|
+
], Sound.prototype, "muted", null);
|
|
448
|
+
__decorate([
|
|
449
|
+
Field({
|
|
450
|
+
type: 'number',
|
|
451
|
+
min: 0,
|
|
452
|
+
max: 1,
|
|
453
|
+
step: 0.01,
|
|
454
|
+
group: 'Sound',
|
|
455
|
+
label: 'Volume',
|
|
456
|
+
description: 'Loudness of this sound from 0 (silent) to 1 (full).',
|
|
457
|
+
editor: 'volume-slider',
|
|
458
|
+
})
|
|
459
|
+
], Sound.prototype, "volume", null);
|
|
460
|
+
__decorate([
|
|
461
|
+
Field({
|
|
462
|
+
type: 'boolean',
|
|
463
|
+
group: 'Sound',
|
|
464
|
+
label: 'Loop',
|
|
465
|
+
description: 'Replay the sound continuously when it reaches the end.',
|
|
466
|
+
editor: 'toggle',
|
|
467
|
+
})
|
|
468
|
+
], Sound.prototype, "loop", null);
|
|
469
|
+
__decorate([
|
|
470
|
+
Field({
|
|
471
|
+
type: 'boolean',
|
|
472
|
+
group: 'Sound',
|
|
473
|
+
label: 'Autoplay',
|
|
474
|
+
description: 'Start playing automatically once the audio has loaded.',
|
|
475
|
+
editor: 'toggle',
|
|
476
|
+
})
|
|
477
|
+
], Sound.prototype, "autoplay", null);
|
|
478
|
+
__decorate([
|
|
479
|
+
Field({
|
|
480
|
+
type: 'string',
|
|
481
|
+
group: 'Sound',
|
|
482
|
+
label: 'Resource',
|
|
483
|
+
description: 'Audio resource id used by the sound system.',
|
|
484
|
+
editor: 'text',
|
|
485
|
+
})
|
|
486
|
+
], Sound.prototype, "resource", null);
|
|
417
487
|
|
|
418
488
|
export { Sound, SoundSystem$1 as SoundSystem };
|
|
419
489
|
//# sourceMappingURL=plugin-sound.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-sound.esm.js","sources":["../lib/SoundSystem.ts","../lib/__combosPackageMeta.gen.ts","../lib/Sound.ts"],"sourcesContent":["import { System, decorators, ComponentChanged, OBSERVER_TYPE, resource } from '@combos-fun/engine';\nimport SoundComponent from './Sound';\n\ninterface SoundSystemParams {\n autoPauseAndStart?: boolean;\n onError?: (error: any) => void;\n}\n\n@decorators.componentObserver({\n Sound: [],\n})\nclass SoundSystem extends System {\n static systemName = 'SoundSystem';\n\n private ctx: AudioContext;\n\n private gainNode: GainNode;\n\n /** Whether to pause/resume in sync with the game. */\n private autoPauseAndStart = true;\n\n private onError: (error: any) => void;\n\n private components: SoundComponent[] = [];\n\n private pausedComponents: SoundComponent[] = [];\n\n private audioBufferCache = {};\n\n private decodeAudioPromiseMap = {};\n\n /** Desired mute/volume are the source of truth; the gain node is derived. */\n private _muted = false;\n\n private _volume = 1;\n\n get muted(): boolean {\n return this._muted;\n }\n\n set muted(v: boolean) {\n this._muted = v;\n this.applyGain();\n }\n\n get volume(): number {\n return this._volume;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this._volume = v;\n this.applyGain();\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * Assigns `gain.value` directly rather than `setValueAtTime`: `.value` updates\n * the AudioParam's intrinsic value synchronously, so the `muted` / `volume`\n * getters reflect the change immediately. `setValueAtTime` only schedules an\n * event on the automation timeline and leaves `.value` stale until the next\n * render quantum, which made `muted` report the pre-change value.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this._muted ? 0 : this._volume;\n }\n\n get audioLocked(): boolean {\n if (!this.ctx) {\n return true;\n }\n return this.ctx.state !== 'running';\n }\n\n constructor(obj?: SoundSystemParams) {\n super();\n Object.assign(this, obj);\n }\n\n /**\n * Resume playback of all paused audio.\n */\n resumeAll() {\n const handleResume = () => {\n this.pausedComponents.forEach(component => {\n component.play();\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n };\n this.ctx.resume().then(handleResume, handleResume);\n }\n\n /**\n * Pause all currently playing audio.\n */\n pauseAll() {\n this.components.forEach(component => {\n if (component.playing) {\n this.pausedComponents.push(component);\n component.pause();\n }\n });\n this.ctx.suspend().then();\n }\n\n /**\n * Stop all currently playing audio.\n */\n stopAll() {\n this.components.forEach(component => {\n if (component.playing) {\n component.stop();\n }\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n this.ctx.suspend().then();\n }\n\n /**\n * System init: configure params before the game starts.\n */\n init() {\n this.setupAudioContext();\n }\n\n update() {\n const changes = this.componentObserver.clear();\n for (const changed of changes) {\n this.componentChanged(changed);\n }\n }\n\n /**\n * Called when the game starts or resumes playing after a pause.\n */\n onResume() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.resumeAll();\n }\n\n /**\n * Called when the game is paused.\n */\n onPause() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.pauseAll();\n }\n\n /**\n * Called when the system is destroyed.\n */\n onDestroy() {\n this.components.forEach(component => {\n component.onDestroy();\n });\n this.components = [];\n if (this.ctx) {\n this.gainNode.disconnect();\n this.gainNode = null;\n this.ctx.close();\n this.ctx = null;\n }\n }\n\n async componentChanged(changed: ComponentChanged) {\n if (changed.componentName !== 'Sound') return;\n\n if (changed.type === OBSERVER_TYPE.ADD) {\n this.add(changed);\n }\n }\n\n private setupAudioContext() {\n try {\n const AudioContext = window.AudioContext || (window as any).webkitAudioContext;\n this.ctx = new AudioContext();\n } catch (error) {\n console.error(error);\n if (this.onError) {\n this.onError(error);\n }\n }\n\n if (!this.ctx) {\n return;\n }\n this.gainNode =\n typeof this.ctx.createGain === 'undefined' ? (this.ctx as any).createGainNode() : this.ctx.createGain();\n this.applyGain();\n this.gainNode.connect(this.ctx.destination);\n this.unlockAudio();\n }\n\n private unlockAudio() {\n if (!this.ctx || !this.audioLocked) {\n return;\n }\n\n const unlock = () => {\n if (this.ctx) {\n const removeListenerFn = () => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n document.body.removeEventListener('click', unlock);\n };\n this.ctx.resume().then(removeListenerFn, removeListenerFn);\n }\n };\n document.body.addEventListener('touchstart', unlock);\n document.body.addEventListener('touchend', unlock);\n document.body.addEventListener('click', unlock);\n }\n\n private async add(changed: ComponentChanged) {\n const component = changed.component as SoundComponent;\n this.components.push(component);\n try {\n const { config } = component;\n component.state = 'loading';\n\n const audio = await resource.getResource(config.resource);\n if (!this.audioBufferCache[audio.name] && audio?.data?.audio) {\n this.audioBufferCache[audio.name] = await this.decodeAudioData(audio.data.audio, audio.name);\n }\n if (this.audioBufferCache[audio.name]) {\n component.systemContext = this.ctx;\n component.systemDestination = this.gainNode;\n component.onload(this.audioBufferCache[audio.name]);\n }\n } catch (error) {\n if (this.onError) {\n this.onError(error);\n }\n }\n }\n\n private decodeAudioData(arraybuffer: ArrayBuffer, name: string) {\n if (this.decodeAudioPromiseMap[name]) {\n return this.decodeAudioPromiseMap[name];\n }\n\n const promise = new Promise<AudioBuffer>((resolve, reject) => {\n if (!this.ctx) {\n reject(new Error('No audio support'));\n }\n\n const success = (decodedData: AudioBuffer) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n if (decodedData) {\n resolve(decodedData);\n } else {\n reject(new Error(`Error decoding audio ${name}`));\n }\n };\n\n const error = (err: DOMException) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n reject(new Error(`${err}. arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n };\n\n const promise = this.ctx.decodeAudioData(arraybuffer, success, error)\n if (promise instanceof Promise) {\n promise.catch((err) => {\n reject(new Error(`catch ${err}, arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n });\n }\n });\n\n this.decodeAudioPromiseMap[name] = promise;\n return promise;\n }\n}\n\nexport default SoundSystem;\n","/** Auto-generated by scripts/build-package.mjs — do not edit. */\n\nimport SoundSystem from './SoundSystem';\n\nObject.assign(SoundSystem, {\n packageName: \"@combos-fun/plugin-sound\",\n packageVersion: \"0.0.33\",\n});\n","import { Component } from '@combos-fun/engine';\n\nexport interface SoundParams {\n resource: string;\n autoplay?: boolean;\n muted?: boolean;\n volume?: number;\n loop?: boolean;\n seek?: number;\n duration?: number;\n onEnd?: () => void;\n}\n\nclass Sound extends Component<SoundParams> {\n static componentName = 'Sound';\n\n systemContext: AudioContext;\n\n systemDestination: GainNode;\n\n playing: boolean;\n\n state: 'unloaded' | 'loading' | 'loaded' = 'unloaded';\n\n config: SoundParams = {\n resource: '',\n autoplay: false,\n muted: false,\n volume: 1,\n loop: false,\n seek: 0,\n };\n\n private buffer: AudioBuffer;\n\n private sourceNode: AudioBufferSourceNode;\n\n private gainNode: GainNode;\n\n private paused: boolean;\n\n private playTime: number = 0;\n\n private startTime: number = 0;\n\n private duration: number = 0;\n\n private actionQueue: (() => void)[] = [];\n\n private endedListener: () => void;\n\n get muted(): boolean {\n return this.config.muted ?? false;\n }\n\n set muted(v: boolean) {\n this.config.muted = v;\n this.applyGain();\n }\n\n get volume(): number {\n return this.config.volume ?? 1;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this.config.volume = v;\n this.applyGain();\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * `config` is the source of truth and the gain is assigned via `gain.value`\n * (updates the AudioParam intrinsic value synchronously) so the `muted` /\n * `volume` getters — and anything reading them back, e.g. the scene-edit\n * volume slider — reflect the change immediately. `setValueAtTime` only\n * schedules on the automation timeline and leaves `.value` stale.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this.config.muted ? 0 : (this.config.volume ?? 1);\n }\n\n init(obj?: SoundParams) {\n if (!obj) {\n return;\n }\n\n Object.assign(this.config, obj);\n if (this.config.autoplay) {\n this.actionQueue.push(this.play.bind(this));\n }\n }\n\n play() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.play.bind(this));\n }\n this.destroySource();\n this.createSource();\n\n if (!this.sourceNode) {\n return;\n }\n const when = this.systemContext.currentTime;\n const offset = this.config.seek;\n const duration = this.config.duration;\n\n this.sourceNode.start(0, offset, duration);\n\n this.startTime = when;\n this.playTime = when - offset;\n this.paused = false;\n this.playing = true;\n this.resetConfig();\n this.endedListener = () => {\n if (!this.sourceNode) {\n return;\n }\n if (this.config.onEnd) {\n this.config.onEnd();\n }\n // Release resources once non-interactive playback finishes.\n if (this.playing) {\n this.destroySource();\n }\n };\n this.sourceNode.addEventListener('ended', this.endedListener);\n }\n\n pause() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.pause.bind(this));\n }\n if (this.paused || !this.playing) {\n return;\n }\n this.paused = true;\n this.playing = false;\n this.config.seek = this.getCurrentTime();\n this.destroySource();\n }\n\n stop() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.stop.bind(this));\n }\n if (!this.paused && !this.playing) {\n return;\n }\n this.playing = false;\n this.paused = false;\n this.destroySource();\n this.resetConfig();\n }\n\n onload(buffer: AudioBuffer) {\n this.state = 'loaded';\n this.buffer = buffer;\n this.duration = this.buffer.duration;\n this.actionQueue.forEach(action => action());\n this.actionQueue.length = 0;\n }\n\n onDestroy() {\n this.actionQueue.length = 0;\n this.destroySource();\n }\n\n private resetConfig() {\n this.config.seek = 0;\n }\n\n private getCurrentTime() {\n if (this.config.loop && this.duration > 0) {\n return (this.systemContext.currentTime - this.playTime) % this.duration;\n }\n\n return this.systemContext.currentTime - this.playTime;\n }\n\n private createSource() {\n if (!this.systemContext || this.state !== 'loaded') {\n return;\n }\n this.sourceNode = this.systemContext.createBufferSource();\n this.sourceNode.buffer = this.buffer;\n this.sourceNode.loop = this.config.loop;\n\n if (!this.gainNode) {\n this.gainNode = this.systemContext.createGain();\n this.gainNode.connect(this.systemDestination);\n Object.assign(this, this.config);\n }\n this.sourceNode.connect(this.gainNode);\n }\n\n private destroySource() {\n if (!this.sourceNode) return;\n this.sourceNode.removeEventListener('ended', this.endedListener);\n this.sourceNode.stop();\n this.sourceNode.disconnect();\n this.sourceNode = null;\n\n this.startTime = 0;\n this.playTime = 0;\n this.playing = false;\n }\n}\n\nexport default Sound;\n"],"names":["SoundSystem"],"mappings":";;;AAWA,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,MAAM,CAAA;aACvB,IAAA,CAAA,UAAU,GAAG,aAAH,CAAiB;AAwBlC,IAAA,IAAI,KAAK,GAAA;QACP,OAAO,IAAI,CAAC,MAAM;IACpB;IAEA,IAAI,KAAK,CAAC,CAAU,EAAA;AAClB,QAAA,IAAI,CAAC,MAAM,GAAG,CAAC;QACf,IAAI,CAAC,SAAS,EAAE;IAClB;AAEA,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,IAAI,MAAM,CAAC,CAAS,EAAA;AAClB,QAAA,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAC3C;QACF;AACA,QAAA,IAAI,CAAC,OAAO,GAAG,CAAC;QAChB,IAAI,CAAC,SAAS,EAAE;IAClB;AAEA;;;;;;;;AAQG;IACK,S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CAAC,QAAQ,CAAC;IACxC;IAEQ,aAAa,GAAA;QACnB,IAAI,CAAC,IAAI,CAAC,UAAU;YAAE;QACtB,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC;AAChE,QAAA,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;AACtB,QAAA,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE;AAC5B,QAAA,IAAI,CAAC,UAAU,GAAG,IAAI;AAEtB,QAAA,IAAI,CAAC,SAAS,GAAG,CAAC;AAClB,QAAA,IAAI,CAAC,QAAQ,GAAG,CAAC;AACjB,QAAA,IAAI,CAAC,OAAO,GAAG,KAAK;IACtB;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin-sound.esm.js","sources":["../lib/SoundSystem.ts","../lib/__combosPackageMeta.gen.ts","../lib/Sound.ts"],"sourcesContent":["import { System, decorators, ComponentChanged, OBSERVER_TYPE, resource } from '@combos-fun/engine';\nimport SoundComponent from './Sound';\n\ninterface SoundSystemParams {\n autoPauseAndStart?: boolean;\n onError?: (error: any) => void;\n}\n\n@decorators.componentObserver({\n Sound: [],\n})\nclass SoundSystem extends System {\n static systemName = 'SoundSystem';\n\n private ctx: AudioContext;\n\n private gainNode: GainNode;\n\n /** Whether to pause/resume in sync with the game. */\n private autoPauseAndStart = true;\n\n private onError: (error: any) => void;\n\n private components: SoundComponent[] = [];\n\n private pausedComponents: SoundComponent[] = [];\n\n private audioBufferCache = {};\n\n private decodeAudioPromiseMap = {};\n\n /** Desired mute/volume are the source of truth; the gain node is derived. */\n private _muted = false;\n\n private _volume = 1;\n\n get muted(): boolean {\n return this._muted;\n }\n\n set muted(v: boolean) {\n this._muted = v;\n this.applyGain();\n }\n\n get volume(): number {\n return this._volume;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this._volume = v;\n this.applyGain();\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * Assigns `gain.value` directly rather than `setValueAtTime`: `.value` updates\n * the AudioParam's intrinsic value synchronously, so the `muted` / `volume`\n * getters reflect the change immediately. `setValueAtTime` only schedules an\n * event on the automation timeline and leaves `.value` stale until the next\n * render quantum, which made `muted` report the pre-change value.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this._muted ? 0 : this._volume;\n }\n\n get audioLocked(): boolean {\n if (!this.ctx) {\n return true;\n }\n return this.ctx.state !== 'running';\n }\n\n constructor(obj?: SoundSystemParams) {\n super();\n Object.assign(this, obj);\n }\n\n /**\n * Resume playback of all paused audio.\n */\n resumeAll() {\n const handleResume = () => {\n this.pausedComponents.forEach(component => {\n component.play();\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n };\n this.ctx.resume().then(handleResume, handleResume);\n }\n\n /**\n * Pause all currently playing audio.\n */\n pauseAll() {\n this.components.forEach(component => {\n if (component.playing) {\n this.pausedComponents.push(component);\n component.pause();\n }\n });\n this.ctx.suspend().then();\n }\n\n /**\n * Stop all currently playing audio.\n */\n stopAll() {\n this.components.forEach(component => {\n if (component.playing) {\n component.stop();\n }\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n this.ctx.suspend().then();\n }\n\n /**\n * System init: configure params before the game starts.\n */\n init() {\n this.setupAudioContext();\n }\n\n update() {\n const changes = this.componentObserver.clear();\n for (const changed of changes) {\n this.componentChanged(changed);\n }\n }\n\n /**\n * Called when the game starts or resumes playing after a pause.\n */\n onResume() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.resumeAll();\n }\n\n /**\n * Called when the game is paused.\n */\n onPause() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.pauseAll();\n }\n\n /**\n * Called when the system is destroyed.\n */\n onDestroy() {\n this.components.forEach(component => {\n component.onDestroy();\n });\n this.components = [];\n if (this.ctx) {\n this.gainNode.disconnect();\n this.gainNode = null;\n this.ctx.close();\n this.ctx = null;\n }\n }\n\n async componentChanged(changed: ComponentChanged) {\n if (changed.componentName !== 'Sound') return;\n\n if (changed.type === OBSERVER_TYPE.ADD) {\n this.add(changed);\n }\n }\n\n private setupAudioContext() {\n try {\n const AudioContext = window.AudioContext || (window as any).webkitAudioContext;\n this.ctx = new AudioContext();\n } catch (error) {\n console.error(error);\n if (this.onError) {\n this.onError(error);\n }\n }\n\n if (!this.ctx) {\n return;\n }\n this.gainNode =\n typeof this.ctx.createGain === 'undefined' ? (this.ctx as any).createGainNode() : this.ctx.createGain();\n this.applyGain();\n this.gainNode.connect(this.ctx.destination);\n this.unlockAudio();\n }\n\n private unlockAudio() {\n if (!this.ctx || !this.audioLocked) {\n return;\n }\n\n const unlock = () => {\n if (this.ctx) {\n const removeListenerFn = () => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n document.body.removeEventListener('click', unlock);\n };\n this.ctx.resume().then(removeListenerFn, removeListenerFn);\n }\n };\n document.body.addEventListener('touchstart', unlock);\n document.body.addEventListener('touchend', unlock);\n document.body.addEventListener('click', unlock);\n }\n\n private async add(changed: ComponentChanged) {\n const component = changed.component as SoundComponent;\n this.components.push(component);\n try {\n const { config } = component;\n component.state = 'loading';\n\n const audio = await resource.getResource(config.resource);\n if (!this.audioBufferCache[audio.name] && audio?.data?.audio) {\n this.audioBufferCache[audio.name] = await this.decodeAudioData(audio.data.audio, audio.name);\n }\n if (this.audioBufferCache[audio.name]) {\n component.systemContext = this.ctx;\n component.systemDestination = this.gainNode;\n component.onload(this.audioBufferCache[audio.name]);\n }\n } catch (error) {\n if (this.onError) {\n this.onError(error);\n }\n }\n }\n\n private decodeAudioData(arraybuffer: ArrayBuffer, name: string) {\n if (this.decodeAudioPromiseMap[name]) {\n return this.decodeAudioPromiseMap[name];\n }\n\n const promise = new Promise<AudioBuffer>((resolve, reject) => {\n if (!this.ctx) {\n reject(new Error('No audio support'));\n }\n\n const success = (decodedData: AudioBuffer) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n if (decodedData) {\n resolve(decodedData);\n } else {\n reject(new Error(`Error decoding audio ${name}`));\n }\n };\n\n const error = (err: DOMException) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n reject(new Error(`${err}. arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n };\n\n const promise = this.ctx.decodeAudioData(arraybuffer, success, error)\n if (promise instanceof Promise) {\n promise.catch((err) => {\n reject(new Error(`catch ${err}, arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n });\n }\n });\n\n this.decodeAudioPromiseMap[name] = promise;\n return promise;\n }\n}\n\nexport default SoundSystem;\n","/** Auto-generated by scripts/build-package.mjs — do not edit. */\n\nimport SoundSystem from './SoundSystem';\n\nObject.assign(SoundSystem, {\n packageName: \"@combos-fun/plugin-sound\",\n packageVersion: \"0.0.34\",\n});\n","import { Component } from '@combos-fun/engine';\nimport { Field } from '@combos-fun/inspector-decorator';\n\nexport interface SoundParams {\n resource: string;\n autoplay?: boolean;\n muted?: boolean;\n volume?: number;\n loop?: boolean;\n seek?: number;\n duration?: number;\n onEnd?: () => void;\n}\n\nclass Sound extends Component<SoundParams> {\n static componentName = 'Sound';\n\n systemContext: AudioContext;\n\n systemDestination: GainNode;\n\n playing: boolean;\n\n state: 'unloaded' | 'loading' | 'loaded' = 'unloaded';\n\n config: SoundParams = {\n resource: '',\n autoplay: false,\n muted: false,\n volume: 1,\n loop: false,\n seek: 0,\n };\n\n private buffer: AudioBuffer;\n\n private sourceNode: AudioBufferSourceNode;\n\n private gainNode: GainNode;\n\n private paused: boolean;\n\n private playTime: number = 0;\n\n private startTime: number = 0;\n\n private duration: number = 0;\n\n private actionQueue: (() => void)[] = [];\n\n private endedListener: () => void;\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Muted',\n description: 'Silence this sound without changing its volume setting.',\n editor: 'toggle',\n })\n get muted(): boolean {\n return this.config.muted ?? false;\n }\n\n set muted(v: boolean) {\n this.config.muted = v;\n this.applyGain();\n }\n\n @Field({\n type: 'number',\n min: 0,\n max: 1,\n step: 0.01,\n group: 'Sound',\n label: 'Volume',\n description: 'Loudness of this sound from 0 (silent) to 1 (full).',\n editor: 'volume-slider',\n })\n get volume(): number {\n return this.config.volume ?? 1;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this.config.volume = v;\n this.applyGain();\n }\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Loop',\n description: 'Replay the sound continuously when it reaches the end.',\n editor: 'toggle',\n })\n get loop(): boolean {\n return this.config.loop ?? false;\n }\n\n set loop(v: boolean) {\n this.config.loop = v;\n if (this.sourceNode) {\n this.sourceNode.loop = v;\n }\n }\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Autoplay',\n description: 'Start playing automatically once the audio has loaded.',\n editor: 'toggle',\n })\n get autoplay(): boolean {\n return this.config.autoplay ?? false;\n }\n\n set autoplay(v: boolean) {\n this.config.autoplay = v;\n }\n\n @Field({\n type: 'string',\n group: 'Sound',\n label: 'Resource',\n description: 'Audio resource id used by the sound system.',\n editor: 'text',\n })\n get resource(): string {\n return this.config.resource ?? '';\n }\n\n set resource(v: string) {\n this.config.resource = v;\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * `config` is the source of truth and the gain is assigned via `gain.value`\n * (updates the AudioParam intrinsic value synchronously) so the `muted` /\n * `volume` getters — and anything reading them back, e.g. the scene-edit\n * volume slider — reflect the change immediately. `setValueAtTime` only\n * schedules on the automation timeline and leaves `.value` stale.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this.config.muted ? 0 : (this.config.volume ?? 1);\n }\n\n init(obj?: SoundParams) {\n if (!obj) {\n return;\n }\n\n Object.assign(this.config, obj);\n if (this.config.autoplay) {\n this.actionQueue.push(this.play.bind(this));\n }\n }\n\n play() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.play.bind(this));\n }\n this.destroySource();\n this.createSource();\n\n if (!this.sourceNode) {\n return;\n }\n const when = this.systemContext.currentTime;\n const offset = this.config.seek;\n const duration = this.config.duration;\n\n this.sourceNode.start(0, offset, duration);\n\n this.startTime = when;\n this.playTime = when - offset;\n this.paused = false;\n this.playing = true;\n this.resetConfig();\n this.endedListener = () => {\n if (!this.sourceNode) {\n return;\n }\n if (this.config.onEnd) {\n this.config.onEnd();\n }\n // Release resources once non-interactive playback finishes.\n if (this.playing) {\n this.destroySource();\n }\n };\n this.sourceNode.addEventListener('ended', this.endedListener);\n }\n\n pause() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.pause.bind(this));\n }\n if (this.paused || !this.playing) {\n return;\n }\n this.paused = true;\n this.playing = false;\n this.config.seek = this.getCurrentTime();\n this.destroySource();\n }\n\n stop() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.stop.bind(this));\n }\n if (!this.paused && !this.playing) {\n return;\n }\n this.playing = false;\n this.paused = false;\n this.destroySource();\n this.resetConfig();\n }\n\n onload(buffer: AudioBuffer) {\n this.state = 'loaded';\n this.buffer = buffer;\n this.duration = this.buffer.duration;\n this.actionQueue.forEach(action => action());\n this.actionQueue.length = 0;\n }\n\n onDestroy() {\n this.actionQueue.length = 0;\n this.destroySource();\n }\n\n private resetConfig() {\n this.config.seek = 0;\n }\n\n private getCurrentTime() {\n if (this.config.loop && this.duration > 0) {\n return (this.systemContext.currentTime - this.playTime) % this.duration;\n }\n\n return this.systemContext.currentTime - this.playTime;\n }\n\n private createSource() {\n if (!this.systemContext || this.state !== 'loaded') {\n return;\n }\n this.sourceNode = this.systemContext.createBufferSource();\n this.sourceNode.buffer = this.buffer;\n this.sourceNode.loop = this.config.loop;\n\n if (!this.gainNode) {\n this.gainNode = this.systemContext.createGain();\n this.gainNode.connect(this.systemDestination);\n Object.assign(this, this.config);\n }\n this.sourceNode.connect(this.gainNode);\n }\n\n private destroySource() {\n if (!this.sourceNode) return;\n this.sourceNode.removeEventListener('ended', this.endedListener);\n this.sourceNode.stop();\n this.sourceNode.disconnect();\n this.sourceNode = null;\n\n this.startTime = 0;\n this.playTime = 0;\n this.playing = false;\n }\n}\n\nexport default Sound;\n"],"names":["SoundSystem"],"mappings":";;;;AAWA,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,MAAM,CAAA;aACvB,IAAA,CAAA,UAAU,GAAG,aAAH,CAAiB;AAwBlC,IAAA,IAAI,KAAK,GAAA;QACP,OAAO,IAAI,CAAC,MAAM;IACpB;IAEA,IAAI,KAAK,CAAC,CAAU,EAAA;AAClB,QAAA,IAAI,CAAC,MAAM,GAAG,CAAC;QACf,IAAI,CAAC,SAAS,EAAE;IAClB;AAEA,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,IAAI,MAAM,CAAC,CAAS,EAAA;AAClB,QAAA,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAC3C;QACF;AACA,QAAA,IAAI,CAAC,OAAO,GAAG,CAAC;QAChB,IAAI,CAAC,SAAS,EAAE;IAClB;AAEA;;;;;;;;AAQG;IACK,SAAS,GAAA;AACf,QAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB;QACF;QACA,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO;IAC3D;AAEA,IAAA,IAAI,WAAW,GAAA;AACb,QAAA,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;AACb,YAAA,OAAO,IAAI;QACb;AACA,QAAA,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,SAAS;IACrC;AAEA,IAAA,WAAA,CAAY,GAAuB,EAAA;AACjC,QAAA,KAAK,EAAE;;QA9DD,IAAA,CAAA,iBA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KACxB;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,QAAA,EAAA,IAAA,CAAA;AAiBD,UAAA,CAAA;AAPC,IAAA,KAAK,CAAC;AACL,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,KAAK,EAAE,OAAO;AACd,QAAA,KAAK,EAAE,MAAM;AACb,QAAA,WAAW,EAAE,wDAAwD;AACrE,QAAA,MAAM,EAAE,QAAQ;KACjB;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,MAAA,EAAA,IAAA,CAAA;AAgBD,UAAA,CAAA;AAPC,IAAA,KAAK,CAAC;AACL,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,KAAK,EAAE,OAAO;AACd,QAAA,KAAK,EAAE,UAAU;AACjB,QAAA,WAAW,EAAE,wDAAwD;AACrE,QAAA,MAAM,EAAE,QAAQ;KACjB;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;AAaD,UAAA,CAAA;AAPC,IAAA,KAAK,CAAC;AACL,QAAA,IAAI,EAAE,QAAQ;AACd,QAAA,KAAK,EAAE,OAAO;AACd,QAAA,KAAK,EAAE,UAAU;AACjB,QAAA,WAAW,EAAE,6CAA6C;AAC1D,QAAA,MAAM,EAAE,MAAM;KACf;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@combos-fun/plugin-sound",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"description": "Audio playback",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-sound.esm.js",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"author": "sun668 <q947692259@gmail.com>",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"eventemitter3": "^5.0.4",
|
|
41
|
-
"@combos-fun/engine": "0.0.
|
|
41
|
+
"@combos-fun/engine": "0.0.34",
|
|
42
|
+
"@combos-fun/inspector-decorator": "0.0.34"
|
|
42
43
|
},
|
|
43
44
|
"scripts": {
|
|
44
45
|
"build": "node ../../scripts/build-package.mjs"
|