diff --git a/lib/game/components/game_bloc_status_listener.dart b/lib/game/components/game_bloc_status_listener.dart index 1984a523..c0ddf6c0 100644 --- a/lib/game/components/game_bloc_status_listener.dart +++ b/lib/game/components/game_bloc_status_listener.dart @@ -22,6 +22,7 @@ class GameBlocStatusListener extends Component gameRef.overlays.remove(PinballGame.playButtonOverlay); break; case GameStatus.gameOver: + gameRef.player.play(PinballAudio.gameOverVoiceOver); gameRef.descendants().whereType().first.requestInitials( score: state.displayScore, character: gameRef.characterTheme, diff --git a/packages/pinball_audio/assets/sfx/game_over_voice_over.mp3 b/packages/pinball_audio/assets/sfx/game_over_voice_over.mp3 new file mode 100644 index 00000000..2f2ae590 Binary files /dev/null and b/packages/pinball_audio/assets/sfx/game_over_voice_over.mp3 differ diff --git a/packages/pinball_audio/lib/gen/assets.gen.dart b/packages/pinball_audio/lib/gen/assets.gen.dart index 5bb8fea8..2bace523 100644 --- a/packages/pinball_audio/lib/gen/assets.gen.dart +++ b/packages/pinball_audio/lib/gen/assets.gen.dart @@ -16,6 +16,7 @@ class $AssetsSfxGen { String get bumperA => 'assets/sfx/bumper_a.mp3'; String get bumperB => 'assets/sfx/bumper_b.mp3'; + String get gameOverVoiceOver => 'assets/sfx/game_over_voice_over.mp3'; String get google => 'assets/sfx/google.mp3'; String get ioPinballVoiceOver => 'assets/sfx/io_pinball_voice_over.mp3'; } diff --git a/packages/pinball_audio/lib/src/pinball_audio.dart b/packages/pinball_audio/lib/src/pinball_audio.dart index a859a86f..dd3e8242 100644 --- a/packages/pinball_audio/lib/src/pinball_audio.dart +++ b/packages/pinball_audio/lib/src/pinball_audio.dart @@ -18,7 +18,10 @@ enum PinballAudio { backgroundMusic, /// IO Pinball voice over - ioPinballVoiceOver + ioPinballVoiceOver, + + /// Game over + gameOverVoiceOver, } /// Defines the contract of the creation of an [AudioPool]. @@ -30,20 +33,16 @@ typedef CreateAudioPool = Future Function( String? prefix, }); -/// Function that defines the contract for playing a single -/// audio +/// Defines the contract for playing a single audio. typedef PlaySingleAudio = Future Function(String); -/// Function that defines the contract for looping a single -/// audio +/// Defines the contract for looping a single audio. typedef LoopSingleAudio = Future Function(String); -/// Function that defines the contract for pre fetching an -/// audio +/// Defines the contract for pre fetching an audio. typedef PreCacheSingleAudio = Future Function(String); -/// Function that defines the contract for configuring -/// an [AudioCache] instance +/// Defines the contract for configuring an [AudioCache] instance. typedef ConfigureAudioCache = void Function(AudioCache); abstract class _Audio { @@ -164,6 +163,11 @@ class PinballPlayer { playSingleAudio: _playSingleAudio, path: Assets.sfx.ioPinballVoiceOver, ), + PinballAudio.gameOverVoiceOver: _SimplePlayAudio( + preCacheSingleAudio: _preCacheSingleAudio, + playSingleAudio: _playSingleAudio, + path: Assets.sfx.gameOverVoiceOver, + ), PinballAudio.bumper: _BumperAudio( createAudioPool: _createAudioPool, seed: _seed, diff --git a/packages/pinball_audio/test/src/pinball_audio_test.dart b/packages/pinball_audio/test/src/pinball_audio_test.dart index 8740cda0..b7760aa5 100644 --- a/packages/pinball_audio/test/src/pinball_audio_test.dart +++ b/packages/pinball_audio/test/src/pinball_audio_test.dart @@ -146,6 +146,11 @@ void main() { 'packages/pinball_audio/assets/sfx/io_pinball_voice_over.mp3', ), ).called(1); + verify( + () => preCacheSingleAudio.onCall( + 'packages/pinball_audio/assets/sfx/game_over_voice_over.mp3', + ), + ).called(1); verify( () => preCacheSingleAudio .onCall('packages/pinball_audio/assets/music/background.mp3'), @@ -227,6 +232,19 @@ void main() { }); }); + group('gameOverVoiceOver', () { + test('plays the correct file', () async { + await Future.wait(player.load()); + player.play(PinballAudio.gameOverVoiceOver); + + verify( + () => playSingleAudio.onCall( + 'packages/pinball_audio/${Assets.sfx.gameOverVoiceOver}', + ), + ).called(1); + }); + }); + group('backgroundMusic', () { test('plays the correct file', () async { await Future.wait(player.load()); diff --git a/test/game/components/game_bloc_status_listener_test.dart b/test/game/components/game_bloc_status_listener_test.dart index 4bb313e6..a614a2e2 100644 --- a/test/game/components/game_bloc_status_listener_test.dart +++ b/test/game/components/game_bloc_status_listener_test.dart @@ -128,6 +128,18 @@ void main() { .called(1); }, ); + + test( + 'plays the game over voice over when it is game over', + () { + gameFlowController.onNewState( + GameState.initial().copyWith(status: GameStatus.gameOver), + ); + + verify(() => pinballPlayer.play(PinballAudio.gameOverVoiceOver)) + .called(1); + }, + ); }); }); }