mirror of https://github.com/flutter/pinball.git
refactor: moved noise logic to `BumperNoisyBehavior` (#326)
parent
44566bcbf0
commit
f38f18d60a
@ -0,0 +1,2 @@
|
||||
export 'bumper_noisy_behavior.dart';
|
||||
export 'scoring_behavior.dart';
|
@ -0,0 +1,14 @@
|
||||
// ignore_for_file: public_member_api_docs
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||
import 'package:pinball/game/pinball_game.dart';
|
||||
import 'package:pinball_flame/pinball_flame.dart';
|
||||
|
||||
class BumperNoisyBehavior extends ContactBehavior with HasGameRef<PinballGame> {
|
||||
@override
|
||||
void beginContact(Object other, Contact contact) {
|
||||
super.beginContact(other, contact);
|
||||
gameRef.audio.bumper();
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
// 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 '../../helpers/helpers.dart';
|
||||
|
||||
class _TestBodyComponent extends BodyComponent {
|
||||
@override
|
||||
Body createBody() {
|
||||
return world.createBody(BodyDef());
|
||||
}
|
||||
}
|
||||
|
||||
class _MockPinballAudio extends Mock implements PinballAudio {}
|
||||
|
||||
class _MockContact extends Mock implements Contact {}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('BumperNoisyBehavior', () {});
|
||||
|
||||
late PinballAudio audio;
|
||||
final flameTester = FlameTester(
|
||||
() => EmptyPinballTestGame(audio: audio),
|
||||
);
|
||||
|
||||
setUp(() {
|
||||
audio = _MockPinballAudio();
|
||||
});
|
||||
|
||||
flameTester.testGameWidget(
|
||||
'plays bumper sound',
|
||||
setUp: (game, _) async {
|
||||
final behavior = BumperNoisyBehavior();
|
||||
final parent = _TestBodyComponent();
|
||||
await game.ensureAdd(parent);
|
||||
await parent.ensureAdd(behavior);
|
||||
behavior.beginContact(Object(), _MockContact());
|
||||
},
|
||||
verify: (_, __) async {
|
||||
verify(audio.bumper).called(1);
|
||||
},
|
||||
);
|
||||
}
|
Loading…
Reference in new issue