Apply suggestions from code review

Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
pull/35/head
Erick 4 years ago committed by GitHub
parent 3787a12bb0
commit 6889a47e59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -50,7 +50,7 @@ class GameState extends Equatable {
bool get isLastBall => balls == 1; bool get isLastBall => balls == 1;
/// Shortcut method to check if the given [i] /// Shortcut method to check if the given [i]
/// is activated on the state /// is activated.
bool isLetterActivated(int i) => bool isLetterActivated(int i) =>
activatedBonusLetters.contains(i); activatedBonusLetters.contains(i);

@ -8,9 +8,8 @@ import 'package:flutter/material.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
/// {@template bonus_letter} /// {@template bonus_letter}
/// A pass through, [BodyType.static] component, part of /// [BodyType.static] sensor component, part of a word bonus,
/// a word bonus, which will active its letter once a ball /// which will activate its letter after contact with a [Ball].
/// pass through it
/// {@endtemplate} /// {@endtemplate}
class BonusLetter extends BodyComponent<PinballGame> class BonusLetter extends BodyComponent<PinballGame>
with BlocComponent<GameBloc, GameState> { with BlocComponent<GameBloc, GameState> {
@ -25,7 +24,7 @@ class BonusLetter extends BodyComponent<PinballGame>
paint = Paint()..color = _disableColor; paint = Paint()..color = _disableColor;
} }
/// The area size of this bonus letter /// The area size of this [BonusLetter].
static final areaSize = Vector2.all(4); static final areaSize = Vector2.all(4);
static const _activeColor = Colors.green; static const _activeColor = Colors.green;
@ -76,18 +75,16 @@ class BonusLetter extends BodyComponent<PinballGame>
void onNewState(GameState state) { void onNewState(GameState state) {
final isActive = state.isLetterActivated(_index); final isActive = state.isLetterActivated(_index);
final color = isActive ? _activeColor : _disableColor;
add( add(
ColorEffect( ColorEffect(
color, isActive ? _activeColor : _disableColor,
const Offset(0, 1), const Offset(0, 1),
EffectController(duration: 0.25), EffectController(duration: 0.25),
), ),
); );
} }
/// When called, will activate this letter, if still not activated /// Activates this [BonusLetter], if it's not already activated.
void activate() { void activate() {
final isActive = state?.isLetterActivated(_index) ?? false; final isActive = state?.isLetterActivated(_index) ?? false;
if (!isActive) { if (!isActive) {
@ -96,8 +93,8 @@ class BonusLetter extends BodyComponent<PinballGame>
} }
} }
/// Handles contact for [Ball] and [BonusLetter], which trigger [BonusLetter] /// Triggers [activate] method when a [BonusLetter] and a [Ball] come in
/// activate method. /// contact.
class BonusLetterBallContactCallback class BonusLetterBallContactCallback
extends ContactCallback<Ball, BonusLetter> { extends ContactCallback<Ball, BonusLetter> {
@override @override

@ -136,7 +136,7 @@ void main() {
); );
tester.widgetTest( tester.widgetTest(
"don't add BonusLetterActivated to GameBloc when is already activated", "doesn't add BonusLetterActivated to GameBloc when already activated",
(game, tester) async { (game, tester) async {
const state = GameState( const state = GameState(
score: 0, score: 0,
@ -159,7 +159,7 @@ void main() {
); );
tester.widgetTest( tester.widgetTest(
'adds a ColorEffect when it gets activated', 'adds a ColorEffect',
(game, tester) async { (game, tester) async {
await game.ready(); await game.ready();
await tester.pump(); await tester.pump();
@ -184,7 +184,7 @@ void main() {
); );
tester.widgetTest( tester.widgetTest(
'only listen when there an change on the letter status', 'only listens when there is a change on the letter status',
(game, tester) async { (game, tester) async {
await game.ready(); await game.ready();
await tester.pump(); await tester.pump();

Loading…
Cancel
Save