test: backboard changes

pull/319/head
Allison Ryan 3 years ago
parent 83212d91ba
commit f428cb2def

@ -57,7 +57,7 @@ class InitialsInputDisplay extends Component with HasGameRef {
Future<void> onLoad() async { Future<void> onLoad() async {
for (var i = 0; i < 3; i++) { for (var i = 0; i < 3; i++) {
await add( await add(
_BackboardLetterPrompt( _InitialsLetterPrompt(
position: Vector2( position: Vector2(
11.4 + (2.3 * i), 11.4 + (2.3 * i),
-20, -20,
@ -80,7 +80,7 @@ class InitialsInputDisplay extends Component with HasGameRef {
/// Returns the current inputed initials /// Returns the current inputed initials
String get initials => children String get initials => children
.whereType<_BackboardLetterPrompt>() .whereType<_InitialsLetterPrompt>()
.map((prompt) => prompt.char) .map((prompt) => prompt.char)
.join(); .join();
@ -90,7 +90,7 @@ class InitialsInputDisplay extends Component with HasGameRef {
} }
bool _movePrompt(bool left) { bool _movePrompt(bool left) {
final prompts = children.whereType<_BackboardLetterPrompt>().toList(); final prompts = children.whereType<_InitialsLetterPrompt>().toList();
final current = prompts.firstWhere((prompt) => prompt.hasFocus) final current = prompts.firstWhere((prompt) => prompt.hasFocus)
..hasFocus = false; ..hasFocus = false;
@ -118,7 +118,7 @@ class _ScoreLabelTextComponent extends TextComponent with HasGameRef {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
text = gameRef.buildContext!.l10n.score; text = AppLocalizations.of(gameRef.buildContext!).score;
} }
} }
@ -147,7 +147,7 @@ class _NameLabelTextComponent extends TextComponent with HasGameRef {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
text = gameRef.buildContext!.l10n.name; text = AppLocalizations.of(gameRef.buildContext!).name;
} }
} }
@ -170,8 +170,8 @@ class _CharacterIconSpriteComponent extends SpriteComponent with HasGameRef {
} }
} }
class _BackboardLetterPrompt extends PositionComponent { class _InitialsLetterPrompt extends PositionComponent {
_BackboardLetterPrompt({ _InitialsLetterPrompt({
required Vector2 position, required Vector2 position,
bool hasFocus = false, bool hasFocus = false,
}) : _hasFocus = hasFocus, }) : _hasFocus = hasFocus,
@ -303,7 +303,7 @@ class _EnterInitialsTextComponent extends TextComponent with HasGameRef {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
text = gameRef.buildContext!.l10n.enterInitials; text = AppLocalizations.of(gameRef.buildContext!).enterInitials;
} }
} }
@ -322,7 +322,7 @@ class _ArrowsTextComponent extends TextComponent with HasGameRef {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
text = gameRef.buildContext!.l10n.arrows; text = AppLocalizations.of(gameRef.buildContext!).arrows;
} }
} }
@ -337,7 +337,7 @@ class _AndPressTextComponent extends TextComponent with HasGameRef {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
text = gameRef.buildContext!.l10n.andPress; text = AppLocalizations.of(gameRef.buildContext!).andPress;
} }
} }
@ -356,7 +356,7 @@ class _EnterReturnTextComponent extends TextComponent with HasGameRef {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
text = gameRef.buildContext!.l10n.enterReturn; text = AppLocalizations.of(gameRef.buildContext!).enterReturn;
} }
} }
@ -371,6 +371,6 @@ class _ToSubmitTextComponent extends TextComponent with HasGameRef {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
text = gameRef.buildContext!.l10n.toSubmit; text = AppLocalizations.of(gameRef.buildContext!).toSubmit;
} }
} }

@ -1,7 +1,6 @@
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flame_bloc/flame_bloc.dart'; import 'package:flame_bloc/flame_bloc.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart'; import 'package:pinball_flame/pinball_flame.dart';
/// {@template game_flow_controller} /// {@template game_flow_controller}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 844 KiB

@ -0,0 +1,76 @@
// ignore_for_file: cascade_invocations
import 'package:flame/components.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_theme/pinball_theme.dart' as theme;
import '../../../helpers/helpers.dart';
void main() {
group('Backboard', () {
final characterIconPath = theme.Assets.images.dash.leaderboardIcon.keyName;
final assets = [
characterIconPath,
Assets.images.backboard.marquee.keyName,
Assets.images.backboard.displayDivider.keyName,
];
final tester = FlameTester(() => EmptyPinballTestGame(assets: assets));
tester.test(
'loads correctly',
(game) async {
final backboard = Backboard();
await game.ensureAdd(backboard);
expect(game.children, contains(backboard));
},
);
group('renders correctly', () {
tester.testGameWidget(
'empty',
setUp: (game, tester) async {
await game.images.loadAll(assets);
game.camera.zoom = 6;
game.camera.followVector2(Vector2(0, -130));
await game.ensureAdd(Backboard());
await game.ready();
await tester.pump();
},
verify: (game, tester) async {
await expectLater(
find.byGame<EmptyPinballTestGame>(),
matchesGoldenFile('../golden/backboard/empty.png'),
);
},
);
tester.testGameWidget(
'on initialsInput',
setUp: (game, tester) async {
await game.mounted;
await game.images.loadAll(assets);
game.camera.zoom = 2;
game.camera.followVector2(Vector2.zero());
final backboard = Backboard();
await game.ensureAdd(backboard);
await backboard.initialsInput(
score: 1000,
characterIconPath: characterIconPath,
onSubmit: (_) {},
);
await tester.pump();
},
verify: (game, tester) async {
await expectLater(
find.byGame<EmptyPinballTestGame>(),
matchesGoldenFile('../golden/backboard/initials-input.png'),
);
},
);
});
});
}

@ -0,0 +1,139 @@
// ignore_for_file: cascade_invocations
import 'package:flame_test/flame_test.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball/game/components/backboard/displays/displays.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_theme/pinball_theme.dart' as theme;
import '../../../../helpers/helpers.dart';
void main() {
group('InitialsInputDisplay', () {
final characterIconPath = theme.Assets.images.dash.leaderboardIcon.keyName;
final assets = [
characterIconPath,
Assets.images.backboard.displayDivider.keyName,
];
final tester = FlameTester(() => EmptyPinballTestGame(assets: assets));
tester.testGameWidget(
'changes the initials with arrow keys',
setUp: (game, tester) async {
final initialsInputDisplay = InitialsInputDisplay(
score: 1000,
characterIconPath: characterIconPath,
onSubmit: (_) {},
);
await game.ensureAdd(initialsInputDisplay);
// Focus is already on the first letter
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.pump();
// Move to the next an press up again
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.pump();
// One more time
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.pump();
// Back to the previous and increase one more
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.pump();
},
verify: (game, tester) async {
final initialsInputDisplay =
game.descendants().whereType<InitialsInputDisplay>().first;
expect(initialsInputDisplay.initials, equals('BCB'));
},
);
String? submitedInitials;
tester.testGameWidget(
'enter submits the initials',
setUp: (game, tester) async {
final initialsInputDisplay = InitialsInputDisplay(
score: 1000,
characterIconPath: characterIconPath,
onSubmit: (value) {
submitedInitials = value;
},
);
await game.ensureAdd(initialsInputDisplay);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
},
verify: (game, tester) async {
expect(submitedInitials, equals('AAA'));
},
);
});
}
// group('BackboardLetterPrompt', () {
// final tester = FlameTester(KeyboardTestGame.new);
// tester.testGameWidget(
// 'cycles the char up and down when it has focus',
// setUp: (game, tester) async {
// await game.ensureAdd(
// BackboardLetterPrompt(hasFocus: true, position: Vector2.zero()),
// );
// await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
// await tester.pump();
// await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
// await tester.pump();
// await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
// await tester.pump();
// await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
// await tester.pump();
// },
// verify: (game, tester) async {
// final prompt = game.firstChild<BackboardLetterPrompt>();
// expect(prompt?.char, equals('C'));
// },
// );
// tester.testGameWidget(
// "does nothing when it doesn't have focus",
// setUp: (game, tester) async {
// await game.ensureAdd(
// BackboardLetterPrompt(position: Vector2.zero()),
// );
// await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
// await tester.pump();
// },
// verify: (game, tester) async {
// final prompt = game.firstChild<BackboardLetterPrompt>();
// expect(prompt?.char, equals('A'));
// },
// );
// tester.testGameWidget(
// 'blinks the prompt when it has the focus',
// setUp: (game, tester) async {
// await game.ensureAdd(
// BackboardLetterPrompt(position: Vector2.zero(), hasFocus: true),
// );
// },
// verify: (game, tester) async {
// final underscore = game.descendants().whereType<ShapeComponent>().first;
// expect(underscore.paint.color, Colors.white);
// game.update(2);
// expect(underscore.paint.color, Colors.transparent);
// },
// );
// });

@ -24,15 +24,18 @@ void main() {
test('correctly calculates the zooms', () async { test('correctly calculates the zooms', () async {
expect(controller.gameFocus.zoom.toInt(), equals(12)); expect(controller.gameFocus.zoom.toInt(), equals(12));
expect(controller.backboardFocus.zoom.toInt(), equals(11)); expect(controller.waitingBackboardFocus.zoom.toInt(), equals(11));
}); });
test('correctly sets the initial zoom and position', () async { test('correctly sets the initial zoom and position', () async {
expect(game.camera.zoom, equals(controller.backboardFocus.zoom)); expect(game.camera.zoom, equals(controller.waitingBackboardFocus.zoom));
expect(game.camera.follow, equals(controller.backboardFocus.position)); expect(
game.camera.follow,
equals(controller.waitingBackboardFocus.position),
);
}); });
group('focusOnBoard', () { group('focusOnGame', () {
test('changes the zoom', () async { test('changes the zoom', () async {
controller.focusOnGame(); controller.focusOnGame();
@ -57,18 +60,43 @@ void main() {
}); });
}); });
group('focusOnBackboard', () { group('focusOnWaitingBackboard', () {
test('changes the zoom', () async { test('changes the zoom', () async {
controller.focusOnBackboard(); controller.focusOnWaitingBackboard();
await game.ready(); await game.ready();
final zoom = game.firstChild<CameraZoom>(); final zoom = game.firstChild<CameraZoom>();
expect(zoom, isNotNull); expect(zoom, isNotNull);
expect(zoom?.value, equals(controller.backboardFocus.zoom)); expect(zoom?.value, equals(controller.waitingBackboardFocus.zoom));
}); });
test('moves the camera after the zoom is completed', () async { test('moves the camera after the zoom is completed', () async {
controller.focusOnBackboard(); controller.focusOnWaitingBackboard();
await game.ready();
final cameraZoom = game.firstChild<CameraZoom>()!;
final future = cameraZoom.completed;
game.update(10);
game.update(0); // Ensure that the component was removed
await future;
expect(game.camera.position, Vector2(-4.5, -109.8));
});
});
group('focusOnGameOverBackboard', () {
test('changes the zoom', () async {
controller.focusOnGameOverBackboard();
await game.ready();
final zoom = game.firstChild<CameraZoom>();
expect(zoom, isNotNull);
expect(zoom?.value, equals(controller.gameOverBackboardFocus.zoom));
});
test('moves the camera after the zoom is completed', () async {
controller.focusOnGameOverBackboard();
await game.ready(); await game.ready();
final cameraZoom = game.firstChild<CameraZoom>()!; final cameraZoom = game.firstChild<CameraZoom>()!;
final future = cameraZoom.completed; final future = cameraZoom.completed;

@ -4,7 +4,6 @@ import 'package:flame/game.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_theme/pinball_theme.dart'; import 'package:pinball_theme/pinball_theme.dart';
import '../../helpers/helpers.dart'; import '../../helpers/helpers.dart';
@ -43,14 +42,13 @@ void main() {
overlays = MockActiveOverlaysNotifier(); overlays = MockActiveOverlaysNotifier();
when( when(
() => backboard.gameOverMode( () => backboard.initialsInput(
score: any(named: 'score'), score: any(named: 'score'),
characterIconPath: any(named: 'characterIconPath'), characterIconPath: any(named: 'characterIconPath'),
onSubmit: any(named: 'onSubmit'), onSubmit: any(named: 'onSubmit'),
), ),
).thenAnswer((_) async {}); ).thenAnswer((_) async {});
when(backboard.waitingMode).thenAnswer((_) async {}); when(cameraController.focusOnWaitingBackboard).thenAnswer((_) async {});
when(cameraController.focusOnBackboard).thenAnswer((_) async {});
when(cameraController.focusOnGame).thenAnswer((_) async {}); when(cameraController.focusOnGame).thenAnswer((_) async {});
when(() => overlays.remove(any())).thenAnswer((_) => true); when(() => overlays.remove(any())).thenAnswer((_) => true);
@ -62,7 +60,7 @@ void main() {
}); });
test( test(
'changes the backboard and camera correctly when it is a game over', 'changes the backboard and camera correctly when the game is over',
() { () {
gameFlowController.onNewState( gameFlowController.onNewState(
GameState( GameState(
@ -74,13 +72,13 @@ void main() {
); );
verify( verify(
() => backboard.gameOverMode( () => backboard.initialsInput(
score: 0, score: 0,
characterIconPath: any(named: 'characterIconPath'), characterIconPath: any(named: 'characterIconPath'),
onSubmit: any(named: 'onSubmit'), onSubmit: any(named: 'onSubmit'),
), ),
).called(1); ).called(1);
verify(cameraController.focusOnBackboard).called(1); verify(cameraController.focusOnWaitingBackboard).called(1);
}, },
); );
@ -89,7 +87,6 @@ void main() {
() { () {
gameFlowController.onNewState(GameState.initial()); gameFlowController.onNewState(GameState.initial());
verify(backboard.waitingMode).called(1);
verify(cameraController.focusOnGame).called(1); verify(cameraController.focusOnGame).called(1);
verify(() => overlays.remove(PinballGame.playButtonOverlay)) verify(() => overlays.remove(PinballGame.playButtonOverlay))
.called(1); .called(1);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

@ -21,9 +21,8 @@ void main() {
Assets.images.android.bumper.b.dimmed.keyName, Assets.images.android.bumper.b.dimmed.keyName,
Assets.images.android.bumper.cow.lit.keyName, Assets.images.android.bumper.cow.lit.keyName,
Assets.images.android.bumper.cow.dimmed.keyName, Assets.images.android.bumper.cow.dimmed.keyName,
Assets.images.backboard.backboardScores.keyName, Assets.images.backboard.marquee.keyName,
Assets.images.backboard.backboardGameOver.keyName, Assets.images.backboard.displayDivider.keyName,
Assets.images.backboard.display.keyName,
Assets.images.boardBackground.keyName, Assets.images.boardBackground.keyName,
Assets.images.ball.ball.keyName, Assets.images.ball.ball.keyName,
Assets.images.ball.flameEffect.keyName, Assets.images.ball.flameEffect.keyName,

Loading…
Cancel
Save