Merge branch 'main' into feat/bonus-letter-bloc

pull/24/head
Erick 4 years ago committed by GitHub
commit bc122a70bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,18 @@
name: geometry
on:
push:
paths:
- "packages/geometry/**"
- ".github/workflows/geometry.yaml"
pull_request:
paths:
- "packages/geometry/**"
- ".github/workflows/geometry.yaml"
jobs:
build:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
with:
working_directory: packages/geometry

@ -53,7 +53,7 @@ class Ball extends PositionBodyComponent<PinballGame, SpriteComponent> {
final bloc = gameRef.read<GameBloc>()..add(const BallLost());
final shouldBallRespwan = !bloc.state.isLastBall;
final shouldBallRespwan = !bloc.state.isLastBall && !bloc.state.isGameOver;
if (shouldBallRespwan) {
gameRef.spawnBall();
}

@ -22,9 +22,4 @@ class BallScorePointsCallback extends ContactCallback<Ball, ScorePoints> {
) {
ball.gameRef.read<GameBloc>().add(Scored(points: scorePoints.points));
}
// TODO(alestiago): remove once this issue is closed.
// https://github.com/flame-engine/flame/issues/1414
@override
void end(Ball _, ScorePoints __, Contact ___) {}
}

@ -63,7 +63,4 @@ class BottomWallBallContactCallback extends ContactCallback<Ball, BottomWall> {
void begin(Ball ball, BottomWall wall, Contact contact) {
ball.lost();
}
@override
void end(_, __, ___) {}
}

@ -105,3 +105,12 @@ class PinballGame extends Forge2DGame
);
}
}
class DebugPinballGame extends PinballGame with TapDetector {
DebugPinballGame({required PinballTheme theme}) : super(theme: theme);
@override
void onTapUp(TapUpInfo info) {
add(Ball(position: info.eventPosition.game));
}
}

@ -1,6 +1,7 @@
// ignore_for_file: public_member_api_docs
import 'package:flame/game.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/game/game.dart';
@ -29,9 +30,15 @@ class PinballGamePage extends StatelessWidget {
}
class PinballGameView extends StatefulWidget {
const PinballGameView({Key? key, required this.theme}) : super(key: key);
const PinballGameView({
Key? key,
required this.theme,
bool isDebugMode = kDebugMode,
}) : _isDebugMode = isDebugMode,
super(key: key);
final PinballTheme theme;
final bool _isDebugMode;
@override
State<PinballGameView> createState() => _PinballGameViewState();
@ -47,7 +54,10 @@ class _PinballGameViewState extends State<PinballGameView> {
// TODO(erickzanardo): Revisit this when we start to have more assets
// this could expose a Stream (maybe even a cubit?) so we could show the
// the loading progress with some fancy widgets.
_game = PinballGame(theme: widget.theme)..preLoadAssets();
_game = (widget._isDebugMode
? DebugPinballGame(theme: widget.theme)
: PinballGame(theme: widget.theme))
..preLoadAssets();
}
@override

@ -1,5 +1,6 @@
import 'dart:math' as math;
import 'package:flame/extensions.dart';
import 'package:vector_math/vector_math_64.dart';
/// Calculates all [Vector2]s of a circumference.
///

@ -7,13 +7,9 @@ environment:
sdk: ">=2.16.0 <3.0.0"
dependencies:
flame: ^1.0.0
flutter:
sdk: flutter
vector_math: ^2.1.1
dev_dependencies:
flutter_test:
sdk: flutter
mocktail: ^0.2.0
test: ^1.19.2
very_good_analysis: ^2.4.0

@ -1,7 +1,8 @@
// ignore_for_file: prefer_const_constructors, cascade_invocations
import 'package:flame/extensions.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:geometry/geometry.dart';
import 'package:test/test.dart';
import 'package:vector_math/vector_math_64.dart';
class Binomial {
Binomial({required this.n, required this.k});
@ -42,18 +43,18 @@ void main() {
],
step: 2,
),
throwsAssertionError,
throwsA(isA<AssertionError>()),
);
});
test('fails if not enough control points', () {
expect(
() => calculateBezierCurve(controlPoints: [Vector2.zero()]),
throwsAssertionError,
throwsA(isA<AssertionError>()),
);
expect(
() => calculateBezierCurve(controlPoints: []),
throwsAssertionError,
throwsA(isA<AssertionError>()),
);
});
@ -81,15 +82,24 @@ void main() {
group('binomial', () {
test('fails if k is negative', () {
expect(() => binomial(1, -1), throwsAssertionError);
expect(
() => binomial(1, -1),
throwsA(isA<AssertionError>()),
);
});
test('fails if n is negative', () {
expect(() => binomial(-1, 1), throwsAssertionError);
expect(
() => binomial(-1, 1),
throwsA(isA<AssertionError>()),
);
});
test('fails if n < k', () {
expect(() => binomial(1, 2), throwsAssertionError);
expect(
() => binomial(1, 2),
throwsA(isA<AssertionError>()),
);
});
test('for a specific input gives a correct value', () {
@ -131,7 +141,7 @@ void main() {
group('factorial', () {
test('fails if negative number', () {
expect(() => factorial(-1), throwsAssertionError);
expect(() => factorial(-1), throwsA(isA<AssertionError>()));
});
test('for a specific input gives a correct value', () {

@ -11,7 +11,7 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('Anchor', () {
final flameTester = FlameTester(PinballGameX.initial);
final flameTester = FlameTester(PinballGameTest.create);
flameTester.test(
'loads correctly',

@ -13,7 +13,7 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('Ball', () {
final flameTester = FlameTester(PinballGameX.initial);
final flameTester = FlameTester(PinballGameTest.create);
flameTester.test(
'loads correctly',

@ -12,7 +12,7 @@ import '../../helpers/helpers.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(PinballGameX.initial);
final flameTester = FlameTester(PinballGameTest.create);
group(
'Flipper',
() {

@ -10,7 +10,7 @@ import '../../helpers/helpers.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(PinballGameX.initial);
final flameTester = FlameTester(PinballGameTest.create);
group('Pathway', () {
const width = 50.0;

@ -10,7 +10,7 @@ import '../../helpers/helpers.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(PinballGameX.initial);
final flameTester = FlameTester(PinballGameTest.create);
group('Plunger', () {
flameTester.test(

@ -32,7 +32,7 @@ void main() {
},
);
});
final flameTester = FlameTester(PinballGameX.initial);
final flameTester = FlameTester(PinballGameTest.create);
flameTester.test(
'loads correctly',

@ -3,6 +3,7 @@
import 'package:flame/components.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/game.dart';
import '../helpers/helpers.dart';
@ -10,7 +11,8 @@ import '../helpers/helpers.dart';
void main() {
group('PinballGame', () {
TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(PinballGameX.initial);
final flameTester = FlameTester(PinballGameTest.create);
final debugModeFlameTester = FlameTester(DebugPinballGameTest.create);
// TODO(alestiago): test if [PinballGame] registers
// [BallScorePointsCallback] once the following issue is resolved:
@ -49,6 +51,24 @@ void main() {
);
},
);
debugModeFlameTester.test('adds a ball on tap up', (game) async {
await game.ready();
final eventPosition = MockEventPosition();
when(() => eventPosition.game).thenReturn(Vector2.all(10));
final tapUpEvent = MockTapUpInfo();
when(() => tapUpEvent.eventPosition).thenReturn(eventPosition);
game.onTapUp(tapUpEvent);
await game.ready();
expect(
game.children.whereType<Ball>().length,
equals(1),
);
});
});
},
);

@ -1,3 +1,5 @@
// ignore_for_file: prefer_const_constructors
import 'package:bloc_test/bloc_test.dart';
import 'package:flame/game.dart';
import 'package:flutter/material.dart';
@ -20,7 +22,7 @@ void main() {
);
await tester.pumpApp(
const PinballGamePage(theme: theme),
PinballGamePage(theme: theme),
gameBloc: gameBloc,
);
expect(find.byType(PinballGameView), findsOneWidget);
@ -64,9 +66,10 @@ void main() {
);
await tester.pumpApp(
const PinballGameView(theme: theme),
PinballGameView(theme: theme),
gameBloc: gameBloc,
);
expect(
find.byWidgetPredicate((w) => w is GameWidget<PinballGame>),
findsOneWidget,
@ -106,5 +109,45 @@ void main() {
);
},
);
testWidgets('renders the real game when not in debug mode', (tester) async {
final gameBloc = MockGameBloc();
whenListen(
gameBloc,
Stream.value(const GameState.initial()),
initialState: const GameState.initial(),
);
await tester.pumpApp(
const PinballGameView(theme: theme, isDebugMode: false),
gameBloc: gameBloc,
);
expect(
find.byWidgetPredicate(
(w) => w is GameWidget<PinballGame> && w.game is! DebugPinballGame,
),
findsOneWidget,
);
});
testWidgets('renders the debug game when on debug mode', (tester) async {
final gameBloc = MockGameBloc();
whenListen(
gameBloc,
Stream.value(const GameState.initial()),
initialState: const GameState.initial(),
);
await tester.pumpApp(
const PinballGameView(theme: theme),
gameBloc: gameBloc,
);
expect(
find.byWidgetPredicate(
(w) => w is GameWidget<PinballGame> && w.game is DebugPinballGame,
),
findsOneWidget,
);
});
});
}

@ -1,13 +1,14 @@
import 'package:flame_test/flame_test.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball_theme/pinball_theme.dart';
import 'helpers.dart';
FlameTester<PinballGame> flameBlocTester({
required GameBloc gameBloc,
}) {
return FlameTester<PinballGame>(
PinballGameX.initial,
PinballGameTest.create,
pumpWidget: (gameWidget, tester) async {
await tester.pumpWidget(
BlocProvider.value(
@ -18,11 +19,3 @@ FlameTester<PinballGame> flameBlocTester({
},
);
}
extension PinballGameX on PinballGame {
static PinballGame initial() => PinballGame(
theme: const PinballTheme(
characterTheme: DashTheme(),
),
);
}

@ -0,0 +1,22 @@
import 'package:pinball/game/game.dart';
import 'package:pinball_theme/pinball_theme.dart';
/// [PinballGame] extension to reduce boilerplate in tests.
extension PinballGameTest on PinballGame {
/// Create [PinballGame] with default [PinballTheme].
static PinballGame create() => PinballGame(
theme: const PinballTheme(
characterTheme: DashTheme(),
),
);
}
/// [DebugPinballGame] extension to reduce boilerplate in tests.
extension DebugPinballGameTest on DebugPinballGame {
/// Create [PinballGame] with default [PinballTheme].
static DebugPinballGame create() => DebugPinballGame(
theme: const PinballTheme(
characterTheme: DashTheme(),
),
);
}

@ -1,11 +1,11 @@
// Copyright (c) 2021, Very Good Ventures
// https://verygood.ventures
//
// Copyright (c) 2021, Very Good Ventures
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
// https://verygood.ventures
// license that can be found in the LICENSE file or at
export 'builders.dart';
export 'extensions.dart';
export 'key_testers.dart';
export 'mocks.dart';
export 'pump_app.dart';

@ -1,3 +1,4 @@
import 'package:flame/input.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
@ -32,3 +33,7 @@ class MockRawKeyUpEvent extends Mock implements RawKeyUpEvent {
return super.toString();
}
}
class MockTapUpInfo extends Mock implements TapUpInfo {}
class MockEventPosition extends Mock implements EventPosition {}

Loading…
Cancel
Save