refactor: rename backbox

pull/319/head
Allison Ryan 3 years ago
parent f428cb2def
commit 4d775c8286

@ -1,25 +1,26 @@
import 'dart:async';
import 'package:flame/components.dart';
import 'package:pinball/game/components/backboard/displays/displays.dart';
import 'package:pinball/game/components/backbox/displays/displays.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball_components/pinball_components.dart';
/// {@template backboard}
/// The [Backboard] of the pinball machine.
/// {@template backbox}
/// The [Backbox] of the pinball machine.
/// {@endtemplate}
class Backboard extends PositionComponent with HasGameRef {
/// {@macro backboard}
Backboard()
class Backbox extends PositionComponent with HasGameRef {
/// {@macro backbox}
Backbox()
: super(
position: Vector2(0, -87),
anchor: Anchor.bottomCenter,
priority: RenderPriority.backboardMarquee,
children: [
_BackboardSpriteComponent(),
_BackboxSpriteComponent(),
],
);
/// Puts [InitialsInputDisplay] on the [Backboard].
/// Puts [InitialsInputDisplay] on the [Backbox].
Future<void> initialsInput({
required int score,
required String characterIconPath,
@ -36,8 +37,8 @@ class Backboard extends PositionComponent with HasGameRef {
}
}
class _BackboardSpriteComponent extends SpriteComponent with HasGameRef {
_BackboardSpriteComponent() : super(anchor: Anchor.bottomCenter);
class _BackboxSpriteComponent extends SpriteComponent with HasGameRef {
_BackboxSpriteComponent() : super(anchor: Anchor.bottomCenter);
@override
Future<void> onLoad() async {
@ -45,10 +46,10 @@ class _BackboardSpriteComponent extends SpriteComponent with HasGameRef {
final sprite = Sprite(
gameRef.images.fromCache(
Assets.images.backboard.marquee.keyName,
Assets.images.backbox.marquee.keyName,
),
);
this.sprite = sprite;
size = sprite.originalSize / 10;
size = sprite.originalSize / 20;
}
}

@ -270,7 +270,7 @@ class _DividerSpriteComponent extends SpriteComponent with HasGameRef {
Future<void> onLoad() async {
await super.onLoad();
final sprite = Sprite(
gameRef.images.fromCache(Assets.images.backboard.displayDivider.keyName),
gameRef.images.fromCache(Assets.images.backbox.displayDivider.keyName),
);
this.sprite = sprite;
size = sprite.originalSize / 20;

@ -45,49 +45,49 @@ class CameraController extends ComponentController<FlameGame> {
/// {@macro camera_controller}
CameraController(FlameGame component) : super(component) {
final gameZoom = component.size.y / 16;
final waitingBackboardZoom = component.size.y / 18;
final gameOverBackboardZoom = component.size.y / 10;
final waitingBackboxZoom = component.size.y / 18;
final gameOverBackboxZoom = component.size.y / 10;
gameFocus = FocusData(
zoom: gameZoom,
position: Vector2(0, -7.8),
);
waitingBackboardFocus = FocusData(
zoom: waitingBackboardZoom,
waitingBackboxFocus = FocusData(
zoom: waitingBackboxZoom,
position: Vector2(0, -112),
);
gameOverBackboardFocus = FocusData(
zoom: gameOverBackboardZoom,
gameOverBackboxFocus = FocusData(
zoom: gameOverBackboxZoom,
position: Vector2(0, -111),
);
// Game starts with the camera focused on the panel.
// Game starts with the camera focused on the [Backbox].
component.camera
..speed = 70
..snapToFocus(waitingBackboardFocus);
..snapToFocus(waitingBackboxFocus);
}
/// Holds the data for the game focus point.
late final FocusData gameFocus;
/// Holds the data for the waiting backboard focus point.
late final FocusData waitingBackboardFocus;
/// Holds the data for the waiting backbox focus point.
late final FocusData waitingBackboxFocus;
/// Holds the data for the game over backboard focus point.
late final FocusData gameOverBackboardFocus;
/// Holds the data for the game over backbox focus point.
late final FocusData gameOverBackboxFocus;
/// Move the camera focus to the game board.
void focusOnGame() {
component.add(component.camera.focusToCameraZoom(gameFocus));
}
/// Move the camera focus to the waiting backboard.
void focusOnWaitingBackboard() {
component.add(component.camera.focusToCameraZoom(waitingBackboardFocus));
/// Move the camera focus to the waiting backbox.
void focusOnWaitingBackbox() {
component.add(component.camera.focusToCameraZoom(waitingBackboxFocus));
}
/// Move the camera focus to the game over backboard.
void focusOnGameOverBackboard() {
component.add(component.camera.focusToCameraZoom(gameOverBackboardFocus));
/// Move the camera focus to the game over backbox.
void focusOnGameOverBackbox() {
component.add(component.camera.focusToCameraZoom(gameOverBackboxFocus));
}
}

@ -1,5 +1,5 @@
export 'android_acres.dart';
export 'backboard/backboard.dart';
export 'backbox/backbox.dart';
export 'bottom_group.dart';
export 'camera_controller.dart';
export 'controlled_ball.dart';

@ -29,11 +29,11 @@ class GameFlowController extends ComponentController<PinballGame>
void initialsInput() {
// TODO(erickzanardo): implement score submission and "navigate" to the
// next page
component.firstChild<Backboard>()?.initialsInput(
component.firstChild<Backbox>()?.initialsInput(
score: state?.score ?? 0,
characterIconPath: component.characterTheme.leaderboardIcon.keyName,
);
component.firstChild<CameraController>()?.focusOnGameOverBackboard();
component.firstChild<CameraController>()?.focusOnGameOverBackbox();
}
/// Puts the game in the playing state.

@ -96,8 +96,8 @@ extension PinballGameAssetsX on PinballGame {
images.load(components.Assets.images.sparky.bumper.b.inactive.keyName),
images.load(components.Assets.images.sparky.bumper.c.active.keyName),
images.load(components.Assets.images.sparky.bumper.c.inactive.keyName),
images.load(components.Assets.images.backboard.marquee.keyName),
images.load(components.Assets.images.backboard.displayDivider.keyName),
images.load(components.Assets.images.backbox.marquee.keyName),
images.load(components.Assets.images.backbox.displayDivider.keyName),
images.load(components.Assets.images.googleWord.letter1.keyName),
images.load(components.Assets.images.googleWord.letter2.keyName),
images.load(components.Assets.images.googleWord.letter3.keyName),

@ -44,7 +44,7 @@ class PinballGame extends Forge2DGame
Future<void> onLoad() async {
unawaited(add(gameFlowController = GameFlowController(this)));
unawaited(add(CameraController(this)));
await add(Backboard());
await add(Backbox());
await add(BoardBackgroundSpriteComponent());
await add(Drain());
await add(BottomGroup());

Binary file not shown.

Before

Width:  |  Height:  |  Size: 820 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 KiB

@ -11,7 +11,7 @@ class $AssetsImagesGen {
const $AssetsImagesGen();
$AssetsImagesAndroidGen get android => const $AssetsImagesAndroidGen();
$AssetsImagesBackboardGen get backboard => const $AssetsImagesBackboardGen();
$AssetsImagesBackboxGen get backbox => const $AssetsImagesBackboxGen();
$AssetsImagesBallGen get ball => const $AssetsImagesBallGen();
$AssetsImagesBaseboardGen get baseboard => const $AssetsImagesBaseboardGen();
@ -46,16 +46,16 @@ class $AssetsImagesAndroidGen {
const $AssetsImagesAndroidSpaceshipGen();
}
class $AssetsImagesBackboardGen {
const $AssetsImagesBackboardGen();
class $AssetsImagesBackboxGen {
const $AssetsImagesBackboxGen();
/// File path: assets/images/backboard/display-divider.png
/// File path: assets/images/backbox/display-divider.png
AssetGenImage get displayDivider =>
const AssetGenImage('assets/images/backboard/display-divider.png');
const AssetGenImage('assets/images/backbox/display-divider.png');
/// File path: assets/images/backboard/marquee.png
/// File path: assets/images/backbox/marquee.png
AssetGenImage get marquee =>
const AssetGenImage('assets/images/backboard/marquee.png');
const AssetGenImage('assets/images/backbox/marquee.png');
}
class $AssetsImagesBallGen {

@ -72,7 +72,7 @@ flutter:
- assets/images/sparky/bumper/a/
- assets/images/sparky/bumper/b/
- assets/images/sparky/bumper/c/
- assets/images/backboard/
- assets/images/backbox/
- assets/images/google_word/
- assets/images/signpost/
- assets/images/multiplier/x2/

@ -1,139 +0,0 @@
// 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);
// },
// );
// });

@ -10,22 +10,22 @@ import 'package:pinball_theme/pinball_theme.dart' as theme;
import '../../../helpers/helpers.dart';
void main() {
group('Backboard', () {
group('Backbox', () {
final characterIconPath = theme.Assets.images.dash.leaderboardIcon.keyName;
final assets = [
characterIconPath,
Assets.images.backboard.marquee.keyName,
Assets.images.backboard.displayDivider.keyName,
Assets.images.backbox.marquee.keyName,
Assets.images.backbox.displayDivider.keyName,
];
final tester = FlameTester(() => EmptyPinballTestGame(assets: assets));
tester.test(
'loads correctly',
(game) async {
final backboard = Backboard();
await game.ensureAdd(backboard);
final backbox = Backbox();
await game.ensureAdd(backbox);
expect(game.children, contains(backboard));
expect(game.children, contains(backbox));
},
);
@ -36,38 +36,14 @@ void main() {
await game.images.loadAll(assets);
game.camera.zoom = 6;
game.camera.followVector2(Vector2(0, -130));
await game.ensureAdd(Backboard());
await game.ensureAdd(Backbox());
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'),
matchesGoldenFile('../golden/backbox/empty.png'),
);
},
);

@ -24,14 +24,14 @@ void main() {
test('correctly calculates the zooms', () async {
expect(controller.gameFocus.zoom.toInt(), equals(12));
expect(controller.waitingBackboardFocus.zoom.toInt(), equals(11));
expect(controller.waitingBackboxFocus.zoom.toInt(), equals(11));
});
test('correctly sets the initial zoom and position', () async {
expect(game.camera.zoom, equals(controller.waitingBackboardFocus.zoom));
expect(game.camera.zoom, equals(controller.waitingBackboxFocus.zoom));
expect(
game.camera.follow,
equals(controller.waitingBackboardFocus.position),
equals(controller.waitingBackboxFocus.position),
);
});
@ -60,18 +60,18 @@ void main() {
});
});
group('focusOnWaitingBackboard', () {
group('focusOnWaitingBackbox', () {
test('changes the zoom', () async {
controller.focusOnWaitingBackboard();
controller.focusOnWaitingBackbox();
await game.ready();
final zoom = game.firstChild<CameraZoom>();
expect(zoom, isNotNull);
expect(zoom?.value, equals(controller.waitingBackboardFocus.zoom));
expect(zoom?.value, equals(controller.waitingBackboxFocus.zoom));
});
test('moves the camera after the zoom is completed', () async {
controller.focusOnWaitingBackboard();
controller.focusOnWaitingBackbox();
await game.ready();
final cameraZoom = game.firstChild<CameraZoom>()!;
final future = cameraZoom.completed;
@ -85,18 +85,18 @@ void main() {
});
});
group('focusOnGameOverBackboard', () {
group('focusOnGameOverBackbox', () {
test('changes the zoom', () async {
controller.focusOnGameOverBackboard();
controller.focusOnGameOverBackbox();
await game.ready();
final zoom = game.firstChild<CameraZoom>();
expect(zoom, isNotNull);
expect(zoom?.value, equals(controller.gameOverBackboardFocus.zoom));
expect(zoom?.value, equals(controller.gameOverBackboxFocus.zoom));
});
test('moves the camera after the zoom is completed', () async {
controller.focusOnGameOverBackboard();
controller.focusOnGameOverBackbox();
await game.ready();
final cameraZoom = game.firstChild<CameraZoom>()!;
final future = cameraZoom.completed;

@ -29,38 +29,39 @@ void main() {
group('onNewState', () {
late PinballGame game;
late Backboard backboard;
late Backbox backbox;
late CameraController cameraController;
late GameFlowController gameFlowController;
late ActiveOverlaysNotifier overlays;
setUp(() {
game = MockPinballGame();
backboard = MockBackboard();
backbox = MockBackbox();
cameraController = MockCameraController();
gameFlowController = GameFlowController(game);
overlays = MockActiveOverlaysNotifier();
when(
() => backboard.initialsInput(
() => backbox.initialsInput(
score: any(named: 'score'),
characterIconPath: any(named: 'characterIconPath'),
onSubmit: any(named: 'onSubmit'),
),
).thenAnswer((_) async {});
when(cameraController.focusOnWaitingBackboard).thenAnswer((_) async {});
when(cameraController.focusOnWaitingBackbox).thenAnswer((_) async {});
when(cameraController.focusOnGame).thenAnswer((_) async {});
when(() => overlays.remove(any())).thenAnswer((_) => true);
when(game.firstChild<Backboard>).thenReturn(backboard);
when(game.firstChild<Backbox>).thenReturn(backbox);
when(game.firstChild<CameraController>).thenReturn(cameraController);
when(() => game.overlays).thenReturn(overlays);
when(() => game.characterTheme).thenReturn(DashTheme());
});
test(
'changes the backboard and camera correctly when the game is over',
'changes the backbox display and camera correctly '
'when the game is over',
() {
gameFlowController.onNewState(
GameState(
@ -72,18 +73,18 @@ void main() {
);
verify(
() => backboard.initialsInput(
() => backbox.initialsInput(
score: 0,
characterIconPath: any(named: 'characterIconPath'),
onSubmit: any(named: 'onSubmit'),
),
).called(1);
verify(cameraController.focusOnWaitingBackboard).called(1);
verify(cameraController.focusOnWaitingBackbox).called(1);
},
);
test(
'changes the backboard and camera correctly when it is not a game over',
'changes the backbox and camera correctly when it is not a game over',
() {
gameFlowController.onNewState(GameState.initial());

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

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

@ -82,7 +82,7 @@ class MockSparkyComputerSensor extends Mock implements SparkyComputerSensor {}
class MockAssetsManagerCubit extends Mock implements AssetsManagerCubit {}
class MockBackboard extends Mock implements Backboard {}
class MockBackbox extends Mock implements Backbox {}
class MockCameraController extends Mock implements CameraController {}

Loading…
Cancel
Save