|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
// ignore_for_file: prefer_const_constructors, one_member_abstracts
|
|
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
|
|
import 'package:audioplayers/audioplayers.dart';
|
|
|
|
|
import 'package:flame_audio/audio_pool.dart';
|
|
|
|
|
import 'package:flame_audio/flame_audio.dart';
|
|
|
|
@ -39,6 +41,8 @@ abstract class _PreCacheSingleAudio {
|
|
|
|
|
|
|
|
|
|
class _MockPreCacheSingleAudio extends Mock implements _PreCacheSingleAudio {}
|
|
|
|
|
|
|
|
|
|
class _MockRandom extends Mock implements Random {}
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
group('PinballAudio', () {
|
|
|
|
|
late _MockCreateAudioPool createAudioPool;
|
|
|
|
@ -46,6 +50,7 @@ void main() {
|
|
|
|
|
late _MockPlaySingleAudio playSingleAudio;
|
|
|
|
|
late _MockLoopSingleAudio loopSingleAudio;
|
|
|
|
|
late _PreCacheSingleAudio preCacheSingleAudio;
|
|
|
|
|
late Random seed;
|
|
|
|
|
late PinballAudio audio;
|
|
|
|
|
|
|
|
|
|
setUpAll(() {
|
|
|
|
@ -74,12 +79,15 @@ void main() {
|
|
|
|
|
preCacheSingleAudio = _MockPreCacheSingleAudio();
|
|
|
|
|
when(() => preCacheSingleAudio.onCall(any())).thenAnswer((_) async {});
|
|
|
|
|
|
|
|
|
|
seed = _MockRandom();
|
|
|
|
|
|
|
|
|
|
audio = PinballAudio(
|
|
|
|
|
configureAudioCache: configureAudioCache.onCall,
|
|
|
|
|
createAudioPool: createAudioPool.onCall,
|
|
|
|
|
playSingleAudio: playSingleAudio.onCall,
|
|
|
|
|
loopSingleAudio: loopSingleAudio.onCall,
|
|
|
|
|
preCacheSingleAudio: preCacheSingleAudio.onCall,
|
|
|
|
|
seed: seed,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -88,12 +96,20 @@ void main() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('load', () {
|
|
|
|
|
test('creates the score pool', () async {
|
|
|
|
|
test('creates the bumpers pools', () async {
|
|
|
|
|
await audio.load();
|
|
|
|
|
|
|
|
|
|
verify(
|
|
|
|
|
() => createAudioPool.onCall(
|
|
|
|
|
'packages/pinball_audio/${Assets.sfx.plim}',
|
|
|
|
|
'packages/pinball_audio/${Assets.sfx.bumperA}',
|
|
|
|
|
maxPlayers: 4,
|
|
|
|
|
prefix: '',
|
|
|
|
|
),
|
|
|
|
|
).called(1);
|
|
|
|
|
|
|
|
|
|
verify(
|
|
|
|
|
() => createAudioPool.onCall(
|
|
|
|
|
'packages/pinball_audio/${Assets.sfx.bumperB}',
|
|
|
|
|
maxPlayers: 4,
|
|
|
|
|
prefix: '',
|
|
|
|
|
),
|
|
|
|
@ -137,22 +153,52 @@ void main() {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('score', () {
|
|
|
|
|
test('plays the score sound pool', () async {
|
|
|
|
|
final audioPool = _MockAudioPool();
|
|
|
|
|
when(audioPool.start).thenAnswer((_) async => () {});
|
|
|
|
|
group('bumper', () {
|
|
|
|
|
late AudioPool bumperAPool;
|
|
|
|
|
late AudioPool bumperBPool;
|
|
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
|
bumperAPool = _MockAudioPool();
|
|
|
|
|
when(() => bumperAPool.start(volume: any(named: 'volume')))
|
|
|
|
|
.thenAnswer((_) async => () {});
|
|
|
|
|
when(
|
|
|
|
|
() => createAudioPool.onCall(
|
|
|
|
|
any(),
|
|
|
|
|
'packages/pinball_audio/${Assets.sfx.bumperA}',
|
|
|
|
|
maxPlayers: any(named: 'maxPlayers'),
|
|
|
|
|
prefix: any(named: 'prefix'),
|
|
|
|
|
),
|
|
|
|
|
).thenAnswer((_) async => audioPool);
|
|
|
|
|
).thenAnswer((_) async => bumperAPool);
|
|
|
|
|
|
|
|
|
|
bumperBPool = _MockAudioPool();
|
|
|
|
|
when(() => bumperBPool.start(volume: any(named: 'volume')))
|
|
|
|
|
.thenAnswer((_) async => () {});
|
|
|
|
|
when(
|
|
|
|
|
() => createAudioPool.onCall(
|
|
|
|
|
'packages/pinball_audio/${Assets.sfx.bumperB}',
|
|
|
|
|
maxPlayers: any(named: 'maxPlayers'),
|
|
|
|
|
prefix: any(named: 'prefix'),
|
|
|
|
|
),
|
|
|
|
|
).thenAnswer((_) async => bumperBPool);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('when seed is true', () {
|
|
|
|
|
test('plays the bumper A sound pool', () async {
|
|
|
|
|
when(seed.nextBool).thenReturn(true);
|
|
|
|
|
await audio.load();
|
|
|
|
|
audio.score();
|
|
|
|
|
audio.bumper();
|
|
|
|
|
|
|
|
|
|
verify(audioPool.start).called(1);
|
|
|
|
|
verify(() => bumperAPool.start(volume: 0.6)).called(1);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('when seed is false', () {
|
|
|
|
|
test('plays the bumper B sound pool', () async {
|
|
|
|
|
when(seed.nextBool).thenReturn(false);
|
|
|
|
|
await audio.load();
|
|
|
|
|
audio.bumper();
|
|
|
|
|
|
|
|
|
|
verify(() => bumperBPool.start(volume: 0.6)).called(1);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|