@ -0,0 +1,11 @@
|
||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||
import 'package:pinball_audio/pinball_audio.dart';
|
||||
import 'package:pinball_flame/pinball_flame.dart';
|
||||
|
||||
class KickerNoiseBehavior extends ContactBehavior {
|
||||
@override
|
||||
void beginContact(Object other, Contact contact) {
|
||||
super.beginContact(other, contact);
|
||||
readProvider<PinballAudioPlayer>().play(PinballAudio.kicker);
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 638 KiB After Width: | Height: | Size: 326 KiB |
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 996 B After Width: | Height: | Size: 715 B |
Before Width: | Height: | Size: 226 KiB After Width: | Height: | Size: 86 KiB |
Before Width: | Height: | Size: 646 KiB After Width: | Height: | Size: 326 KiB |
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 942 B |
Before Width: | Height: | Size: 150 KiB After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 654 KiB After Width: | Height: | Size: 347 KiB |
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 723 B After Width: | Height: | Size: 433 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 206 KiB After Width: | Height: | Size: 100 KiB |
Before Width: | Height: | Size: 660 KiB After Width: | Height: | Size: 331 KiB |
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 789 B After Width: | Height: | Size: 561 B |
@ -0,0 +1,59 @@
|
||||
// ignore_for_file: cascade_invocations
|
||||
|
||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||
import 'package:flame_test/flame_test.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:pinball/game/behaviors/behaviors.dart';
|
||||
import 'package:pinball_audio/pinball_audio.dart';
|
||||
import 'package:pinball_flame/pinball_flame.dart';
|
||||
|
||||
class _TestGame extends Forge2DGame {
|
||||
Future<void> pump(
|
||||
_TestBodyComponent child, {
|
||||
required PinballAudioPlayer audioPlayer,
|
||||
}) {
|
||||
return ensureAdd(
|
||||
FlameProvider<PinballAudioPlayer>.value(
|
||||
audioPlayer,
|
||||
children: [child],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TestBodyComponent extends BodyComponent {
|
||||
@override
|
||||
Body createBody() => world.createBody(BodyDef());
|
||||
}
|
||||
|
||||
class _MockPinballAudioPlayer extends Mock implements PinballAudioPlayer {}
|
||||
|
||||
class _MockContact extends Mock implements Contact {}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('KickerNoiseBehavior', () {
|
||||
late PinballAudioPlayer audioPlayer;
|
||||
final flameTester = FlameTester(_TestGame.new);
|
||||
|
||||
setUp(() {
|
||||
audioPlayer = _MockPinballAudioPlayer();
|
||||
});
|
||||
|
||||
flameTester.testGameWidget(
|
||||
'plays kicker sound',
|
||||
setUp: (game, _) async {
|
||||
final behavior = KickerNoiseBehavior();
|
||||
final parent = _TestBodyComponent();
|
||||
await game.pump(parent, audioPlayer: audioPlayer);
|
||||
await parent.ensureAdd(behavior);
|
||||
behavior.beginContact(Object(), _MockContact());
|
||||
},
|
||||
verify: (_, __) async {
|
||||
verify(() => audioPlayer.play(PinballAudio.kicker)).called(1);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|