diff --git a/.markdownlint.yaml b/.markdownlint.yaml index 40033f22b2e..9bfa8e38344 100644 --- a/.markdownlint.yaml +++ b/.markdownlint.yaml @@ -201,7 +201,8 @@ MD044: html_elements: true # MD045/no-alt-text - Images should have alternate text (alt text) -MD045: true +# TODO: Activate this with #2913 +MD045: false # MD046/code-block-style - Code block style MD046: diff --git a/doc/flame/components.md b/doc/flame/components.md index 74b101e7e81..396a147b2d7 100644 --- a/doc/flame/components.md +++ b/doc/flame/components.md @@ -105,12 +105,12 @@ In the following example we first initialize the component with priority 1, and user taps the component we change its priority to 2: ```dart -class MyComponent extends PositionComponent with Tappable { +class MyComponent extends PositionComponent with TapCallbacks { MyComponent() : super(priority: 1); @override - void onTap() { + void onTapDown(TapDownEvent event) { priority = 2; } } @@ -818,8 +818,8 @@ robot.animationTickers?[RobotState.idle]?.onFrame = (currentIndex) { Example: ```dart -class ButtonComponent extends SpriteGroupComponent - with HasGameRef, Tappable { +class PlayerComponent extends SpriteGroupComponent + with HasGameReference, TapCallbacks { @override Future? onLoad() async { final pressedSprite = await gameRef.loadSprite(/* omitted */); diff --git a/doc/flame/examples/lib/collision_detection.dart b/doc/flame/examples/lib/collision_detection.dart index 17e2fbecf30..1a9c10911c9 100644 --- a/doc/flame/examples/lib/collision_detection.dart +++ b/doc/flame/examples/lib/collision_detection.dart @@ -3,7 +3,7 @@ import 'package:flame/collisions.dart'; import 'package:flame/components.dart'; import 'package:flame/effects.dart'; import 'package:flame/game.dart'; -import 'package:flutter/material.dart' hide Image, Draggable; +import 'package:flutter/material.dart' hide Image; class CollisionDetectionGame extends FlameGame with HasCollisionDetection { @override diff --git a/doc/flame/inputs/keyboard_input.md b/doc/flame/inputs/keyboard_input.md index b2c4bb87f9e..512fd06f8ca 100644 --- a/doc/flame/inputs/keyboard_input.md +++ b/doc/flame/inputs/keyboard_input.md @@ -76,7 +76,7 @@ class MyGame extends FlameGame with KeyboardEvents { To receive keyboard events directly in components, there is the mixin `KeyboardHandler`. -Similarly to `Tappable` and `Draggable`, `KeyboardHandler` can be mixed into any subclass of +Similarly to `TapCallbacks` and `DragCallbacks`, `KeyboardHandler` can be mixed into any subclass of `Component`. KeyboardHandlers must only be added to games that are mixed with `HasKeyboardHandlerComponents`. diff --git a/doc/flame/inputs/tap_events.md b/doc/flame/inputs/tap_events.md index a2fc7121833..2718d15cc51 100644 --- a/doc/flame/inputs/tap_events.md +++ b/doc/flame/inputs/tap_events.md @@ -58,7 +58,7 @@ Every component that received an `onTapDown` event will eventually receive eithe ### onLongTapDown If the user holds their finger down for some time (as configured by the `.longTapDelay` property -in `HasTappableComponents`), the "long tap" will be generated. This event invokes the +in `MultiTapDispatcher`), "long tap" will be triggered. This event invokes the `void onLongTapDown(TapDownEvent)` handler on those components that previously received the `onTapDown` event. diff --git a/examples/lib/stories/input/input.dart b/examples/lib/stories/input/input.dart index 9cc2528d98c..40e5b1016bb 100644 --- a/examples/lib/stories/input/input.dart +++ b/examples/lib/stories/input/input.dart @@ -23,7 +23,7 @@ import 'package:flutter/material.dart'; void addInputStories(Dashbook dashbook) { dashbook.storiesOf('Input') ..add( - 'Tappables', + 'TapCallbacks', (_) => GameWidget(game: TapCallbacksExample()), codeLink: baseLink('input/tap_callbacks_example.dart'), info: TapCallbacksExample.description, diff --git a/examples/lib/stories/input/tap_callbacks_example.dart b/examples/lib/stories/input/tap_callbacks_example.dart index f18412b500e..a076e587202 100644 --- a/examples/lib/stories/input/tap_callbacks_example.dart +++ b/examples/lib/stories/input/tap_callbacks_example.dart @@ -6,8 +6,8 @@ import 'package:flutter/material.dart'; class TapCallbacksExample extends FlameGame { static const String description = ''' - In this example we show the `Tappable` mixin functionality. You can add the - `Tappable` mixin to any `PositionComponent`.\n\n + In this example we show the `TapCallbacks` mixin functionality. You can add + the `TapCallbacks` mixin to any `PositionComponent`.\n\n Tap the squares to see them change their angle around their anchor. '''; diff --git a/packages/flame/lib/src/events/component_mixins/tap_callbacks.dart b/packages/flame/lib/src/events/component_mixins/tap_callbacks.dart index 3b4b6fcff86..0bb2479ade1 100644 --- a/packages/flame/lib/src/events/component_mixins/tap_callbacks.dart +++ b/packages/flame/lib/src/events/component_mixins/tap_callbacks.dart @@ -10,8 +10,6 @@ import 'package:meta/meta.dart'; /// In addition to adding this mixin, the component must also implement the /// [containsLocalPoint] method -- the component will only be considered /// "tapped" if the point where the tap has occurred is inside the component. -/// -/// This mixin is the replacement of the Tappable mixin. mixin TapCallbacks on Component { void onTapDown(TapDownEvent event) {} void onLongTapDown(TapDownEvent event) {} diff --git a/packages/flame/test/components/mixins/tappable_test.dart b/packages/flame/test/components/mixins/tappable_test.dart deleted file mode 100644 index 55219a83a21..00000000000 --- a/packages/flame/test/components/mixins/tappable_test.dart +++ /dev/null @@ -1,283 +0,0 @@ -import 'package:flame/components.dart'; -import 'package:flame/events.dart'; -import 'package:flame/game.dart'; -import 'package:flame/src/events/flame_game_mixins/multi_tap_dispatcher.dart'; -import 'package:flame_test/flame_test.dart'; -import 'package:flutter/gestures.dart'; -import 'package:test/test.dart'; - -void main() { - final withTappables = FlameTester(_GameHasTappables.new); - - group('Tappable', () { - testWithGame<_GameHasTappables>( - 'make sure they can be added to game with HasTappables', - _GameHasTappables.new, - (game) async { - await game.add(_TappableComponent()); - await game.ready(); - }, - ); - - testWithGame<_GameHasTappables>( - 'can be Tapped Down', - _GameHasTappables.new, - (game) async { - final component = _TappableComponent() - ..x = 10 - ..y = 10 - ..width = 10 - ..height = 10; - - await game.ensureAdd(component); - final tapDispatcher = game.firstChild()!; - - tapDispatcher.handleTapDown( - 1, - TapDownDetails( - kind: PointerDeviceKind.touch, - globalPosition: const Offset(10, 10), - localPosition: const Offset(10, 10), - ), - ); - - expect(component.hasOnTapDown, true); - }, - ); - - testWithGame<_GameHasTappables>( - 'can be Tapped Up', - _GameHasTappables.new, - (game) async { - final component = _TappableComponent() - ..x = 10 - ..y = 10 - ..width = 10 - ..height = 10; - - await game.ensureAdd(component); - final tapDispatcher = game.firstChild()!; - - tapDispatcher - ..handleTapDown( - 1, - TapDownDetails( - kind: PointerDeviceKind.touch, - globalPosition: const Offset(10, 10), - localPosition: const Offset(10, 10), - ), - ) - ..handleTapUp( - 1, - TapUpDetails( - kind: PointerDeviceKind.touch, - globalPosition: const Offset(10, 10), - localPosition: const Offset(10, 10), - ), - ); - - expect(component.hasOnTapUp, true); - }, - ); - - testWithGame<_GameHasTappables>( - 'can be Tapped Canceled', - _GameHasTappables.new, - (game) async { - final component = _TappableComponent() - ..x = 10 - ..y = 10 - ..width = 10 - ..height = 10; - - await game.ensureAdd(component); - final tapDispatcher = game.firstChild()!; - - tapDispatcher - ..handleTapDown( - 1, - TapDownDetails( - kind: PointerDeviceKind.touch, - globalPosition: const Offset(10, 10), - localPosition: const Offset(10, 10), - ), - ) - ..handleTapCancel( - 1, - ); - - expect(component.hasOnTapCancel, true); - }, - ); - - testWithGame<_GameHasTappables>( - 'can be Long Tapped Down', - _GameHasTappables.new, - (game) async { - final component = _TappableComponent() - ..x = 10 - ..y = 10 - ..width = 10 - ..height = 10; - - await game.ensureAdd(component); - final tapDispatcher = game.firstChild()!; - - tapDispatcher - ..handleTapDown( - 1, - TapDownDetails( - kind: PointerDeviceKind.touch, - globalPosition: const Offset(10, 10), - localPosition: const Offset(10, 10), - ), - ) - ..handleLongTapDown( - 1, - TapDownDetails( - kind: PointerDeviceKind.touch, - globalPosition: const Offset(10, 10), - localPosition: const Offset(10, 10), - ), - ); - - expect(component.hasOnLongTapDown, isTrue); - }, - ); - }); - - withTappables.testGameWidget( - 'tap correctly registered handled event', - setUp: (game, _) async { - final component = _TappableComponent() - ..x = 10 - ..y = 10 - ..width = 10 - ..height = 10; - - await game.ensureAdd(component); - }, - verify: (game, tester) async { - await tester.tapAt(const Offset(10, 10)); - await tester.pump(const Duration(seconds: 1)); - - expect(game.handledOnTapDown, equals(1)); - expect(game.handledOnLongTapDown, equals(0)); - expect(game.handledOnTapUp, equals(1)); - expect(game.handledOnTapCancel, equals(0)); - }, - ); - - withTappables.testGameWidget( - 'long tap correctly registered handled event', - setUp: (game, _) async { - final component = _TappableComponent() - ..x = 10 - ..y = 10 - ..width = 10 - ..height = 10; - - await game.ensureAdd(component); - }, - verify: (game, tester) async { - await tester.longPressAt(const Offset(10, 10)); - await tester.pump(const Duration(seconds: 1)); - expect(game.handledOnTapDown, equals(1)); - expect(game.handledOnLongTapDown, equals(1)); - expect(game.handledOnTapUp, equals(1)); - expect(game.handledOnTapCancel, equals(0)); - }, - ); - - withTappables.testGameWidget( - 'tap outside of component is not registered as handled', - setUp: (game, _) async { - final component = _TappableComponent() - ..x = 10 - ..y = 10 - ..width = 10 - ..height = 10; - - await game.ensureAdd(component); - }, - verify: (game, tester) async { - await tester.tapAt(const Offset(200, 200)); - await tester.pump(const Duration(seconds: 1)); - expect(game.handledOnTapDown, equals(0)); - expect(game.handledOnLongTapDown, equals(0)); - expect(game.handledOnTapUp, equals(0)); - expect(game.handledOnTapCancel, equals(0)); - }, - ); -} - -class _TappableComponent extends PositionComponent with TapCallbacks { - bool hasOnTapUp = false; - bool hasOnTapDown = false; - bool hasOnTapCancel = false; - bool hasOnLongTapDown = false; - - @override - void onTapDown(TapDownEvent info) { - info.handled = true; - info.continuePropagation = true; - hasOnTapDown = true; - } - - @override - void onTapUp(TapUpEvent info) { - info.handled = true; - info.continuePropagation = true; - hasOnTapUp = true; - } - - @override - void onTapCancel(TapCancelEvent info) { - info.continuePropagation = true; - hasOnTapCancel = true; - } - - @override - void onLongTapDown(TapDownEvent info) { - info.handled = true; - info.continuePropagation = true; - hasOnLongTapDown = true; - } -} - -class _GameHasTappables extends FlameGame with TapCallbacks { - int handledOnTapDown = 0; - int handledOnLongTapDown = 0; - int handledOnTapUp = 0; - int handledOnTapCancel = 0; - - @override - void onTapDown(TapDownEvent info) { - super.onTapDown(info); - if (info.handled) { - handledOnTapDown++; - } - } - - @override - void onLongTapDown(TapDownEvent info) { - super.onLongTapDown(info); - if (info.handled) { - handledOnLongTapDown++; - } - } - - @override - void onTapUp(TapUpEvent info) { - super.onTapUp(info); - if (info.handled) { - handledOnTapUp++; - } - } - - @override - void onTapCancel(_) { - super.onTapCancel(_); - handledOnTapCancel++; - } -} diff --git a/packages/flame_rive/test/flame_rive_test.dart b/packages/flame_rive/test/flame_rive_test.dart index 2ddf2b28f90..2c468f0741e 100644 --- a/packages/flame_rive/test/flame_rive_test.dart +++ b/packages/flame_rive/test/flame_rive_test.dart @@ -56,7 +56,7 @@ void main() { }); testWithFlameGame( - 'Can Add with Tappable', + 'Can Add with TapCallbacks', (game) async { final child = _RiveComponentWithTappable( artboard: await loadArtboard(riveFile),