feat: adding start screen sfx (#308)

* feat: adding start screen sfx

* fix: lint

* fix: lint

* feat: PR suggestions

* fix: lint

* Apply suggestions from code review

Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>

Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
pull/316/head
Erick 3 years ago committed by GitHub
parent 58468bde2f
commit 62be5f636d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,8 +3,10 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/gen/gen.dart'; import 'package:pinball/gen/gen.dart';
import 'package:pinball/l10n/l10n.dart'; import 'package:pinball/l10n/l10n.dart';
import 'package:pinball_audio/pinball_audio.dart';
import 'package:pinball_ui/pinball_ui.dart'; import 'package:pinball_ui/pinball_ui.dart';
import 'package:platform_helper/platform_helper.dart'; import 'package:platform_helper/platform_helper.dart';
@ -50,10 +52,13 @@ extension on Control {
} }
Future<void> showHowToPlayDialog(BuildContext context) { Future<void> showHowToPlayDialog(BuildContext context) {
final audio = context.read<PinballAudio>();
return showDialog<void>( return showDialog<void>(
context: context, context: context,
builder: (_) => HowToPlayDialog(), builder: (_) => HowToPlayDialog(),
); ).then((_) {
audio.ioPinballVoiceOver();
});
} }
class HowToPlayDialog extends StatefulWidget { class HowToPlayDialog extends StatefulWidget {

@ -15,6 +15,7 @@ class $AssetsSfxGen {
const $AssetsSfxGen(); const $AssetsSfxGen();
String get google => 'assets/sfx/google.mp3'; String get google => 'assets/sfx/google.mp3';
String get ioPinballVoiceOver => 'assets/sfx/io_pinball_voice_over.mp3';
String get plim => 'assets/sfx/plim.mp3'; String get plim => 'assets/sfx/plim.mp3';
} }

@ -74,6 +74,7 @@ class PinballAudio {
await Future.wait([ await Future.wait([
_preCacheSingleAudio(_prefixFile(Assets.sfx.google)), _preCacheSingleAudio(_prefixFile(Assets.sfx.google)),
_preCacheSingleAudio(_prefixFile(Assets.sfx.ioPinballVoiceOver)),
_preCacheSingleAudio(_prefixFile(Assets.music.background)), _preCacheSingleAudio(_prefixFile(Assets.music.background)),
]); ]);
} }
@ -88,6 +89,11 @@ class PinballAudio {
_playSingleAudio(_prefixFile(Assets.sfx.google)); _playSingleAudio(_prefixFile(Assets.sfx.google));
} }
/// Plays the I/O Pinball voice over audio.
void ioPinballVoiceOver() {
_playSingleAudio(_prefixFile(Assets.sfx.ioPinballVoiceOver));
}
/// Plays the background music /// Plays the background music
void backgroundMusic() { void backgroundMusic() {
_loopSingleAudio(_prefixFile(Assets.music.background)); _loopSingleAudio(_prefixFile(Assets.music.background));

@ -125,6 +125,11 @@ void main() {
() => preCacheSingleAudio () => preCacheSingleAudio
.onCall('packages/pinball_audio/assets/sfx/google.mp3'), .onCall('packages/pinball_audio/assets/sfx/google.mp3'),
).called(1); ).called(1);
verify(
() => preCacheSingleAudio.onCall(
'packages/pinball_audio/assets/sfx/io_pinball_voice_over.mp3',
),
).called(1);
verify( verify(
() => preCacheSingleAudio () => preCacheSingleAudio
.onCall('packages/pinball_audio/assets/music/background.mp3'), .onCall('packages/pinball_audio/assets/music/background.mp3'),
@ -163,6 +168,19 @@ void main() {
}); });
}); });
group('ioPinballVoiceOver', () {
test('plays the correct file', () async {
await audio.load();
audio.ioPinballVoiceOver();
verify(
() => playSingleAudio.onCall(
'packages/pinball_audio/${Assets.sfx.ioPinballVoiceOver}',
),
).called(1);
});
});
group('backgroundMusic', () { group('backgroundMusic', () {
test('plays the correct file', () async { test('plays the correct file', () async {
await audio.load(); await audio.load();

@ -3,10 +3,13 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:pinball/how_to_play/how_to_play.dart'; import 'package:pinball/how_to_play/how_to_play.dart';
import 'package:pinball/l10n/l10n.dart'; import 'package:pinball/l10n/l10n.dart';
import 'package:pinball_audio/pinball_audio.dart';
import 'package:platform_helper/platform_helper.dart'; import 'package:platform_helper/platform_helper.dart';
import '../helpers/helpers.dart'; import '../helpers/helpers.dart';
class _MockPinballAudio extends Mock implements PinballAudio {}
class _MockPlatformHelper extends Mock implements PlatformHelper {} class _MockPlatformHelper extends Mock implements PlatformHelper {}
void main() { void main() {
@ -93,5 +96,30 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byType(HowToPlayDialog), findsNothing); expect(find.byType(HowToPlayDialog), findsNothing);
}); });
testWidgets(
'plays the I/O Pinball voice over audio on dismiss',
(tester) async {
final audio = _MockPinballAudio();
await tester.pumpApp(
Builder(
builder: (context) {
return TextButton(
onPressed: () => showHowToPlayDialog(context),
child: const Text('test'),
);
},
),
pinballAudio: audio,
);
expect(find.byType(HowToPlayDialog), findsNothing);
await tester.tap(find.text('test'));
await tester.pumpAndSettle();
await tester.tapAt(Offset.zero);
await tester.pumpAndSettle();
verify(audio.ioPinballVoiceOver).called(1);
},
);
}); });
} }

Loading…
Cancel
Save