From d547608e3f3f23a97e5ef69aaa733e551ab69f8d Mon Sep 17 00:00:00 2001 From: Alejandro Santiago Date: Fri, 16 Feb 2024 06:38:50 +0000 Subject: [PATCH] ci: add trashy_road workflow (#111) * ci: add trashy_road workflow * chore: use game.update(1) * chore: small tweaks * chore: bump min SDK * chore: ignore deprecated members * ci: add min_coverage --- .github/workflows/trashy_road.yaml | 27 ++++++++++ .../player_keyboard_moving_behavior.dart | 4 ++ .../behaviors/player_moving_behavior.dart | 2 +- .../lib/src/game/entities/player/player.dart | 2 +- .../lib/src/loading/view/loading_page.dart | 2 +- .../trashy_road/lib/src/maps/view/view.dart | 1 + packages/trashy_road/pubspec.lock | 50 ++++++++++++------- packages/trashy_road/pubspec.yaml | 2 +- .../player_moving_behavior_test.dart | 41 ++++++++++----- .../player_moving_keyboard_behavior_test.dart | 40 +++++++++++---- 10 files changed, 128 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/trashy_road.yaml diff --git a/.github/workflows/trashy_road.yaml b/.github/workflows/trashy_road.yaml new file mode 100644 index 00000000..15fb74fc --- /dev/null +++ b/.github/workflows/trashy_road.yaml @@ -0,0 +1,27 @@ +name: trashy_road + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + paths: + - .github/workflows/trashy_road.yaml + - "packages/trashy_road/**" + branches: + - main + pull_request: + paths: + - .github/workflows/trashy_road.yaml + - "packages/trashy_road/**" + branches: + - main + +jobs: + build: + uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1 + with: + coverage_excludes: "*.gen.dart" + working_directory: "packages/trashy_road" + min_coverage: 14 diff --git a/packages/trashy_road/lib/src/game/entities/player/behaviors/player_keyboard_moving_behavior.dart b/packages/trashy_road/lib/src/game/entities/player/behaviors/player_keyboard_moving_behavior.dart index 31997cf6..7d9749af 100644 --- a/packages/trashy_road/lib/src/game/entities/player/behaviors/player_keyboard_moving_behavior.dart +++ b/packages/trashy_road/lib/src/game/entities/player/behaviors/player_keyboard_moving_behavior.dart @@ -1,3 +1,7 @@ +// FIXME(alestiago): Avoid ignoring deprecated_member_use as soon as: +// https://github.com/flame-engine/flame/pull/3002 is released. +// ignore_for_file: deprecated_member_use + import 'dart:async'; import 'package:flame/components.dart'; diff --git a/packages/trashy_road/lib/src/game/entities/player/behaviors/player_moving_behavior.dart b/packages/trashy_road/lib/src/game/entities/player/behaviors/player_moving_behavior.dart index b65a9fc9..a5ce3287 100644 --- a/packages/trashy_road/lib/src/game/entities/player/behaviors/player_moving_behavior.dart +++ b/packages/trashy_road/lib/src/game/entities/player/behaviors/player_moving_behavior.dart @@ -7,7 +7,7 @@ import 'package:trashy_road/src/game/game.dart'; enum Direction { up, down, left, right } /// A behavior that allows the player to move around the game. -class PlayerMovingBehavior extends Behavior +final class PlayerMovingBehavior extends Behavior with FlameBlocReader { /// The position the player is trying to move to. /// diff --git a/packages/trashy_road/lib/src/game/entities/player/player.dart b/packages/trashy_road/lib/src/game/entities/player/player.dart index 5998e240..a3a658cb 100644 --- a/packages/trashy_road/lib/src/game/entities/player/player.dart +++ b/packages/trashy_road/lib/src/game/entities/player/player.dart @@ -35,7 +35,7 @@ class Player extends PositionedEntity { ); @visibleForTesting - Player.test({super.behaviors}); + Player.empty(); /// Derives a [Player] from a [TiledObject]. /// diff --git a/packages/trashy_road/lib/src/loading/view/loading_page.dart b/packages/trashy_road/lib/src/loading/view/loading_page.dart index 060c27b4..b1a3dcad 100644 --- a/packages/trashy_road/lib/src/loading/view/loading_page.dart +++ b/packages/trashy_road/lib/src/loading/view/loading_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:trashy_road/src/loading/loading.dart'; -import 'package:trashy_road/src/maps/view/maps_menu_page.dart'; +import 'package:trashy_road/src/maps/maps.dart'; class LoadingPage extends StatefulWidget { const LoadingPage({super.key}); diff --git a/packages/trashy_road/lib/src/maps/view/view.dart b/packages/trashy_road/lib/src/maps/view/view.dart index e69de29b..fd540227 100644 --- a/packages/trashy_road/lib/src/maps/view/view.dart +++ b/packages/trashy_road/lib/src/maps/view/view.dart @@ -0,0 +1 @@ +export 'maps_menu_page.dart'; diff --git a/packages/trashy_road/pubspec.lock b/packages/trashy_road/pubspec.lock index 6440deef..17f42c3d 100644 --- a/packages/trashy_road/pubspec.lock +++ b/packages/trashy_road/pubspec.lock @@ -411,6 +411,30 @@ packages: url: "https://pub.dev" source: hosted version: "4.8.1" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" logging: dependency: transitive description: @@ -423,26 +447,26 @@ packages: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: "direct main" description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" mime: dependency: transitive description: @@ -495,10 +519,10 @@ packages: dependency: "direct main" description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" petitparser: dependency: transitive description: @@ -736,14 +760,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" - web: - dependency: transitive - description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 - url: "https://pub.dev" - source: hosted - version: "0.3.0" web_socket_channel: dependency: transitive description: @@ -777,5 +793,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.2.2 <4.0.0" + dart: ">=3.3.0 <4.0.0" flutter: ">=3.13.0" diff --git a/packages/trashy_road/pubspec.yaml b/packages/trashy_road/pubspec.yaml index 8b6bd846..e56f5aaa 100644 --- a/packages/trashy_road/pubspec.yaml +++ b/packages/trashy_road/pubspec.yaml @@ -5,7 +5,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=3.2.2 <4.0.0" + sdk: ">=3.3.0 <4.0.0" dependencies: bloc: ^8.1.2 diff --git a/packages/trashy_road/test/src/game/entities/player/behaviors/player_moving_behavior_test.dart b/packages/trashy_road/test/src/game/entities/player/behaviors/player_moving_behavior_test.dart index 8ba9611c..17397637 100644 --- a/packages/trashy_road/test/src/game/entities/player/behaviors/player_moving_behavior_test.dart +++ b/packages/trashy_road/test/src/game/entities/player/behaviors/player_moving_behavior_test.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flame/game.dart'; import 'package:flame_bloc/flame_bloc.dart'; import 'package:flame_test/flame_test.dart'; @@ -8,6 +10,17 @@ import 'package:trashy_road/src/game/game.dart'; class _MockTiledMap extends Mock implements TiledMap {} +class _MockObjectGroup extends Mock implements ObjectGroup {} + +class _MockTiledObject extends Mock implements TiledObject {} + +class _TestPlayer extends Player { + _TestPlayer() : super.empty(); + + @override + FutureOr onLoad() {} +} + class _TestGame extends FlameGame { _TestGame({ required GameBloc gameBloc, @@ -22,9 +35,7 @@ class _TestGame extends FlameGame { FlameBlocProvider( create: () => _gameBloc, children: [ - Player.test( - behaviors: [behavior], - ), + _TestPlayer()..add(behavior), ], ), ); @@ -39,9 +50,13 @@ void main() { late GameBloc gameBloc; setUp(() { - gameBloc = GameBloc( - map: _MockTiledMap(), - ); + final objectGroup = _MockObjectGroup(); + when(() => objectGroup.objects).thenReturn([_MockTiledObject()]); + + final map = _MockTiledMap(); + when(() => map.layerByName('TrashLayer')).thenReturn(objectGroup); + + gameBloc = GameBloc(map: map); game = _TestGame(gameBloc: gameBloc); }); @@ -58,11 +73,12 @@ void main() { final behavior = PlayerMovingBehavior(); await game.pump(behavior); - final previousVerticalPosition = behavior.parent.position.y; + final player = behavior.parent; + final previousVerticalPosition = player.position.y; + behavior.move(direction); - game.update(0); + game.update(1); - final player = behavior.parent; final currentVerticalPosition = player.position.y; expect( previousVerticalPosition, @@ -72,6 +88,7 @@ void main() { ); }, ); + testWithGame<_TestGame>( 'moves downwards with $Direction.down', () => game, @@ -82,7 +99,7 @@ void main() { final previousVerticalPosition = behavior.parent.position.y; behavior.move(direction); - game.update(0); + game.update(1); final player = behavior.parent; final currentVerticalPosition = player.position.y; @@ -104,7 +121,7 @@ void main() { final previousVerticalPosition = behavior.parent.position.x; behavior.move(direction); - game.update(0); + game.update(1); final player = behavior.parent; final currentVerticalPosition = player.position.x; @@ -126,7 +143,7 @@ void main() { final previousVerticalPosition = behavior.parent.position.x; behavior.move(direction); - game.update(0); + game.update(1); final player = behavior.parent; final currentVerticalPosition = player.position.x; diff --git a/packages/trashy_road/test/src/game/entities/player/behaviors/player_moving_keyboard_behavior_test.dart b/packages/trashy_road/test/src/game/entities/player/behaviors/player_moving_keyboard_behavior_test.dart index 4641f7c0..bc218768 100644 --- a/packages/trashy_road/test/src/game/entities/player/behaviors/player_moving_keyboard_behavior_test.dart +++ b/packages/trashy_road/test/src/game/entities/player/behaviors/player_moving_keyboard_behavior_test.dart @@ -1,3 +1,9 @@ +// FIXME(alestiago): Avoid ignoring deprecated_member_use as soon as: +// https://github.com/flame-engine/flame/pull/3002 is released. +// ignore_for_file: deprecated_member_use + +import 'dart:async'; + import 'package:flame/game.dart'; import 'package:flame_bloc/flame_bloc.dart'; import 'package:flame_test/flame_test.dart'; @@ -9,12 +15,23 @@ import 'package:trashy_road/src/game/game.dart'; class _MockTiledMap extends Mock implements TiledMap {} +class _MockObjectGroup extends Mock implements ObjectGroup {} + +class _MockTiledObject extends Mock implements TiledObject {} + class _MockRawKeyEventData extends Mock implements RawKeyEventData { @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) => super.toString(); } +class _TestPlayer extends Player { + _TestPlayer() : super.empty(); + + @override + FutureOr onLoad() {} +} + class _TestGame extends FlameGame { _TestGame({ required GameBloc gameBloc, @@ -25,9 +42,7 @@ class _TestGame extends FlameGame { Future pump( PlayerKeyboardMovingBehavior behavior, ) async { - final player = Player.test( - behaviors: [PlayerMovingBehavior()], - ); + final player = _TestPlayer(); await ensureAdd( FlameBlocProvider( @@ -36,6 +51,7 @@ class _TestGame extends FlameGame { ), ); + await player.ensureAdd(PlayerMovingBehavior()); await player.ensureAdd(behavior); } } @@ -48,9 +64,13 @@ void main() { late GameBloc gameBloc; setUp(() { - gameBloc = GameBloc( - map: _MockTiledMap(), - ); + final objectGroup = _MockObjectGroup(); + when(() => objectGroup.objects).thenReturn([_MockTiledObject()]); + + final map = _MockTiledMap(); + when(() => map.layerByName('TrashLayer')).thenReturn(objectGroup); + + gameBloc = GameBloc(map: map); game = _TestGame(gameBloc: gameBloc); }); @@ -80,7 +100,7 @@ void main() { behavior.onKeyEvent(event, {upKey}); - game.update(0); + game.update(1); final player = behavior.parent; final currentVerticalPosition = player.position.y; @@ -108,7 +128,7 @@ void main() { behavior.onKeyEvent(event, {downKey}); - game.update(0); + game.update(1); final player = behavior.parent; final currentVerticalPosition = player.position.y; @@ -136,7 +156,7 @@ void main() { behavior.onKeyEvent(event, {leftKey}); - game.update(0); + game.update(1); final player = behavior.parent; final currentHorizontalPosition = player.position.x; @@ -164,7 +184,7 @@ void main() { behavior.onKeyEvent(event, {rightKey}); - game.update(0); + game.update(1); final player = behavior.parent; final currentHorizontalPosition = player.position.x;