PR suggestions

pull/28/head
Erick Zanardo 4 years ago
parent 27308d1eaa
commit 7adca67e6d

@ -4,19 +4,15 @@ import 'dart:async';
import 'package:flame/input.dart';
import 'package:flame_bloc/flame_bloc.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball_theme/pinball_theme.dart';
class PinballGame extends Forge2DGame
with FlameBloc, HasKeyboardHandlerComponents, TapDetector {
PinballGame({required this.theme, bool isDebugMode = kDebugMode}) : _isDebugMode = isDebugMode;
with FlameBloc, HasKeyboardHandlerComponents {
PinballGame({required this.theme});
final PinballTheme theme;
final bool _isDebugMode;
// TODO(erickzanardo): Change to the plumber position
late final ballStartingPosition = screenToWorld(
Vector2(
@ -108,11 +104,14 @@ class PinballGame extends Forge2DGame
),
);
}
}
class DebugPinballGame extends PinballGame with TapDetector {
DebugPinballGame({ required PinballTheme theme}) : super(theme: theme);
@override
void onTapUp(TapUpInfo info) {
if (_isDebugMode) {
add(Ball(position: info.eventPosition.game));
}
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,12 @@ 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 +51,8 @@ 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

@ -12,9 +12,7 @@ void main() {
group('PinballGame', () {
TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(PinballGameTest.create);
final debugModeFlameTester = FlameTester(
() => PinballGame(isDebugMode: true),
);
final debugModeFlameTester = FlameTester(DebugPinballGame.new);
// TODO(alestiago): test if [PinballGame] registers
// [BallScorePointsCallback] once the following issue is resolved:

@ -100,5 +100,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(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(),
gameBloc: gameBloc,
);
expect(
find.byWidgetPredicate(
(w) => w is GameWidget<PinballGame> && w.game is DebugPinballGame,
),
findsOneWidget,
);
});
});
}

Loading…
Cancel
Save