@ -0,0 +1,13 @@
|
|||||||
|
// ignore_for_file: public_member_api_docs
|
||||||
|
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:pinball_audio/pinball_audio.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
class RolloverNoiseBehavior extends ContactBehavior {
|
||||||
|
@override
|
||||||
|
void beginContact(Object other, Contact contact) {
|
||||||
|
super.beginContact(other, contact);
|
||||||
|
readProvider<PinballAudioPlayer>().play(PinballAudio.rollover);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
export 'google_word_animating_behavior.dart';
|
@ -0,0 +1,24 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_bloc/flame_bloc.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
class GoogleWordAnimatingBehavior extends TimerComponent
|
||||||
|
with FlameBlocReader<GoogleWordCubit, GoogleWordState> {
|
||||||
|
GoogleWordAnimatingBehavior() : super(period: 0.35, repeat: true);
|
||||||
|
|
||||||
|
final _maxBlinks = 7;
|
||||||
|
int _blinks = 0;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onTick() {
|
||||||
|
super.onTick();
|
||||||
|
if (_blinks != _maxBlinks * 2) {
|
||||||
|
bloc.switched();
|
||||||
|
_blinks++;
|
||||||
|
} else {
|
||||||
|
timer.stop();
|
||||||
|
bloc.onAnimationFinished();
|
||||||
|
shouldRemove = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame_bloc/flame_bloc.dart';
|
||||||
|
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_components/pinball_components.dart';
|
||||||
|
|
||||||
|
class _TestGame extends Forge2DGame {
|
||||||
|
Future<void> pump(
|
||||||
|
GoogleWordAnimatingBehavior child, {
|
||||||
|
required GoogleWordCubit bloc,
|
||||||
|
}) async {
|
||||||
|
await ensureAdd(
|
||||||
|
FlameBlocProvider<GoogleWordCubit, GoogleWordState>.value(
|
||||||
|
value: bloc,
|
||||||
|
children: [child],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MockGoogleWordCubit extends Mock implements GoogleWordCubit {}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final flameTester = FlameTester(_TestGame.new);
|
||||||
|
|
||||||
|
group('GoogleWordAnimatingBehavior', () {
|
||||||
|
flameTester.testGameWidget(
|
||||||
|
'calls switched after timer period reached',
|
||||||
|
setUp: (game, tester) async {
|
||||||
|
final behavior = GoogleWordAnimatingBehavior();
|
||||||
|
final bloc = _MockGoogleWordCubit();
|
||||||
|
await game.pump(behavior, bloc: bloc);
|
||||||
|
game.update(behavior.timer.limit);
|
||||||
|
|
||||||
|
verify(bloc.switched).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.testGameWidget(
|
||||||
|
'calls onAnimationFinished and removes itself '
|
||||||
|
'after all blinks complete',
|
||||||
|
setUp: (game, tester) async {
|
||||||
|
final behavior = GoogleWordAnimatingBehavior();
|
||||||
|
final bloc = _MockGoogleWordCubit();
|
||||||
|
|
||||||
|
await game.pump(behavior, bloc: bloc);
|
||||||
|
for (var i = 0; i <= 14; i++) {
|
||||||
|
game.update(behavior.timer.limit);
|
||||||
|
}
|
||||||
|
await game.ready();
|
||||||
|
|
||||||
|
verify(bloc.onAnimationFinished).called(1);
|
||||||
|
expect(
|
||||||
|
game.descendants().whereType<GoogleWordAnimatingBehavior>().isEmpty,
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
Before Width: | Height: | Size: 650 KiB After Width: | Height: | Size: 360 KiB |
Before Width: | Height: | Size: 662 KiB After Width: | Height: | Size: 363 KiB |
Before Width: | Height: | Size: 654 KiB After Width: | Height: | Size: 372 KiB |
Before Width: | Height: | Size: 663 KiB After Width: | Height: | Size: 366 KiB |
@ -0,0 +1,58 @@
|
|||||||
|
// 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('RolloverNoiseBehavior', () {
|
||||||
|
late PinballAudioPlayer audioPlayer;
|
||||||
|
final flameTester = FlameTester(_TestGame.new);
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
audioPlayer = _MockPinballAudioPlayer();
|
||||||
|
});
|
||||||
|
flameTester.testGameWidget(
|
||||||
|
'plays rollover sound on contact',
|
||||||
|
setUp: (game, _) async {
|
||||||
|
final behavior = RolloverNoiseBehavior();
|
||||||
|
final parent = _TestBodyComponent();
|
||||||
|
await game.pump(parent, audioPlayer: audioPlayer);
|
||||||
|
await parent.ensureAdd(behavior);
|
||||||
|
behavior.beginContact(Object(), _MockContact());
|
||||||
|
},
|
||||||
|
verify: (_, __) async {
|
||||||
|
verify(() => audioPlayer.play(PinballAudio.rollover)).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|