feat: add icon to initials input

pull/209/head
Allison Ryan 3 years ago
parent 7c931b9c4b
commit ff1a9eab80

@ -32,6 +32,8 @@ class GameFlowController extends ComponentController<PinballGame>
// next page // next page
component.firstChild<Backboard>()?.gameOverMode( component.firstChild<Backboard>()?.gameOverMode(
score: state?.score ?? 0, score: state?.score ?? 0,
characterIconPath:
component.theme.characterTheme.leaderboardIcon.keyName,
); );
component.firstChild<CameraController>()?.focusOnBackboard(); component.firstChild<CameraController>()?.focusOnBackboard();
} }

@ -12,5 +12,5 @@ class PinballFonts {
static final String pixeloidMono = _prefixFont(FontFamily.pixeloidMono); static final String pixeloidMono = _prefixFont(FontFamily.pixeloidMono);
/// Sans variation of the Pixeloid font /// Sans variation of the Pixeloid font
static final String pixeloidSans = _prefixFont(FontFamily.pixeloidMono); static final String pixeloidSans = _prefixFont(FontFamily.pixeloidSans);
} }

@ -34,12 +34,14 @@ class Backboard extends PositionComponent with HasGameRef {
/// Returns a [Backboard] initialized in the game over mode /// Returns a [Backboard] initialized in the game over mode
factory Backboard.gameOver({ factory Backboard.gameOver({
required Vector2 position, required Vector2 position,
required String characterIconPath,
required int score, required int score,
required BackboardOnSubmit onSubmit, required BackboardOnSubmit onSubmit,
}) { }) {
return Backboard(position: position) return Backboard(position: position)
..gameOverMode( ..gameOverMode(
score: score, score: score,
characterIconPath: characterIconPath,
onSubmit: onSubmit, onSubmit: onSubmit,
); );
} }
@ -62,12 +64,14 @@ class Backboard extends PositionComponent with HasGameRef {
/// Puts the Backboard in game over mode, where the score input is shown. /// Puts the Backboard in game over mode, where the score input is shown.
Future<void> gameOverMode({ Future<void> gameOverMode({
required int score, required int score,
required String characterIconPath,
BackboardOnSubmit? onSubmit, BackboardOnSubmit? onSubmit,
}) async { }) async {
children.removeWhere((_) => true); children.removeWhere((_) => true);
await add( await add(
BackboardGameOver( BackboardGameOver(
score: score, score: score,
characterIconPath: characterIconPath,
onSubmit: onSubmit, onSubmit: onSubmit,
), ),
); );

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:math'; import 'dart:math';
import 'package:flame/assets.dart';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
@ -18,11 +19,14 @@ class BackboardGameOver extends PositionComponent with HasGameRef {
/// {@macro backboard_game_over} /// {@macro backboard_game_over}
BackboardGameOver({ BackboardGameOver({
required int score, required int score,
required String characterIconPath,
BackboardOnSubmit? onSubmit, BackboardOnSubmit? onSubmit,
}) : _score = score, }) : _score = score,
_characterIconPath = characterIconPath,
_onSubmit = onSubmit; _onSubmit = onSubmit;
final int _score; final int _score;
final String _characterIconPath;
final BackboardOnSubmit? _onSubmit; final BackboardOnSubmit? _onSubmit;
@override @override
@ -30,7 +34,6 @@ class BackboardGameOver extends PositionComponent with HasGameRef {
final backgroundSprite = await gameRef.loadSprite( final backgroundSprite = await gameRef.loadSprite(
Assets.images.backboard.backboardGameOver.keyName, Assets.images.backboard.backboardGameOver.keyName,
); );
unawaited( unawaited(
add( add(
SpriteComponent( SpriteComponent(
@ -44,7 +47,6 @@ class BackboardGameOver extends PositionComponent with HasGameRef {
final displaySprite = await gameRef.loadSprite( final displaySprite = await gameRef.loadSprite(
Assets.images.backboard.display.keyName, Assets.images.backboard.display.keyName,
); );
unawaited( unawaited(
add( add(
SpriteComponent( SpriteComponent(
@ -60,20 +62,35 @@ class BackboardGameOver extends PositionComponent with HasGameRef {
add( add(
TextComponent( TextComponent(
text: _score.formatScore(), text: _score.formatScore(),
position: Vector2(-22, -46.5), position: Vector2(-34, -45),
anchor: Anchor.center, anchor: Anchor.centerLeft,
textRenderer: Backboard.textPaint, textRenderer: Backboard.textPaint,
), ),
), ),
); );
final characterIconSprite = await Sprite.load(
_characterIconPath,
images: Images(prefix: ''),
);
unawaited(
add(
SpriteComponent(
sprite: characterIconSprite,
size: characterIconSprite.originalSize / 10,
anchor: Anchor.center,
position: Vector2(18.4, -45),
),
),
);
for (var i = 0; i < 3; i++) { for (var i = 0; i < 3; i++) {
unawaited( unawaited(
add( add(
BackboardLetterPrompt( BackboardLetterPrompt(
position: Vector2( position: Vector2(
20 + (6 * i).toDouble(), 24.3 + (4.5 * i),
-46.5, -45,
), ),
hasFocus: i == 0, hasFocus: i == 0,
), ),

@ -35,11 +35,11 @@ class BackboardLetterPrompt extends PositionComponent {
Future<void> onLoad() async { Future<void> onLoad() async {
_underscore = RectangleComponent( _underscore = RectangleComponent(
size: Vector2( size: Vector2(
4, 3.8,
1.2, 0.8,
), ),
anchor: Anchor.center, anchor: Anchor.center,
position: Vector2(0, 4), position: Vector2(-0.3, 4),
); );
unawaited(add(_underscore)); unawaited(add(_underscore));

@ -16,6 +16,8 @@ dependencies:
intl: ^0.17.0 intl: ^0.17.0
pinball_flame: pinball_flame:
path: ../pinball_flame path: ../pinball_flame
pinball_theme:
path: ../pinball_theme
dev_dependencies: dev_dependencies:

@ -4,13 +4,25 @@ import 'package:pinball_components/pinball_components.dart';
import 'package:sandbox/common/common.dart'; import 'package:sandbox/common/common.dart';
class BackboardGameOverGame extends BasicKeyboardGame { class BackboardGameOverGame extends BasicKeyboardGame {
BackboardGameOverGame(this.score); BackboardGameOverGame(this.score, this.character);
static const info = ''' static const info = '''
Simple example showing the waiting mode of the backboard. Simple example showing the game over mode of the backboard.
- Select a character to update the character icon.
'''; ''';
final int score; final int score;
final String character;
final characterIconPaths = <String, String>{
'Dash': 'packages/pinball_theme/assets/images/dash/leaderboard_icon.png',
'Sparky':
'packages/pinball_theme/assets/images/sparky/leaderboard_icon.png',
'Android':
'packages/pinball_theme/assets/images/android/leaderboard_icon.png',
'Dino': 'packages/pinball_theme/assets/images/dino/leaderboard_icon.png',
};
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
@ -22,6 +34,7 @@ class BackboardGameOverGame extends BasicKeyboardGame {
Backboard.gameOver( Backboard.gameOver(
position: Vector2(0, 20), position: Vector2(0, 20),
score: score, score: score,
characterIconPath: characterIconPaths[character]!,
onSubmit: (initials) { onSubmit: (initials) {
add( add(
ScoreText( ScoreText(

@ -5,6 +5,7 @@ import 'package:sandbox/stories/backboard/game_over.dart';
import 'package:sandbox/stories/backboard/waiting.dart'; import 'package:sandbox/stories/backboard/waiting.dart';
void addBackboardStories(Dashbook dashbook) { void addBackboardStories(Dashbook dashbook) {
final characters = ['Dash', 'Sparky', 'Android', 'Dino'];
dashbook.storiesOf('Backboard') dashbook.storiesOf('Backboard')
..add( ..add(
'Waiting mode', 'Waiting mode',
@ -18,7 +19,12 @@ void addBackboardStories(Dashbook dashbook) {
'Game over', 'Game over',
(context) => GameWidget( (context) => GameWidget(
game: BackboardGameOverGame( game: BackboardGameOverGame(
context.numberProperty('score', 9000000000).toInt(), context.numberProperty('Score', 9000000000).toInt(),
context.listProperty(
'Character',
characters.first,
characters,
),
), ),
), ),
codeLink: buildSourceLink('backboard/game_over.dart'), codeLink: buildSourceLink('backboard/game_over.dart'),

@ -64,6 +64,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.0" version: "1.0.0"
equatable:
dependency: transitive
description:
name: equatable
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
@ -247,6 +254,13 @@ packages:
relative: true relative: true
source: path source: path
version: "1.0.0+1" version: "1.0.0+1"
pinball_theme:
dependency: transitive
description:
path: "../../pinball_theme"
relative: true
source: path
version: "1.0.0+1"
platform: platform:
dependency: transitive dependency: transitive
description: description:

@ -12,6 +12,8 @@ import '../../helpers/helpers.dart';
void main() { void main() {
group('Backboard', () { group('Backboard', () {
final tester = FlameTester(KeyboardTestGame.new); final tester = FlameTester(KeyboardTestGame.new);
const characterIconPath =
'packages/pinball_theme/assets/images/dash/leaderboard_icon.png';
group('on waitingMode', () { group('on waitingMode', () {
tester.testGameWidget( tester.testGameWidget(
@ -39,6 +41,7 @@ void main() {
final backboard = Backboard.gameOver( final backboard = Backboard.gameOver(
position: Vector2(0, 15), position: Vector2(0, 15),
score: 1000, score: 1000,
characterIconPath: characterIconPath,
onSubmit: (_) {}, onSubmit: (_) {},
); );
await game.ensureAdd(backboard); await game.ensureAdd(backboard);
@ -52,7 +55,6 @@ void main() {
(component) => (component) =>
component is TextComponent && component.text == '1,000', component is TextComponent && component.text == '1,000',
); );
expect(score, isNotNull); expect(score, isNotNull);
}, },
); );
@ -63,6 +65,7 @@ void main() {
final backboard = Backboard.gameOver( final backboard = Backboard.gameOver(
position: Vector2(0, 15), position: Vector2(0, 15),
score: 1000, score: 1000,
characterIconPath: characterIconPath,
onSubmit: (_) {}, onSubmit: (_) {},
); );
await game.ensureAdd(backboard); await game.ensureAdd(backboard);
@ -106,6 +109,7 @@ void main() {
final backboard = Backboard.gameOver( final backboard = Backboard.gameOver(
position: Vector2(0, 15), position: Vector2(0, 15),
score: 1000, score: 1000,
characterIconPath: characterIconPath,
onSubmit: (value) { onSubmit: (value) {
submitedInitials = value; submitedInitials = value;
}, },

@ -5,6 +5,7 @@ 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_components/pinball_components.dart';
import 'package:pinball_theme/pinball_theme.dart';
import '../../helpers/helpers.dart'; import '../../helpers/helpers.dart';
@ -43,6 +44,7 @@ void main() {
when( when(
() => backboard.gameOverMode( () => backboard.gameOverMode(
score: any(named: 'score'), score: any(named: 'score'),
characterIconPath: any(named: 'characterIconPath'),
onSubmit: any(named: 'onSubmit'), onSubmit: any(named: 'onSubmit'),
), ),
).thenAnswer((_) async {}); ).thenAnswer((_) async {});
@ -55,6 +57,8 @@ void main() {
when(game.firstChild<Backboard>).thenReturn(backboard); when(game.firstChild<Backboard>).thenReturn(backboard);
when(game.firstChild<CameraController>).thenReturn(cameraController); when(game.firstChild<CameraController>).thenReturn(cameraController);
when(() => game.overlays).thenReturn(overlays); when(() => game.overlays).thenReturn(overlays);
when(() => game.theme)
.thenReturn(PinballTheme(characterTheme: DashTheme()));
}); });
test( test(
@ -71,6 +75,7 @@ void main() {
verify( verify(
() => backboard.gameOverMode( () => backboard.gameOverMode(
score: 0, score: 0,
characterIconPath: any(named: 'characterIconPath'),
onSubmit: any(named: 'onSubmit'), onSubmit: any(named: 'onSubmit'),
), ),
).called(1); ).called(1);

Loading…
Cancel
Save