diff --git a/doc/flame/inputs/gesture_input.md b/doc/flame/inputs/gesture_input.md index fd3db730e0e..00131ed5e30 100644 --- a/doc/flame/inputs/gesture_input.md +++ b/doc/flame/inputs/gesture_input.md @@ -24,33 +24,6 @@ Detectors will be deprecated in the future. Prefer `Callbacks` instead. ``` ```text -- TapDetector - - onTap - - onTapCancel - - onTapDown - - onLongTapDown - - onTapUp - -- SecondaryTapDetector - - onSecondaryTapDown - - onSecondaryTapUp - - onSecondaryTapCancel - -- TertiaryTapDetector - - onTertiaryTapDown - - onTertiaryTapUp - - onTertiaryTapCancel - -- DoubleTapDetector - - onDoubleTap - -- LongPressDetector - - onLongPress - - onLongPressStart - - onLongPressMoveUpdate - - onLongPressUp - - onLongPressEnd - - VerticalDragDetector - onVerticalDragDown - onVerticalDragStart @@ -209,23 +182,25 @@ The position where the event occurred relative to the `GameWidget` position and ## Example ```dart -class MyGame extends FlameGame with TapDetector { +class MyGame extends FlameGame with MultiTouchTapDetector { // Other methods omitted @override - bool onTapDown(TapDownInfo info) { - print("Player tap down on ${info.eventPosition.widget}"); - return true; + void onTapDown(int pointerId, TapDownInfo info) { + print('Player tap down on ${info.eventPosition.widget}'); } @override - bool onTapUp(TapUpInfo info) { - print("Player tap up on ${info.eventPosition.widget}"); - return true; + void onTapUp(int pointerId, TapUpInfo info) { + print('Player tap up on ${info.eventPosition.widget}'); } } ``` +Note that there is no single-pointer tap detector at the game level; for that, use the component +level [`TapCallbacks`](tap_events.md) instead, which `FlameGame` can mix in directly since it is +itself a `Component`. + You can also check more complete examples in the [input examples directory](https://github.com/flame-engine/flame/tree/main/examples/lib/stories/input/). diff --git a/doc/flame/migration.md b/doc/flame/migration.md index d145b5fe0e2..ba59dba2a89 100644 --- a/doc/flame/migration.md +++ b/doc/flame/migration.md @@ -7,6 +7,52 @@ major versions of Flame, together with the steps required to migrate your code. ## Migrating from v1.38.0 to v2.0.0 +### Deprecated tap and long press game detectors removed + +The game-level detector mixins that were deprecated in v1.38.0 have now been removed, together with +the event classes that only they used: + +| Removed | Use instead | +| --- | --- | +| `TapDetector` | `TapCallbacks` | +| `SecondaryTapDetector` | `SecondaryTapCallbacks` | +| `TertiaryTapDetector` | `TertiaryTapCallbacks` | +| `DoubleTapDetector` | `DoubleTapCallbacks` | +| `LongPressDetector` | `LongPressCallbacks` | +| `LongPressStartInfo` | `LongPressStartEvent` | +| `LongPressMoveUpdateInfo` | `LongPressMoveUpdateEvent` | +| `LongPressEndInfo` | `LongPressEndEvent` | + +The replacements are mixed into a component rather than into the game, and each callback takes a +single event object: + +```dart +// Before +class MyGame extends FlameGame with TapDetector { + @override + void onTapDown(TapDownInfo info) { + final position = info.eventPosition.widget; + } +} + +// After +class MyComponent extends PositionComponent with TapCallbacks { + @override + void onTapDown(TapDownEvent event) { + final position = event.localPosition; + } +} +``` + +Note that a component only receives events that occur on top of it, as determined by +`containsLocalPoint()`, whereas the old game-level detectors received every event on the game +surface. To keep the old whole-screen behavior, add the mixin to your `FlameGame` subclass directly +— `FlameGame` is itself a `Component`. + +See [Tap Events](inputs/tap_events.md) and [Long Press Events](inputs/long_press_events.md) for the +full replacement APIs. + + ### `onDragCancel` no longer delegates to `onDragEnd` `DragCallbacks.onDragCancel` used to convert the cancellation into an `onDragEnd` event by default, diff --git a/packages/flame/lib/events.dart b/packages/flame/lib/events.dart index 8ab167f20cb..b9cc484ad71 100644 --- a/packages/flame/lib/events.dart +++ b/packages/flame/lib/events.dart @@ -80,16 +80,12 @@ export 'src/game/mixins/keyboard.dart' show HasKeyboardHandlerComponents, KeyboardEvents; export 'src/gestures/detectors.dart' show - DoubleTapDetector, ForcePressDetector, HorizontalDragDetector, - LongPressDetector, MouseMovementDetector, PanDetector, ScaleDetector, ScrollDetector, - TertiaryTapDetector, - SecondaryTapDetector, VerticalDragDetector; export 'src/gestures/events.dart' show @@ -98,9 +94,6 @@ export 'src/gestures/events.dart' DragStartInfo, DragUpdateInfo, ForcePressInfo, - LongPressEndInfo, - LongPressMoveUpdateInfo, - LongPressStartInfo, PointerHoverInfo, PointerScrollInfo, PositionInfo, diff --git a/packages/flame/lib/src/game/flame_game.dart b/packages/flame/lib/src/game/flame_game.dart index dd5eecba7d5..0a36de8f196 100644 --- a/packages/flame/lib/src/game/flame_game.dart +++ b/packages/flame/lib/src/game/flame_game.dart @@ -245,15 +245,9 @@ class FlameGame extends ComponentTreeRoot @override bool containsEventHandlerAt(Vector2 position) { - // Deprecated game-level detector mixins handle events for the entire - // game surface, so any in-bounds point is a hit. - // ignore: deprecated_member_use_from_same_package - if (this is TapDetector || - this is SecondaryTapDetector || - this is TertiaryTapDetector || - this is DoubleTapDetector || - this is LongPressDetector || - this is VerticalDragDetector || + // Game-level detector mixins handle events for the entire game surface, + // so any in-bounds point is a hit. + if (this is VerticalDragDetector || this is HorizontalDragDetector || this is ForcePressDetector || this is PanDetector || diff --git a/packages/flame/lib/src/game/game_widget/gesture_detector_builder.dart b/packages/flame/lib/src/game/game_widget/gesture_detector_builder.dart index 4699abe1337..877a1b9d19e 100644 --- a/packages/flame/lib/src/game/game_widget/gesture_detector_builder.dart +++ b/packages/flame/lib/src/game/game_widget/gesture_detector_builder.dart @@ -1,5 +1,4 @@ import 'package:flame/events.dart'; -import 'package:flame/input.dart'; import 'package:flame/src/game/game.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/widgets.dart'; @@ -45,58 +44,6 @@ class GestureDetectorBuilder { } void initializeGestures(Game game) { - // support for deprecated detectors - // ignore: deprecated_member_use_from_same_package - if (game is TapDetector || - game is SecondaryTapDetector || - game is TertiaryTapDetector) { - register( - TapGestureRecognizer.new, - (TapGestureRecognizer instance) { - // support for deprecated detectors - // ignore: deprecated_member_use_from_same_package - if (game is TapDetector) { - instance.onTap = game.onTap; - instance.onTapCancel = game.onTapCancel; - instance.onTapUp = game.handleTapUp; - instance.onTapDown = game.handleTapDown; - } - if (game is SecondaryTapDetector) { - instance.onSecondaryTapCancel = game.onSecondaryTapCancel; - instance.onSecondaryTapUp = game.handleSecondaryTapUp; - instance.onSecondaryTapDown = game.handleSecondaryTapDown; - } - if (game is TertiaryTapDetector) { - instance.onTertiaryTapCancel = game.onTertiaryTapCancel; - instance.onTertiaryTapUp = game.handleTertiaryTapUp; - instance.onTertiaryTapDown = game.handleTertiaryTapDown; - } - }, - ); - } - if (game is DoubleTapDetector) { - register( - DoubleTapGestureRecognizer.new, - (DoubleTapGestureRecognizer instance) { - instance.onDoubleTap = game.onDoubleTap; - instance.onDoubleTapDown = game.handleDoubleTapDown; - instance.onDoubleTapCancel = game.onDoubleTapCancel; - }, - ); - } - if (game is LongPressDetector) { - register( - LongPressGestureRecognizer.new, - (LongPressGestureRecognizer instance) { - instance.onLongPress = game.onLongPress; - instance.onLongPressStart = game.handleLongPressStart; - instance.onLongPressMoveUpdate = game.handleLongPressMoveUpdate; - instance.onLongPressEnd = game.handleLongPressEnd; - instance.onLongPressUp = game.onLongPressUp; - instance.onLongPressCancel = game.onLongPressCancel; - }, - ); - } if (game is VerticalDragDetector) { register( VerticalDragGestureRecognizer.new, diff --git a/packages/flame/lib/src/gestures/detectors.dart b/packages/flame/lib/src/gestures/detectors.dart index 352c60d93bf..5e5e30f05a3 100644 --- a/packages/flame/lib/src/gestures/detectors.dart +++ b/packages/flame/lib/src/gestures/detectors.dart @@ -2,85 +2,6 @@ import 'package:flame/src/game/game.dart'; import 'package:flame/src/gestures/events.dart'; import 'package:flutter/gestures.dart'; -@Deprecated('Use TapCallbacks instead') -mixin TapDetector on Game { - void onTap() {} - void onTapCancel() {} - void onTapDown(TapDownInfo info) {} - void onTapUp(TapUpInfo info) {} - - void handleTapUp(TapUpDetails details) { - onTapUp(TapUpInfo.fromDetails(this, details)); - } - - void handleTapDown(TapDownDetails details) { - onTapDown(TapDownInfo.fromDetails(this, details)); - } -} - -@Deprecated('Use SecondaryTapCallbacks instead') -mixin SecondaryTapDetector on Game { - void onSecondaryTapDown(TapDownInfo info) {} - void onSecondaryTapUp(TapUpInfo info) {} - void onSecondaryTapCancel() {} - - void handleSecondaryTapUp(TapUpDetails details) { - onSecondaryTapUp(TapUpInfo.fromDetails(this, details)); - } - - void handleSecondaryTapDown(TapDownDetails details) { - onSecondaryTapDown(TapDownInfo.fromDetails(this, details)); - } -} - -@Deprecated('Use TertiaryTapCallbacks instead') -mixin TertiaryTapDetector on Game { - void onTertiaryTapDown(TapDownInfo info) {} - void onTertiaryTapUp(TapUpInfo info) {} - void onTertiaryTapCancel() {} - - void handleTertiaryTapUp(TapUpDetails details) { - onTertiaryTapUp(TapUpInfo.fromDetails(this, details)); - } - - void handleTertiaryTapDown(TapDownDetails details) { - onTertiaryTapDown(TapDownInfo.fromDetails(this, details)); - } -} - -@Deprecated('Use DoubleTapCallbacks instead') -mixin DoubleTapDetector on Game { - void onDoubleTap() {} - void onDoubleTapCancel() {} - void onDoubleTapDown(TapDownInfo info) {} - - void handleDoubleTapDown(TapDownDetails details) { - onDoubleTapDown(TapDownInfo.fromDetails(this, details)); - } -} - -@Deprecated('Use LongPressCallbacks instead') -mixin LongPressDetector on Game { - void onLongPress() {} - void onLongPressStart(LongPressStartInfo info) {} - void onLongPressMoveUpdate(LongPressMoveUpdateInfo info) {} - void onLongPressUp() {} - void onLongPressEnd(LongPressEndInfo info) {} - void onLongPressCancel() {} - - void handleLongPressStart(LongPressStartDetails details) { - onLongPressStart(LongPressStartInfo.fromDetails(this, details)); - } - - void handleLongPressMoveUpdate(LongPressMoveUpdateDetails details) { - onLongPressMoveUpdate(LongPressMoveUpdateInfo.fromDetails(this, details)); - } - - void handleLongPressEnd(LongPressEndDetails details) { - onLongPressEnd(LongPressEndInfo.fromDetails(this, details)); - } -} - mixin VerticalDragDetector on Game { void onVerticalDragDown(DragDownInfo info) {} void onVerticalDragStart(DragStartInfo info) {} diff --git a/packages/flame/lib/src/gestures/events.dart b/packages/flame/lib/src/gestures/events.dart index f7b6c5ed66f..c511fb5421e 100644 --- a/packages/flame/lib/src/gestures/events.dart +++ b/packages/flame/lib/src/gestures/events.dart @@ -75,29 +75,6 @@ class TapUpInfo extends PositionInfo { ) : super(game, raw.globalPosition, raw); } -class LongPressStartInfo extends PositionInfo { - LongPressStartInfo.fromDetails( - Game game, - LongPressStartDetails raw, - ) : super(game, raw.globalPosition, raw); -} - -class LongPressEndInfo extends PositionInfo { - late final Vector2 velocity = raw.velocity.pixelsPerSecond.toVector2(); - - LongPressEndInfo.fromDetails( - Game game, - LongPressEndDetails raw, - ) : super(game, raw.globalPosition, raw); -} - -class LongPressMoveUpdateInfo extends PositionInfo { - LongPressMoveUpdateInfo.fromDetails( - Game game, - LongPressMoveUpdateDetails raw, - ) : super(game, raw.globalPosition, raw); -} - class ForcePressInfo extends PositionInfo { late final double pressure = raw.pressure; diff --git a/packages/flame/test/game/game_widget/game_widget_tap_test.dart b/packages/flame/test/game/game_widget/game_widget_tap_test.dart deleted file mode 100644 index f1c7da5fbe4..00000000000 --- a/packages/flame/test/game/game_widget/game_widget_tap_test.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'package:flame/events.dart'; -import 'package:flame/extensions.dart'; -import 'package:flame/game.dart'; -import 'package:flame/input.dart'; -import 'package:flame_test/flame_test.dart'; -import 'package:flutter_test/flutter_test.dart'; - -// testing the deprecated TapDetector -// ignore: deprecated_member_use_from_same_package -class _TapGame extends FlameGame with TapDetector { - bool tapRegistered = false; - - @override - void onTap() { - tapRegistered = true; - } -} - -class _DoubleTapGame extends FlameGame with DoubleTapDetector { - bool doubleTapRegistered = false; - Vector2? doubleTapPosition; - - @override - void onDoubleTap() { - doubleTapRegistered = true; - } - - @override - void onDoubleTapDown(TapDownInfo info) { - doubleTapPosition = info.eventPosition.global; - } -} - -void main() { - final tapGame = FlameTester(_TapGame.new); - final doubleTapGame = FlameTester(_DoubleTapGame.new); - - group('GameWidget - TapDetectors', () { - tapGame.testGameWidget( - 'can receive taps', - verify: (game, tester) async { - await tester.tapAt(const Offset(10, 10)); - expect(game.tapRegistered, isTrue); - }, - ); - - const tapPosition = Offset(10, 10); - doubleTapGame.testGameWidget( - 'can receive double taps', - setUp: (game, tester) async { - await tester.tapAt(tapPosition); - await Future.delayed(const Duration(milliseconds: 50)); - await tester.tapAt(tapPosition); - }, - verify: (game, tester) async { - expect(game.doubleTapRegistered, isTrue); - final tapVector = tapPosition.toVector2(); - expect(game.doubleTapPosition, closeToVector(tapVector)); - }, - ); - }); -} diff --git a/packages/flame/test/gestures/detectors_test.dart b/packages/flame/test/gestures/detectors_test.dart index 93808c5c048..3e9aae0ba5f 100644 --- a/packages/flame/test/gestures/detectors_test.dart +++ b/packages/flame/test/gestures/detectors_test.dart @@ -1,6 +1,5 @@ import 'package:flame/events.dart' hide PointerMoveEvent; import 'package:flame/game.dart'; -import 'package:flame/input.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -22,7 +21,7 @@ void main() { group('MultiTouchTapDetector', () { testWidgets( - 'Game can have both MultiTouchTapDetector and DoubleTapDetector', + 'Game can have both MultiTouchTapDetector and DoubleTapCallbacks', (tester) async { await tester.pumpWidget( GameWidget( @@ -34,332 +33,6 @@ void main() { ); }); - group('TapDetector', () { - final tapGame = FlameTester(_TapDetectorGame.new); - - testWithGame<_TapDetectorGame>( - 'can be Tapped Down', - _TapDetectorGame.new, - (game) async { - await game.ready(); - - game.handleTapDown(TapDownDetails()); - - expect(game.hasOnTapDown, isTrue); - }, - ); - - testWithGame<_TapDetectorGame>( - 'can be Tapped Up', - _TapDetectorGame.new, - (game) async { - await game.ready(); - - game.handleTapUp(TapUpDetails(kind: PointerDeviceKind.touch)); - - expect(game.hasOnTapUp, isTrue); - }, - ); - - tapGame.testGameWidget( - 'can receive taps', - verify: (game, tester) async { - await tester.tapAt(const Offset(10, 10)); - expect(game.tapRegistered, isTrue); - }, - ); - - tapGame.testGameWidget( - 'can receive tapDown', - verify: (game, tester) async { - await tester.startGesture(const Offset(10, 10)); - expect(game.hasOnTapDown, isTrue); - expect(game.hasOnTapUp, isFalse); - }, - ); - - tapGame.testGameWidget( - 'can receive tapCancel', - verify: (game, tester) async { - await tester.dragFrom(const Offset(10, 10), const Offset(20, 10)); - expect(game.hasOnTapDown, isTrue); - expect(game.hasOnTapCancel, isTrue); - }, - ); - }); - - group('SecondaryTapDetector', () { - final secondaryTapGame = FlameTester(_SecondaryTapDetectorGame.new); - - secondaryTapGame.testGameWidget( - 'can receive secondary taps', - verify: (game, tester) async { - await tester.tapAt(const Offset(10, 10), buttons: kSecondaryButton); - - expect(game.hasOnSecondaryTapDown, isTrue); - expect(game.hasOnSecondaryTapUp, isTrue); - }, - ); - - secondaryTapGame.testGameWidget( - 'can receive secondaryTapDown', - verify: (game, tester) async { - await tester.startGesture( - const Offset(10, 10), - buttons: kSecondaryButton, - ); - expect(game.hasOnSecondaryTapDown, isTrue); - expect(game.hasOnSecondaryTapUp, isFalse); - }, - ); - - secondaryTapGame.testGameWidget( - 'can receive secondaryTapCancel', - verify: (game, tester) async { - await tester.dragFrom( - const Offset(10, 10), - const Offset(20, 20), - buttons: kSecondaryButton, - ); - expect(game.hasOnSecondaryTapDown, isTrue); - expect(game.hasOnSecondaryTapCancel, isTrue); - }, - ); - - testWithGame<_SecondaryTapDetectorGame>( - 'can be Secondary Tapped Down', - _SecondaryTapDetectorGame.new, - (game) async { - await game.ready(); - - game.handleSecondaryTapDown(TapDownDetails()); - - expect(game.hasOnSecondaryTapDown, isTrue); - }, - ); - - testWithGame<_SecondaryTapDetectorGame>( - 'can be Secondary Tapped Up', - _SecondaryTapDetectorGame.new, - (game) async { - await game.ready(); - - game.handleSecondaryTapUp(TapUpDetails(kind: PointerDeviceKind.touch)); - - expect(game.hasOnSecondaryTapUp, isTrue); - }, - ); - - testWithGame<_SecondaryTapDetectorGame>( - 'can be Secondary Tapped Canceled', - _SecondaryTapDetectorGame.new, - (game) async { - await game.ready(); - - game.handleSecondaryTapDown(TapDownDetails()); - game.onSecondaryTapCancel(); - - expect(game.hasOnSecondaryTapCancel, isTrue); - }, - ); - }); - - group('TertiaryTapDetector', () { - final tertiaryTapGame = FlameTester(_TertiaryTapDetectorGame.new); - - tertiaryTapGame.testGameWidget( - 'can receive tertiary taps', - verify: (game, tester) async { - await tester.tapAt(const Offset(10, 10), buttons: kTertiaryButton); - - expect(game.hasOnTertiaryTapDown, isTrue); - expect(game.hasOnTertiaryTapUp, isTrue); - }, - ); - - tertiaryTapGame.testGameWidget( - 'can receive tertiaryTapDown', - verify: (game, tester) async { - await tester.startGesture( - const Offset(10, 10), - buttons: kTertiaryButton, - ); - expect(game.hasOnTertiaryTapDown, isTrue); - expect(game.hasOnTertiaryTapUp, isFalse); - }, - ); - - tertiaryTapGame.testGameWidget( - 'can receive tertiaryTapCancel', - verify: (game, tester) async { - await tester.dragFrom( - const Offset(10, 10), - const Offset(20, 20), - buttons: kTertiaryButton, - ); - expect(game.hasOnTertiaryTapDown, isTrue); - expect(game.hasOnTertiaryTapCancel, isTrue); - }, - ); - - testWithGame<_TertiaryTapDetectorGame>( - 'can be Secondary Tapped Down', - _TertiaryTapDetectorGame.new, - (game) async { - await game.ready(); - - game.handleTertiaryTapDown(TapDownDetails()); - - expect(game.hasOnTertiaryTapDown, isTrue); - }, - ); - - testWithGame<_TertiaryTapDetectorGame>( - 'can be Secondary Tapped Up', - _TertiaryTapDetectorGame.new, - (game) async { - await game.ready(); - - game.handleTertiaryTapUp(TapUpDetails(kind: PointerDeviceKind.touch)); - - expect(game.hasOnTertiaryTapUp, isTrue); - }, - ); - }); - - group('DoubleTapDetector', () { - final doubleTapGame = FlameTester(_DoubleTapDetectorGame.new); - - doubleTapGame.testGameWidget( - 'can receive double taps', - setUp: (game, tester) async { - await tester.tapAt(const Offset(10, 10)); - await Future.delayed(kDoubleTapMinTime); - await tester.tapAt(const Offset(10, 10)); - }, - verify: (game, tester) async { - expect(game.hasOnDoubleTapDown, isTrue); - expect(game.doubleTapRegistered, isTrue); - }, - ); - - doubleTapGame.testGameWidget( - 'can receive double tapCancel', - setUp: (game, tester) async { - await tester.tapAt(const Offset(10, 10)); - await Future.delayed(kDoubleTapMinTime); - await tester.dragFrom( - const Offset(10, 10), - const Offset(20, 20), - ); - }, - verify: (game, tester) async { - expect(game.hasOnDoubleTapDown, isTrue); - expect(game.hasOnDoubleTapCancel, isTrue); - }, - ); - - testWithGame<_DoubleTapDetectorGame>( - 'can be Double Tapped Down', - _DoubleTapDetectorGame.new, - (game) async { - await game.ready(); - - game.handleDoubleTapDown(TapDownDetails()); - - expect(game.hasOnDoubleTapDown, isTrue); - }, - ); - }); - - group('LongPressDetector', () { - final longPressGame = FlameTester(_LongPressDetectorGame.new); - - longPressGame.testGameWidget( - 'can register longPress', - verify: (game, tester) async { - await tester.longPressAt(const Offset(10, 10)); - - expect(game.hasLongPressRegistered, isTrue); - }, - ); - - longPressGame.testGameWidget( - 'can register moving longPress', - setUp: (game, tester) async { - final gesture = await tester.startGesture( - const Offset(10, 10), - pointer: 7, - ); - - await Future.delayed(kLongPressTimeout); - - await gesture.moveTo(const Offset(20, 10)); - - await gesture.up(); - }, - verify: (game, tester) async { - expect(game.hasLongPressStarted, isTrue); - expect(game.hasLongPressMoveUpdated, isTrue); - expect(game.hasLongPressEnded, isTrue); - }, - ); - - longPressGame.testGameWidget( - 'can register longPressCancel', - setUp: (game, tester) async { - final gesture = await tester.startGesture( - const Offset(10, 10), - pointer: 7, - ); - - await gesture.moveTo(const Offset(20, 10)); - - await gesture.up(); - }, - verify: (game, tester) async { - expect(game.hasLongPressCanceled, isTrue); - expect(game.hasLongPressStarted, isFalse); - }, - ); - - testWithGame<_LongPressDetectorGame>( - 'can be Long Pressed Start', - _LongPressDetectorGame.new, - (game) async { - await game.ready(); - - game.handleLongPressStart(const LongPressStartDetails()); - - expect(game.hasLongPressStarted, isTrue); - }, - ); - - testWithGame<_LongPressDetectorGame>( - 'can be Long Pressed Move Update', - _LongPressDetectorGame.new, - (game) async { - await game.ready(); - - game.handleLongPressMoveUpdate(const LongPressMoveUpdateDetails()); - - expect(game.hasLongPressMoveUpdated, isTrue); - }, - ); - - testWithGame<_LongPressDetectorGame>( - 'can be Long Pressed Move End', - _LongPressDetectorGame.new, - (game) async { - await game.ready(); - - game.handleLongPressEnd(const LongPressEndDetails()); - - expect(game.hasLongPressEnded, isTrue); - }, - ); - }); - group('VerticalDragDetector', () { final verticalDragGame = FlameTester(_VerticalDragDetectorGame.new); @@ -778,134 +451,6 @@ void main() { }); } -// testing the deprecated TapDetector mixin -// ignore: deprecated_member_use_from_same_package -class _TapDetectorGame extends FlameGame with TapDetector { - bool hasOnTapUp = false; - bool hasOnTapDown = false; - bool hasOnTapCancel = false; - bool tapRegistered = false; - - @override - void onTap() { - tapRegistered = true; - } - - @override - void onTapUp(TapUpInfo info) { - hasOnTapUp = true; - } - - @override - void onTapDown(TapDownInfo info) { - hasOnTapDown = true; - } - - @override - void onTapCancel() { - hasOnTapCancel = true; - } -} - -class _SecondaryTapDetectorGame extends FlameGame with SecondaryTapDetector { - bool hasOnSecondaryTapUp = false; - bool hasOnSecondaryTapDown = false; - bool hasOnSecondaryTapCancel = false; - - @override - void onSecondaryTapDown(TapDownInfo info) { - hasOnSecondaryTapDown = true; - } - - @override - void onSecondaryTapUp(TapUpInfo info) { - hasOnSecondaryTapUp = true; - } - - @override - void onSecondaryTapCancel() { - hasOnSecondaryTapCancel = true; - } -} - -class _TertiaryTapDetectorGame extends FlameGame with TertiaryTapDetector { - bool hasOnTertiaryTapUp = false; - bool hasOnTertiaryTapDown = false; - bool hasOnTertiaryTapCancel = false; - - @override - void onTertiaryTapDown(TapDownInfo info) { - hasOnTertiaryTapDown = true; - } - - @override - void onTertiaryTapUp(TapUpInfo info) { - hasOnTertiaryTapUp = true; - } - - @override - void onTertiaryTapCancel() { - hasOnTertiaryTapCancel = true; - } -} - -class _DoubleTapDetectorGame extends FlameGame with DoubleTapDetector { - bool doubleTapRegistered = false; - bool hasOnDoubleTapDown = false; - bool hasOnDoubleTapCancel = false; - - @override - void onDoubleTap() { - doubleTapRegistered = true; - } - - @override - void onDoubleTapCancel() { - hasOnDoubleTapCancel = true; - } - - @override - void onDoubleTapDown(TapDownInfo info) { - hasOnDoubleTapDown = true; - } -} - -class _LongPressDetectorGame extends FlameGame with LongPressDetector { - bool hasLongPressRegistered = false; - bool hasLongPressCanceled = false; - bool hasLongPressEnded = false; - bool hasLongPressMoveUpdated = false; - bool hasLongPressStarted = false; - - @override - void onLongPress() { - hasLongPressRegistered = true; - } - - @override - void onLongPressCancel() { - hasLongPressCanceled = true; - } - - @override - void onLongPressEnd(LongPressEndInfo info) { - hasLongPressEnded = true; - } - - @override - void onLongPressUp() {} - - @override - void onLongPressMoveUpdate(LongPressMoveUpdateInfo info) { - hasLongPressMoveUpdated = true; - } - - @override - void onLongPressStart(LongPressStartInfo info) { - hasLongPressStarted = true; - } -} - class _HorizontalDragDetectorGame extends FlameGame with HorizontalDragDetector { bool hasHorizontalDragDown = false; @@ -1076,4 +621,4 @@ class _MultiDragPanGame extends FlameGame with MultiTouchDragDetector, PanDetector {} class _MultiTapDoubleTapGame extends FlameGame - with MultiTouchTapDetector, DoubleTapDetector {} + with MultiTouchTapDetector, DoubleTapCallbacks {}