Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
ci: add trashy_road workflow (#111)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alestiago authored Feb 16, 2024
1 parent 4ff6152 commit d547608
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 43 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/trashy_road.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player>
final class PlayerMovingBehavior extends Behavior<Player>
with FlameBlocReader<GameBloc, GameState> {
/// The position the player is trying to move to.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Player extends PositionedEntity {
);

@visibleForTesting
Player.test({super.behaviors});
Player.empty();

/// Derives a [Player] from a [TiledObject].
///
Expand Down
Original file line number Diff line number Diff line change
@@ -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});
Expand Down
1 change: 1 addition & 0 deletions packages/trashy_road/lib/src/maps/view/view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'maps_menu_page.dart';
50 changes: 33 additions & 17 deletions packages/trashy_road/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion packages/trashy_road/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<void> onLoad() {}
}

class _TestGame extends FlameGame {
_TestGame({
required GameBloc gameBloc,
Expand All @@ -22,9 +35,7 @@ class _TestGame extends FlameGame {
FlameBlocProvider<GameBloc, GameState>(
create: () => _gameBloc,
children: [
Player.test(
behaviors: [behavior],
),
_TestPlayer()..add(behavior),
],
),
);
Expand All @@ -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);
});

Expand All @@ -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,
Expand All @@ -72,6 +88,7 @@ void main() {
);
},
);

testWithGame<_TestGame>(
'moves downwards with $Direction.down',
() => game,
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<void> onLoad() {}
}

class _TestGame extends FlameGame {
_TestGame({
required GameBloc gameBloc,
Expand All @@ -25,9 +42,7 @@ class _TestGame extends FlameGame {
Future<void> pump(
PlayerKeyboardMovingBehavior behavior,
) async {
final player = Player.test(
behaviors: [PlayerMovingBehavior()],
);
final player = _TestPlayer();

await ensureAdd(
FlameBlocProvider<GameBloc, GameState>(
Expand All @@ -36,6 +51,7 @@ class _TestGame extends FlameGame {
),
);

await player.ensureAdd(PlayerMovingBehavior());
await player.ensureAdd(behavior);
}
}
Expand All @@ -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);
});

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d547608

Please sign in to comment.