@@ -5,6 +5,21 @@ David Quesenberry
55AsteroidsAudio.js
66*/
77import { GaplessLoopPlayer , HtmlAudioMediaBackend , MediaTrackService } from '../../../src/engine/audio/index.js' ;
8+ import { resolveWorkspaceGameAssetPath } from '../../shared/workspaceGameAssetCatalog.js' ;
9+
10+ const ASTEROIDS_GAME_ID = "Asteroids" ;
11+ const ASTEROIDS_AUDIO_ASSET_IDS = Object . freeze ( {
12+ fire : "audio.asteroids.fire" ,
13+ bangLarge : "audio.asteroids.bang-large" ,
14+ bangMedium : "audio.asteroids.bang-medium" ,
15+ bangSmall : "audio.asteroids.bang-small" ,
16+ beat1 : "audio.asteroids.beat-1" ,
17+ beat2 : "audio.asteroids.beat-2" ,
18+ extraShip : "audio.asteroids.extra-ship" ,
19+ thrust : "audio.asteroids.thrust" ,
20+ saucerLarge : "audio.asteroids.saucer-large" ,
21+ saucerSmall : "audio.asteroids.saucer-small"
22+ } ) ;
823
924export default class AsteroidsAudio {
1025 constructor ( ) {
@@ -17,21 +32,36 @@ export default class AsteroidsAudio {
1732 this . activeUfoTrack = null ;
1833 }
1934
35+ resolveAudioPath ( assetId ) {
36+ return resolveWorkspaceGameAssetPath ( ASTEROIDS_GAME_ID , assetId ) ;
37+ }
38+
2039 ensureInitialized ( ) {
2140 if ( this . initialized ) {
2241 return ;
2342 }
2443
25- this . media . register ( 'fire' , { src : '/games/Asteroids/assets/audio/fire.wav' , volume : 0.55 } ) ;
26- this . media . register ( 'bangLarge' , { src : '/games/Asteroids/assets/audio/bangLarge.wav' , volume : 0.65 } ) ;
27- this . media . register ( 'bangMedium' , { src : '/games/Asteroids/assets/audio/bangMedium.wav' , volume : 0.6 } ) ;
28- this . media . register ( 'bangSmall' , { src : '/games/Asteroids/assets/audio/bangSmall.wav' , volume : 0.55 } ) ;
29- this . media . register ( 'beat1' , { src : '/games/Asteroids/assets/audio/beat1.wav' , volume : 0.45 } ) ;
30- this . media . register ( 'beat2' , { src : '/games/Asteroids/assets/audio/beat2.wav' , volume : 0.45 } ) ;
31- this . loopPlayer . register ( 'extraShip' , { src : '/games/Asteroids/assets/audio/extraShip.wav' , volume : 0.6 , overlapSeconds : 0.035 , fadeSeconds : 0.012 } ) ;
32- this . loopPlayer . register ( 'thrust' , { src : '/games/Asteroids/assets/audio/thrust.wav' , volume : 0.35 , overlapSeconds : 0.03 , fadeSeconds : 0.01 } ) ;
33- this . loopPlayer . register ( 'saucerLarge' , { src : '/games/Asteroids/assets/audio/saucerBig.wav' , volume : 0.35 , overlapSeconds : 0.03 , fadeSeconds : 0.01 } ) ;
34- this . loopPlayer . register ( 'saucerSmall' , { src : '/games/Asteroids/assets/audio/saucerSmall.wav' , volume : 0.4 , overlapSeconds : 0.03 , fadeSeconds : 0.01 } ) ;
44+ const firePath = this . resolveAudioPath ( ASTEROIDS_AUDIO_ASSET_IDS . fire ) ;
45+ const bangLargePath = this . resolveAudioPath ( ASTEROIDS_AUDIO_ASSET_IDS . bangLarge ) ;
46+ const bangMediumPath = this . resolveAudioPath ( ASTEROIDS_AUDIO_ASSET_IDS . bangMedium ) ;
47+ const bangSmallPath = this . resolveAudioPath ( ASTEROIDS_AUDIO_ASSET_IDS . bangSmall ) ;
48+ const beat1Path = this . resolveAudioPath ( ASTEROIDS_AUDIO_ASSET_IDS . beat1 ) ;
49+ const beat2Path = this . resolveAudioPath ( ASTEROIDS_AUDIO_ASSET_IDS . beat2 ) ;
50+ const extraShipPath = this . resolveAudioPath ( ASTEROIDS_AUDIO_ASSET_IDS . extraShip ) ;
51+ const thrustPath = this . resolveAudioPath ( ASTEROIDS_AUDIO_ASSET_IDS . thrust ) ;
52+ const saucerLargePath = this . resolveAudioPath ( ASTEROIDS_AUDIO_ASSET_IDS . saucerLarge ) ;
53+ const saucerSmallPath = this . resolveAudioPath ( ASTEROIDS_AUDIO_ASSET_IDS . saucerSmall ) ;
54+
55+ if ( firePath ) this . media . register ( 'fire' , { src : firePath , volume : 0.55 } ) ;
56+ if ( bangLargePath ) this . media . register ( 'bangLarge' , { src : bangLargePath , volume : 0.65 } ) ;
57+ if ( bangMediumPath ) this . media . register ( 'bangMedium' , { src : bangMediumPath , volume : 0.6 } ) ;
58+ if ( bangSmallPath ) this . media . register ( 'bangSmall' , { src : bangSmallPath , volume : 0.55 } ) ;
59+ if ( beat1Path ) this . media . register ( 'beat1' , { src : beat1Path , volume : 0.45 } ) ;
60+ if ( beat2Path ) this . media . register ( 'beat2' , { src : beat2Path , volume : 0.45 } ) ;
61+ if ( extraShipPath ) this . loopPlayer . register ( 'extraShip' , { src : extraShipPath , volume : 0.6 , overlapSeconds : 0.035 , fadeSeconds : 0.012 } ) ;
62+ if ( thrustPath ) this . loopPlayer . register ( 'thrust' , { src : thrustPath , volume : 0.35 , overlapSeconds : 0.03 , fadeSeconds : 0.01 } ) ;
63+ if ( saucerLargePath ) this . loopPlayer . register ( 'saucerLarge' , { src : saucerLargePath , volume : 0.35 , overlapSeconds : 0.03 , fadeSeconds : 0.01 } ) ;
64+ if ( saucerSmallPath ) this . loopPlayer . register ( 'saucerSmall' , { src : saucerSmallPath , volume : 0.4 , overlapSeconds : 0.03 , fadeSeconds : 0.01 } ) ;
3565 this . initialized = true ;
3666 }
3767
0 commit comments