From 069809a440433514518791ba22584eadf9eb764e Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Wed, 4 May 2022 12:34:16 +0200 Subject: [PATCH] refactor: changed name for RampBallAscendingContactBehavior --- .../spaceship_ramp/behavior/behavior.dart | 2 +- ...ramp_ball_ascending_contact_behavior.dart} | 13 ++++---- .../cubit/spaceship_ramp_cubit.dart | 2 +- .../spaceship_ramp/spaceship_ramp.dart | 6 ++-- .../android_acres/spaceship_ramp_game.dart | 2 +- ...ball_ascending_contact_behavior_test.dart} | 18 +++++------ .../cubit/spaceship_ramp_cubit_test.dart | 8 ++--- .../spaceship_ramp/spaceship_ramp_test.dart | 30 +++++++++---------- 8 files changed, 41 insertions(+), 40 deletions(-) rename packages/pinball_components/lib/src/components/spaceship_ramp/behavior/{ramp_ball_contact_behavior.dart => ramp_ball_ascending_contact_behavior.dart} (53%) rename packages/pinball_components/test/src/components/spaceship_ramp/behavior/{ramp_ball_contact_behavior_test.dart => ramp_ball_ascending_contact_behavior_test.dart} (85%) diff --git a/packages/pinball_components/lib/src/components/spaceship_ramp/behavior/behavior.dart b/packages/pinball_components/lib/src/components/spaceship_ramp/behavior/behavior.dart index 19ab2d4b..1f9b6284 100644 --- a/packages/pinball_components/lib/src/components/spaceship_ramp/behavior/behavior.dart +++ b/packages/pinball_components/lib/src/components/spaceship_ramp/behavior/behavior.dart @@ -1 +1 @@ -export 'ramp_ball_contact_behavior.dart'; +export 'ramp_ball_ascending_contact_behavior.dart'; diff --git a/packages/pinball_components/lib/src/components/spaceship_ramp/behavior/ramp_ball_contact_behavior.dart b/packages/pinball_components/lib/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior.dart similarity index 53% rename from packages/pinball_components/lib/src/components/spaceship_ramp/behavior/ramp_ball_contact_behavior.dart rename to packages/pinball_components/lib/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior.dart index 329a83ac..2d0aad7c 100644 --- a/packages/pinball_components/lib/src/components/spaceship_ramp/behavior/ramp_ball_contact_behavior.dart +++ b/packages/pinball_components/lib/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior.dart @@ -4,20 +4,21 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_flame/pinball_flame.dart'; -/// {@template ramp_ball_contact_behavior} -/// Detects a [Ball]that enters in the [SpaceshipRamp]. +/// {@template ramp_ball_ascending_contact_behavior} +/// Detects an ascending [Ball] that enters into the [SpaceshipRamp]. /// -/// The [Ball] can hit with sensor to recognize if [Ball] goes in or out the -/// [SpaceshipRamp]. +/// The [Ball] can hit with sensor to recognize if a [Ball] goes into or out of +/// the [SpaceshipRamp]. /// {@endtemplate} -class RampBallContactBehavior extends ContactBehavior { +class RampBallAscendingContactBehavior + extends ContactBehavior { @override void beginContact(Object other, Contact contact) { super.beginContact(other, contact); if (other is! Ball) return; if (other.body.linearVelocity.y < 0) { - parent.parent.bloc.onBallInside(); + parent.parent.bloc.onAscendingBallEntered(); } } } diff --git a/packages/pinball_components/lib/src/components/spaceship_ramp/cubit/spaceship_ramp_cubit.dart b/packages/pinball_components/lib/src/components/spaceship_ramp/cubit/spaceship_ramp_cubit.dart index a9172416..d27a7a2c 100644 --- a/packages/pinball_components/lib/src/components/spaceship_ramp/cubit/spaceship_ramp_cubit.dart +++ b/packages/pinball_components/lib/src/components/spaceship_ramp/cubit/spaceship_ramp_cubit.dart @@ -8,7 +8,7 @@ part 'spaceship_ramp_state.dart'; class SpaceshipRampCubit extends Cubit { SpaceshipRampCubit() : super(const SpaceshipRampState.initial()); - void onBallInside() { + void onAscendingBallEntered() { emit( state.copyWith(hits: state.hits + 1), ); diff --git a/packages/pinball_components/lib/src/components/spaceship_ramp/spaceship_ramp.dart b/packages/pinball_components/lib/src/components/spaceship_ramp/spaceship_ramp.dart index 3ee380a3..0b407517 100644 --- a/packages/pinball_components/lib/src/components/spaceship_ramp/spaceship_ramp.dart +++ b/packages/pinball_components/lib/src/components/spaceship_ramp/spaceship_ramp.dart @@ -27,11 +27,11 @@ class SpaceshipRamp extends Component { required this.bloc, }) : super( children: [ - // TODO(ruimiguel): refactor RampSensor and RampOpening to be in - // only one sensor. + // TODO(ruimiguel): refactor RampScoringSensor and + // _SpaceshipRampOpening to be in only one sensor if possible. RampScoringSensor( children: [ - RampBallContactBehavior(), + RampBallAscendingContactBehavior(), ], )..initialPosition = Vector2(1.7, -20.4), _SpaceshipRampOpening( diff --git a/packages/pinball_components/sandbox/lib/stories/android_acres/spaceship_ramp_game.dart b/packages/pinball_components/sandbox/lib/stories/android_acres/spaceship_ramp_game.dart index e9af32a6..3446670a 100644 --- a/packages/pinball_components/sandbox/lib/stories/android_acres/spaceship_ramp_game.dart +++ b/packages/pinball_components/sandbox/lib/stories/android_acres/spaceship_ramp_game.dart @@ -54,7 +54,7 @@ class SpaceshipRampGame extends BallGame with KeyboardEvents { ) { if (event is RawKeyDownEvent && event.logicalKey == LogicalKeyboardKey.space) { - _spaceshipRamp.bloc.onBallInside(); + _spaceshipRamp.bloc.onAscendingBallEntered(); return KeyEventResult.handled; } diff --git a/packages/pinball_components/test/src/components/spaceship_ramp/behavior/ramp_ball_contact_behavior_test.dart b/packages/pinball_components/test/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior_test.dart similarity index 85% rename from packages/pinball_components/test/src/components/spaceship_ramp/behavior/ramp_ball_contact_behavior_test.dart rename to packages/pinball_components/test/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior_test.dart index a78455ab..ea37550a 100644 --- a/packages/pinball_components/test/src/components/spaceship_ramp/behavior/ramp_ball_contact_behavior_test.dart +++ b/packages/pinball_components/test/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior_test.dart @@ -36,12 +36,12 @@ void main() { final flameTester = FlameTester(() => TestGame(assets)); group( - 'RampBallContactBehavior', + 'RampBallAscendingContactBehavior', () { test('can be instantiated', () { expect( - RampBallContactBehavior(), - isA(), + RampBallAscendingContactBehavior(), + isA(), ); }); @@ -57,9 +57,9 @@ void main() { }); flameTester.test( - "calls 'onBallInside' when a ball enters into the ramp", + "calls 'onAscendingBallEntered' when a ball enters into the ramp", (game) async { - final behavior = RampBallContactBehavior(); + final behavior = RampBallAscendingContactBehavior(); final bloc = _MockSpaceshipRampCubit(); whenListen( bloc, @@ -80,14 +80,14 @@ void main() { behavior.beginContact(ball, _MockContact()); - verify(bloc.onBallInside).called(1); + verify(bloc.onAscendingBallEntered).called(1); }, ); flameTester.test( - "doesn't call 'onBallInside' when a ball goes out the ramp", + "doesn't call 'onAscendingBallEntered' when a ball goes out the ramp", (game) async { - final behavior = RampBallContactBehavior(); + final behavior = RampBallAscendingContactBehavior(); final bloc = _MockSpaceshipRampCubit(); whenListen( bloc, @@ -108,7 +108,7 @@ void main() { behavior.beginContact(ball, _MockContact()); - verifyNever(bloc.onBallInside); + verifyNever(bloc.onAscendingBallEntered); }, ); }); diff --git a/packages/pinball_components/test/src/components/spaceship_ramp/cubit/spaceship_ramp_cubit_test.dart b/packages/pinball_components/test/src/components/spaceship_ramp/cubit/spaceship_ramp_cubit_test.dart index e0c9dd61..b7e899fe 100644 --- a/packages/pinball_components/test/src/components/spaceship_ramp/cubit/spaceship_ramp_cubit_test.dart +++ b/packages/pinball_components/test/src/components/spaceship_ramp/cubit/spaceship_ramp_cubit_test.dart @@ -6,14 +6,14 @@ import 'package:pinball_components/pinball_components.dart'; void main() { group('SpaceshipRampCubit', () { - group('onBallInside', () { + group('onAscendingBallEntered', () { blocTest( 'emits hits incremented and arrow goes to the next value', build: SpaceshipRampCubit.new, act: (bloc) => bloc - ..onBallInside() - ..onBallInside() - ..onBallInside(), + ..onAscendingBallEntered() + ..onAscendingBallEntered() + ..onAscendingBallEntered(), expect: () => [ SpaceshipRampState(hits: 1), SpaceshipRampState(hits: 2), diff --git a/packages/pinball_components/test/src/components/spaceship_ramp/spaceship_ramp_test.dart b/packages/pinball_components/test/src/components/spaceship_ramp/spaceship_ramp_test.dart index 08cd9b49..b74cfb88 100644 --- a/packages/pinball_components/test/src/components/spaceship_ramp/spaceship_ramp_test.dart +++ b/packages/pinball_components/test/src/components/spaceship_ramp/spaceship_ramp_test.dart @@ -79,7 +79,7 @@ void main() { final canvas = ZCanvasComponent(children: [ramp]); await game.ensureAdd(canvas); - ramp.bloc.onBallInside(); + ramp.bloc.onAscendingBallEntered(); await game.ready(); await tester.pump(); @@ -112,8 +112,8 @@ void main() { await game.ensureAdd(canvas); ramp.bloc - ..onBallInside() - ..onBallInside(); + ..onAscendingBallEntered() + ..onAscendingBallEntered(); await game.ready(); await tester.pump(); @@ -146,9 +146,9 @@ void main() { await game.ensureAdd(canvas); ramp.bloc - ..onBallInside() - ..onBallInside() - ..onBallInside(); + ..onAscendingBallEntered() + ..onAscendingBallEntered() + ..onAscendingBallEntered(); await game.ready(); await tester.pump(); @@ -181,10 +181,10 @@ void main() { await game.ensureAdd(canvas); ramp.bloc - ..onBallInside() - ..onBallInside() - ..onBallInside() - ..onBallInside(); + ..onAscendingBallEntered() + ..onAscendingBallEntered() + ..onAscendingBallEntered() + ..onAscendingBallEntered(); await game.ready(); await tester.pump(); @@ -217,11 +217,11 @@ void main() { await game.ensureAdd(canvas); ramp.bloc - ..onBallInside() - ..onBallInside() - ..onBallInside() - ..onBallInside() - ..onBallInside(); + ..onAscendingBallEntered() + ..onAscendingBallEntered() + ..onAscendingBallEntered() + ..onAscendingBallEntered() + ..onAscendingBallEntered(); await game.ready(); await tester.pump();