diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 653e8c37..5f6fbbdc 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -163,7 +163,6 @@ class _GameBallsController extends ComponentController } } -// coverage:ignore-start class DebugPinballGame extends PinballGame with FPSCounter, PanDetector { DebugPinballGame({ required CharacterTheme characterTheme, @@ -181,7 +180,7 @@ class DebugPinballGame extends PinballGame with FPSCounter, PanDetector { @override Future onLoad() async { await super.onLoad(); - await add(_PreviewLine()); + await add(PreviewLine()); await add(_DebugInformation()); } @@ -211,23 +210,22 @@ class DebugPinballGame extends PinballGame with FPSCounter, PanDetector { void onPanEnd(DragEndInfo info) { if (lineEnd != null) { final line = lineEnd! - lineStart!; - onLine(line); + _turboChargeBall(line); lineEnd = null; lineStart = null; } } - void onLine(Vector2 line) { + void _turboChargeBall(Vector2 line) { final ball = ControlledBall.debug()..initialPosition = lineStart!; final impulse = line * -1 * 10; ball.add(BallTurboChargingBehavior(impulse: impulse)); firstChild()?.add(ball); } } -// coverage:ignore-end // coverage:ignore-start -class _PreviewLine extends PositionComponent with HasGameRef { +class PreviewLine extends PositionComponent with HasGameRef { static final _previewLinePaint = Paint() ..color = Colors.pink ..strokeWidth = 0.4 @@ -246,10 +244,8 @@ class _PreviewLine extends PositionComponent with HasGameRef { } } } -// coverage:ignore-end // TODO(wolfenrain): investigate this CI failure. -// coverage:ignore-start class _DebugInformation extends Component with HasGameRef { @override PositionType get positionType => PositionType.widget; diff --git a/test/game/pinball_game_test.dart b/test/game/pinball_game_test.dart index f61e647d..5fed979f 100644 --- a/test/game/pinball_game_test.dart +++ b/test/game/pinball_game_test.dart @@ -25,6 +25,12 @@ class _MockTapUpDetails extends Mock implements TapUpDetails {} class _MockTapUpInfo extends Mock implements TapUpInfo {} +class _MockDragStartInfo extends Mock implements DragStartInfo {} + +class _MockDragUpdateInfo extends Mock implements DragUpdateInfo {} + +class _MockDragEndInfo extends Mock implements DragEndInfo {} + void main() { TestWidgetsFlutterBinding.ensureInitialized(); final assets = [ @@ -469,5 +475,68 @@ void main() { ); }, ); + + debugModeFlameTester.test( + 'set lineStart on pan start', + (game) async { + final startPosition = Vector2.all(10); + final eventPosition = _MockEventPosition(); + when(() => eventPosition.game).thenReturn(startPosition); + + final dragStartInfo = _MockDragStartInfo(); + when(() => dragStartInfo.eventPosition).thenReturn(eventPosition); + + game.onPanStart(dragStartInfo); + await game.ready(); + + expect( + game.lineStart, + equals(startPosition), + ); + }, + ); + + debugModeFlameTester.test( + 'set lineEnd on pan update', + (game) async { + final endPosition = Vector2.all(10); + final eventPosition = _MockEventPosition(); + when(() => eventPosition.game).thenReturn(endPosition); + + final dragUpdateInfo = _MockDragUpdateInfo(); + when(() => dragUpdateInfo.eventPosition).thenReturn(eventPosition); + + game.onPanUpdate(dragUpdateInfo); + await game.ready(); + + expect( + game.lineEnd, + equals(endPosition), + ); + }, + ); + + debugModeFlameTester.test( + 'launch ball on pan end', + (game) async { + final startPosition = Vector2.zero(); + final endPosition = Vector2.all(10); + + game.lineStart = startPosition; + game.lineEnd = endPosition; + + await game.ready(); + final previousBalls = + game.descendants().whereType().toList(); + + game.onPanEnd(_MockDragEndInfo()); + await game.ready(); + + expect( + game.descendants().whereType().length, + equals(previousBalls.length + 1), + ); + }, + ); }); }