Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(flame_behaviors)!: migrate to flame v1.10.0 #46

Merged
merged 5 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/flame_behaviors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ on:
paths:
- ".github/workflows/flame_behaviors.yaml"
- "packages/flame_behaviors/lib/**"
- packages/flame_behaviors/"test/**"
- packages/flame_behaviors/"pubspec.yaml"
- "packages/flame_behaviors/test/**"
- "packages/flame_behaviors/pubspec.yaml"

jobs:
build:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1
with:
working_directory: packages/flame_behaviors
flutter_channel: stable
flutter_version: 3.7.3
flutter_version: 3.13.5

pana:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/pana.yml@v1
Expand Down
10 changes: 5 additions & 5 deletions docs/input-behaviors.md → docs/event-behaviors.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Input Behaviors ⌨
# Event Behaviors ⌨

The `flame_behaviors` package also provides input behaviors. These behaviors are a layer over the
existing Flame input mixins for components. These behaviors will trigger when the user interacts with their parent entity. So these events are always relative to the parent entity.
The `flame_behaviors` package also provides event behaviors. These behaviors are a layer over the
existing Flame event mixins for components. These behaviors will trigger when the user interacts with their parent entity. So these events are always relative to the parent entity.

## TappableBehavior

Expand Down Expand Up @@ -30,5 +30,5 @@ class MyDraggableBehavior extends DraggableBehavior<MyEntity> {
}
```

[flame_drag_docs]: https://docs.flame-engine.org/1.7.0/flame/inputs/drag_events.html
[flame_tap_docs]: https://docs.flame-engine.org/1.7.0/flame/inputs/tap_events.html
[flame_drag_docs]: https://docs.flame-engine.org/1.10.0/flame/inputs/drag_events.html
[flame_tap_docs]: https://docs.flame-engine.org/1.10.0/flame/inputs/tap_events.html
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ To learn more about how to use Flame Behaviors, check out our [article][article_
[flame_package_link]: https://pub.dev/packages/flame
[flame_behaviors_package_link]: https://pub.dev/packages/flame_behaviors
[article_link]: https://verygood.ventures/blog/build-games-with-flame-behaviors
[input_behaviors_link]: https://github.com/VeryGoodOpenSource/flame_behaviors/blob/docs/main/docs/input-behaviors.md
[input_behaviors_link]: https://github.com/VeryGoodOpenSource/flame_behaviors/blob/docs/main/docs/event-behaviors.md
[naming_conventions_link]: https://github.com/VeryGoodOpenSource/flame_behaviors/blob/docs/main/docs/conventions/naming-conventions.md
[code_conventions_link]: https://github.com/VeryGoodOpenSource/flame_behaviors/blob/docs/main/docs/conventions/coding-conventions.md
2 changes: 1 addition & 1 deletion packages/flame_behaviors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Developed with 💙 and 🔥 by [Very Good Ventures][very_good_ventures_link]
In order to use Flame Behaviors you must have the [Flame package][flame_package_link] added to your
project.

> **Note**: Flame Behaviors requires Flame `">=1.6.0 <2.0.0"`
> **Note**: Flame Behaviors requires Flame `">=1.10.0 <2.0.0"`

### Adding the package

Expand Down
2 changes: 1 addition & 1 deletion packages/flame_behaviors/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:very_good_analysis/analysis_options.4.0.0.yaml
include: package:very_good_analysis/analysis_options.5.1.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:math';

import 'package:example/entities/entities.dart';
import 'package:example/main.dart';
import 'package:flame/experimental.dart' hide Circle, Rectangle;
import 'package:flame/events.dart';
import 'package:flame/extensions.dart';
import 'package:flame_behaviors/flame_behaviors.dart';

Expand All @@ -20,6 +20,7 @@ class SpawningBehavior extends TappableBehavior<ExampleGame> {

@override
void onTapDown(TapDownEvent event) {
if (event.handled) return;
parent.add(nextRandomEntity(event.canvasPosition));
}

Expand All @@ -29,26 +30,21 @@ class SpawningBehavior extends TappableBehavior<ExampleGame> {
final velocity = (Vector2.random(_rng) - Vector2.random(_rng)) * 300;
final shapeType = Shapes.values[_rng.nextInt(Shapes.values.length)];

switch (shapeType) {
case Shapes.circle:
return Circle(
return switch (shapeType) {
Shapes.circle => Circle(
position: position,
size: size,
velocity: velocity,
rotationSpeed: rotationSpeed,
);
case Shapes.rectangle:
return Rectangle(
),
Shapes.rectangle => Rectangle(
position: position,
size: size,
velocity: velocity,
rotationSpeed: rotationSpeed,
);
}
),
};
}
}

enum Shapes {
circle,
rectangle,
}
enum Shapes { circle, rectangle }
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:math';

import 'package:flame/components.dart';
Expand All @@ -11,7 +12,7 @@ class RotatingBehavior extends Behavior<PositionedEntity> with HasGameRef {
late final ScreenHitbox screenHitbox;

@override
Future<void> onLoad() async {
FutureOr<void> onLoad() {
screenHitbox = gameRef.children.whereType<ScreenHitbox>().first;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'circle_collision_behavior.dart';
export 'dragging_behavior.dart';
export 'rectangle_collision_behavior.dart';
export 'tapping_behavior.dart';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:example/entities/entities.dart';
import 'package:flame/experimental.dart' hide Circle;
import 'package:flame/events.dart';
import 'package:flame/extensions.dart';
import 'package:flame_behaviors/flame_behaviors.dart';

Expand All @@ -9,8 +9,9 @@ class DraggingBehavior extends DraggableBehavior<Circle> {
Vector2? originalVelocity;

@override
Future<void> onLoad() async {
void onMount() {
movement = parent.findBehavior<MovingBehavior>();
return super.onMount();
}

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:example/entities/entities.dart';
import 'package:flame/events.dart';
import 'package:flame_behaviors/flame_behaviors.dart';

/// This behavior ensures that SpawningBehavior of the game does not spawn
/// anything when we click on a circle (for dragging).
class TappingBehavior extends TappableBehavior<Circle> {
@override
void onTapDown(TapDownEvent event) {
event.handled = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Circle extends PositionedEntity with HasPaint {
ScreenCollidingBehavior(),
MovingBehavior(velocity: velocity),
RotatingBehavior(rotationSpeed: rotationSpeed),
DraggingBehavior()
TappingBehavior(),
DraggingBehavior(),
],
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:example/entities/entities.dart';
import 'package:flame/experimental.dart' hide Rectangle;
import 'package:flame/events.dart';
import 'package:flame/extensions.dart';
import 'package:flame_behaviors/flame_behaviors.dart';

Expand All @@ -9,8 +9,9 @@ class FreezingBehavior extends TappableBehavior<Rectangle> {
Vector2? originalVelocity;

@override
Future<void> onLoad() async {
void onMount() {
movement = parent.findBehavior<MovingBehavior>();
return super.onMount();
}

@override
Expand All @@ -21,5 +22,6 @@ class FreezingBehavior extends TappableBehavior<Rectangle> {
originalVelocity = movement?.velocity.clone();
movement?.velocity.setFrom(Vector2.zero());
}
event.handled = true;
}
}
4 changes: 2 additions & 2 deletions packages/flame_behaviors/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ version: 1.0.0+1
publish_to: none

environment:
sdk: ">=2.17.0 <3.0.0"
sdk: ">=3.0.0 <4.0.0"

dependencies:
flame: ^1.5.0
flame: ^1.10.0
flame_behaviors:
path: ../
flutter:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export 'behavior.dart';
export 'input/input.dart';
export 'events/events.dart';
export 'propagating_collision_behavior.dart';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flame/experimental.dart';
import 'package:flame/events.dart';
import 'package:flame_behaviors/flame_behaviors.dart';

/// {@template draggable_behavior}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export 'package:flame/input.dart'
export 'package:flame/events.dart'
show
DragEndInfo,
DragStartInfo,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flame/components.dart';
import 'package:flame/events.dart';
import 'package:flame_behaviors/flame_behaviors.dart';

/// {@template hoverable_behavior}
Expand All @@ -9,4 +9,4 @@ import 'package:flame_behaviors/flame_behaviors.dart';
/// behaviors.
/// {@endtemplate}
abstract class HoverableBehavior<Parent extends EntityMixin>
extends Behavior<Parent> with Hoverable {}
extends Behavior<Parent> with HoverCallbacks {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flame/experimental.dart';
import 'package:flame/events.dart';
import 'package:flame_behaviors/flame_behaviors.dart';

/// {@template tappable_behavior}
Expand Down
3 changes: 3 additions & 0 deletions packages/flame_behaviors/lib/src/entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ abstract class Entity extends Component with EntityMixin {
Entity({
super.children,
super.priority,
super.key,
Iterable<Behavior>? behaviors,
}) : assert(
children?.whereType<Behavior>().isEmpty ?? true,
Expand All @@ -91,9 +92,11 @@ abstract class PositionedEntity extends PositionComponent with EntityMixin {
super.size,
super.scale,
super.angle,
super.nativeAngle,
super.anchor,
super.children,
super.priority,
super.key,
Iterable<Behavior>? behaviors,
}) : assert(
children?.whereType<Behavior>().isEmpty ?? true,
Expand Down
8 changes: 4 additions & 4 deletions packages/flame_behaviors/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ issue_tracker: https://github.com/VeryGoodOpenSource/flame_behaviors/issues
documentation: https://github.com/VeryGoodOpenSource/flame_behaviors/tree/main/docs

environment:
sdk: ">=2.17.0 <3.0.0"
sdk: ">=3.0.0 <4.0.0"

dependencies:
flame: ">=1.7.0 <2.0.0"
flame: ">=1.10.0 <2.0.0"
flutter:
sdk: flutter

dev_dependencies:
flame_test: ^1.9.1
flame_test: ^1.13.2
flutter_test:
sdk: flutter
mocktail: ^0.3.0
very_good_analysis: ^4.0.0+1
very_good_analysis: ^5.1.0
1 change: 0 additions & 1 deletion packages/flame_behaviors/test/helpers/helpers.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export 'test_game.dart';
export 'throws_behavior_not_found_for.dart';
4 changes: 0 additions & 4 deletions packages/flame_behaviors/test/helpers/test_game.dart

This file was deleted.

18 changes: 7 additions & 11 deletions packages/flame_behaviors/test/src/behaviors/behavior_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ import 'package:flame_behaviors/flame_behaviors.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../helpers/test_game.dart';

class _TestEntity extends PositionedEntity {
_TestEntity({super.behaviors}) : super(size: Vector2.all(32));
}

class _TestBehavior extends Behavior<_TestEntity> {}

void main() {
final flameTester = FlameTester(TestGame.new);

group('Behavior', () {
flameTester.testGameWidget(
flameGame.testGameWidget(
'can be added to an Entity',
setUp: (game, tester) async {
final behavior = _TestBehavior();
Expand All @@ -32,7 +28,7 @@ void main() {
},
);

flameTester.testGameWidget(
flameGame.testGameWidget(
'contains point is relative to parent',
setUp: (game, tester) async {
final behavior = _TestBehavior();
Expand All @@ -49,7 +45,7 @@ void main() {
},
);

flameTester.testGameWidget(
flameGame.testGameWidget(
'contains local point is relative to parent',
setUp: (game, tester) async {
final behavior = _TestBehavior();
Expand All @@ -66,7 +62,7 @@ void main() {
},
);

flameTester.testGameWidget(
flameGame.testGameWidget(
'debugMode is provided by the parent',
setUp: (game, tester) async {
final behavior = _TestBehavior();
Expand Down Expand Up @@ -94,7 +90,7 @@ void main() {
);
});

flameTester.testGameWidget(
flameGame.testGameWidget(
'can have its own children',
setUp: (game, tester) async {
await game.ensureAdd(testEntity);
Expand All @@ -104,7 +100,7 @@ void main() {
},
);

flameTester.testGameWidget(
flameGame.testGameWidget(
'can not have behaviors as children',
setUp: (game, tester) async {
await game.ensureAdd(testEntity);
Expand All @@ -117,7 +113,7 @@ void main() {
},
);

flameTester.testGameWidget(
flameGame.testGameWidget(
'can not have entities as children',
setUp: (game, tester) async {
await game.ensureAdd(testEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import 'package:flame/collisions.dart';
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame_behaviors/flame_behaviors.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../helpers/helpers.dart';

class _EntityA extends PositionedEntity {
_EntityA({
super.behaviors,
Expand Down Expand Up @@ -60,8 +59,10 @@ class _CollisionBehaviorAtoC extends _CollisionBehavior<_EntityC, _EntityA> {}
class _CollisionBehaviorAtoComponent
extends _CollisionBehavior<PositionComponent, _EntityA> {}

class _TestGame extends FlameGame with HasCollisionDetection {}

void main() {
final flameTester = FlameTester(TestGame.new);
final flameTester = FlameTester(_TestGame.new);

group('$CollisionBehavior', () {
flameTester.testGameWidget(
Expand Down
Loading