From 8920689de45dc5334fc63b05dc53db66b69d187a Mon Sep 17 00:00:00 2001 From: Alejandro Santiago Date: Sat, 7 May 2022 21:45:46 +0100 Subject: [PATCH 1/2] refactor: removed RampScoringSensor (#395) --- .../ramp_ball_ascending_contact_behavior.dart | 2 +- .../spaceship_ramp/spaceship_ramp.dart | 64 ++++--------------- ..._ball_ascending_contact_behavior_test.dart | 12 ++-- .../spaceship_ramp/spaceship_ramp_test.dart | 26 ++++++++ 4 files changed, 45 insertions(+), 59 deletions(-) diff --git a/packages/pinball_components/lib/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior.dart b/packages/pinball_components/lib/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior.dart index 57895c45..db98a30a 100644 --- a/packages/pinball_components/lib/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior.dart +++ b/packages/pinball_components/lib/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior.dart @@ -9,7 +9,7 @@ import 'package:pinball_flame/pinball_flame.dart'; /// the [SpaceshipRamp]. /// {@endtemplate} class RampBallAscendingContactBehavior - extends ContactBehavior { + extends ContactBehavior { @override void beginContact(Object other, Contact contact) { super.beginContact(other, contact); 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 ea7ed2e7..07a5e79b 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,6 @@ class SpaceshipRamp extends Component { required this.bloc, }) : super( children: [ - RampScoringSensor( - children: [ - RampBallAscendingContactBehavior(), - ], - )..initialPosition = Vector2(1.7, -20.4), _SpaceshipRampOpening( outsideLayer: Layer.spaceship, outsidePriority: ZIndexes.ballOnSpaceship, @@ -40,7 +35,7 @@ class SpaceshipRamp extends Component { ..initialPosition = Vector2(-13.7, -18.6) ..layer = Layer.spaceshipEntranceRamp, _SpaceshipRampBackground(), - _SpaceshipRampBoardOpening()..initialPosition = Vector2(3.4, -39.5), + SpaceshipRampBoardOpening()..initialPosition = Vector2(3.4, -39.5), _SpaceshipRampForegroundRailing(), SpaceshipRampBase()..initialPosition = Vector2(3.4, -42.5), _SpaceshipRampBackgroundRailingSpriteComponent(), @@ -246,13 +241,14 @@ extension on SpaceshipRampArrowSpriteState { } } -class _SpaceshipRampBoardOpening extends BodyComponent - with Layered, ZIndex, InitialPosition { - _SpaceshipRampBoardOpening() +class SpaceshipRampBoardOpening extends BodyComponent + with Layered, ZIndex, InitialPosition, ParentIsA { + SpaceshipRampBoardOpening() : super( renderBody: false, children: [ _SpaceshipRampBoardOpeningSpriteComponent(), + RampBallAscendingContactBehavior()..applyTo(['inside']), LayerContactBehavior(layer: Layer.spaceshipEntranceRamp) ..applyTo(['inside']), LayerContactBehavior( @@ -271,6 +267,13 @@ class _SpaceshipRampBoardOpening extends BodyComponent layer = Layer.opening; } + /// Creates a [SpaceshipRampBoardOpening] without any children. + /// + /// This can be used for testing [SpaceshipRampBoardOpening]'s behaviors in + /// isolation. + @visibleForTesting + SpaceshipRampBoardOpening.test(); + List _createFixtureDefs() { final topEdge = EdgeShape() ..set( @@ -495,46 +498,3 @@ class _SpaceshipRampOpening extends LayerSensor { ); } } - -/// {@template ramp_scoring_sensor} -/// Small sensor body used to detect when a ball has entered the -/// [SpaceshipRamp]. -/// {@endtemplate} -class RampScoringSensor extends BodyComponent - with ParentIsA, InitialPosition, Layered { - /// {@macro ramp_scoring_sensor} - RampScoringSensor({ - Iterable? children, - }) : super( - children: children, - renderBody: false, - ) { - layer = Layer.spaceshipEntranceRamp; - } - - /// Creates a [RampScoringSensor] without any children. - @visibleForTesting - RampScoringSensor.test(); - - @override - Body createBody() { - final shape = PolygonShape() - ..setAsBox( - 2.6, - .5, - initialPosition, - -5 * math.pi / 180, - ); - - final fixtureDef = FixtureDef( - shape, - isSensor: true, - ); - final bodyDef = BodyDef( - position: initialPosition, - userData: this, - ); - - return world.createBody(bodyDef)..createFixture(fixtureDef); - } -} diff --git a/packages/pinball_components/test/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior_test.dart b/packages/pinball_components/test/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior_test.dart index ea37550a..d1f03ce7 100644 --- a/packages/pinball_components/test/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior_test.dart +++ b/packages/pinball_components/test/src/components/spaceship_ramp/behavior/ramp_ball_ascending_contact_behavior_test.dart @@ -67,16 +67,16 @@ void main() { initialState: const SpaceshipRampState.initial(), ); - final rampSensor = RampScoringSensor.test(); + final parent = SpaceshipRampBoardOpening.test(); final spaceshipRamp = SpaceshipRamp.test( bloc: bloc, ); when(() => body.linearVelocity).thenReturn(Vector2(0, -1)); - await spaceshipRamp.add(rampSensor); + await spaceshipRamp.add(parent); await game.ensureAddAll([spaceshipRamp, ball]); - await rampSensor.add(behavior); + await parent.add(behavior); behavior.beginContact(ball, _MockContact()); @@ -95,16 +95,16 @@ void main() { initialState: const SpaceshipRampState.initial(), ); - final rampSensor = RampScoringSensor.test(); + final parent = SpaceshipRampBoardOpening.test(); final spaceshipRamp = SpaceshipRamp.test( bloc: bloc, ); when(() => body.linearVelocity).thenReturn(Vector2(0, 1)); - await spaceshipRamp.add(rampSensor); + await spaceshipRamp.add(parent); await game.ensureAddAll([spaceshipRamp, ball]); - await rampSensor.add(behavior); + await parent.add(behavior); behavior.beginContact(ball, _MockContact()); 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 7bd18aeb..1c9c968d 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 @@ -7,6 +7,7 @@ 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'; +import 'package:pinball_components/src/components/spaceship_ramp/behavior/behavior.dart'; import 'package:pinball_flame/pinball_flame.dart'; import '../../../helpers/helpers.dart'; @@ -324,4 +325,29 @@ void main() { }, ); }); + + group('SpaceshipRampBoardOpening', () { + test('can be instantiated', () { + expect(SpaceshipRampBoardOpening(), isA()); + }); + + flameTester.test('can be loaded', (game) async { + final parent = SpaceshipRamp.test(bloc: _MockSpaceshipRampCubit()); + final component = SpaceshipRampBoardOpening(); + await game.ensureAdd(parent); + await parent.ensureAdd(component); + expect(parent.children, contains(component)); + }); + + flameTester.test('adds a RampBallAscendingContactBehavior', (game) async { + final parent = SpaceshipRamp.test(bloc: _MockSpaceshipRampCubit()); + final component = SpaceshipRampBoardOpening(); + await game.ensureAdd(parent); + await parent.ensureAdd(component); + expect( + component.children.whereType().length, + equals(1), + ); + }); + }); } From f517f7e4a3fbd08a7c35135ef9e34d1143eb5331 Mon Sep 17 00:00:00 2001 From: Jorge Coca Date: Sat, 7 May 2022 15:59:49 -0500 Subject: [PATCH 2/2] fix: more information dialog divider has fixed width (#397) --- lib/more_information/more_information_dialog.dart | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/more_information/more_information_dialog.dart b/lib/more_information/more_information_dialog.dart index 179c06f5..b9a9ddbb 100644 --- a/lib/more_information/more_information_dialog.dart +++ b/lib/more_information/more_information_dialog.dart @@ -55,8 +55,6 @@ class _LinkBoxHeader extends StatelessWidget { @override Widget build(BuildContext context) { final l10n = context.l10n; - final indent = MediaQuery.of(context).size.width / 5; - return Column( children: [ Text( @@ -68,11 +66,9 @@ class _LinkBoxHeader extends StatelessWidget { overflow: TextOverflow.ellipsis, ), const SizedBox(height: 12), - Divider( - color: PinballColors.white, - endIndent: indent, - indent: indent, - thickness: 2, + const SizedBox( + width: 200, + child: Divider(color: PinballColors.white, thickness: 2), ), ], );