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
Browse files Browse the repository at this point in the history
  • Loading branch information
alestiago committed Feb 16, 2024
1 parent e1fad2d commit f2e4328
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 24 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/trashy_road.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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"
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,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(10);

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(10);

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(10);

final player = behavior.parent;
final currentVerticalPosition = player.position.x;
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 @@ -9,12 +11,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 +38,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 +47,7 @@ class _TestGame extends FlameGame {
),
);

await player.ensureAdd(PlayerMovingBehavior());
await player.ensureAdd(behavior);
}
}
Expand All @@ -48,9 +60,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 +96,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 +124,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 +152,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 +180,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 f2e4328

Please sign in to comment.