Skip to content

Commit

Permalink
Fixes launch by touching rocket
Browse files Browse the repository at this point in the history
  • Loading branch information
astivi committed Jul 8, 2024
1 parent cf3b00c commit a35e668
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/game/pinball_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class PinballGame extends Forge2DGame
final bounds = rocket.topLeftPosition & rocket.size;

final tappedRocket =
bounds.contains(info.eventPosition.global.toOffset());
bounds.contains(screenToWorld(info.eventPosition.widget).toOffset());
if (tappedRocket) {
descendants()
.whereType<FlameBlocProvider<PlungerCubit, PlungerState>>()
Expand Down
4 changes: 3 additions & 1 deletion test/game/pinball_game_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,9 @@ void main() {
gameBloc.emit(gameBloc.state.copyWith(status: GameStatus.playing));

final eventPosition = _MockEventPosition();
when(() => eventPosition.global).thenReturn(Vector2(40, 60));
when(() => eventPosition.widget).thenReturn(
game.worldToScreen(Vector2(40, 60)),
);

final raw = _MockTapDownDetails();
when(() => raw.kind).thenReturn(PointerDeviceKind.touch);
Expand Down
33 changes: 21 additions & 12 deletions test/game/view/pinball_game_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,25 +301,31 @@ void main() {
expect(game.focusNode.hasFocus, isTrue);
});

testWidgets('mobile controls when the overlay is added', (tester) async {
await tester.pumpApp(
PinballGameView(game),
gameBloc: gameBloc,
startGameBloc: startGameBloc,
);
testWidgets(
'mobile controls when the overlay is added',
(tester) async {
await tester.pumpApp(
Material(child: PinballGameView(game)),
gameBloc: gameBloc,
startGameBloc: startGameBloc,
);

game.overlays.add(PinballGame.mobileControlsOverlay);
game.overlays.add(PinballGame.mobileControlsOverlay);

await tester.pump();
await tester.pump();

expect(find.byType(MobileControls), findsOneWidget);
});
expect(
game.overlays.isActive(PinballGame.mobileControlsOverlay),
isTrue,
);
},
);

testWidgets(
'ReplayButtonOverlay when the overlay is added',
(tester) async {
await tester.pumpApp(
PinballGameView(game),
Material(child: PinballGameView(game)),
gameBloc: gameBloc,
startGameBloc: startGameBloc,
);
Expand All @@ -328,7 +334,10 @@ void main() {

await tester.pump();

expect(find.byType(ReplayButtonOverlay), findsOneWidget);
expect(
game.overlays.isActive(PinballGame.replayButtonOverlay),
isTrue,
);
},
);

Expand Down

0 comments on commit a35e668

Please sign in to comment.