From 6889a47e59c3449632c19dacebe1c8a9d94a0139 Mon Sep 17 00:00:00 2001 From: Erick Date: Fri, 11 Mar 2022 15:23:32 -0300 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> --- lib/game/bloc/game_state.dart | 2 +- lib/game/components/bonus_letter.dart | 17 +++++++---------- test/game/components/bonus_letter_test.dart | 6 +++--- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/game/bloc/game_state.dart b/lib/game/bloc/game_state.dart index fa948320..e9a7418f 100644 --- a/lib/game/bloc/game_state.dart +++ b/lib/game/bloc/game_state.dart @@ -50,7 +50,7 @@ class GameState extends Equatable { bool get isLastBall => balls == 1; /// Shortcut method to check if the given [i] - /// is activated on the state + /// is activated. bool isLetterActivated(int i) => activatedBonusLetters.contains(i); diff --git a/lib/game/components/bonus_letter.dart b/lib/game/components/bonus_letter.dart index 4dbdd42e..cc17e0dd 100644 --- a/lib/game/components/bonus_letter.dart +++ b/lib/game/components/bonus_letter.dart @@ -8,9 +8,8 @@ import 'package:flutter/material.dart'; import 'package:pinball/game/game.dart'; /// {@template bonus_letter} -/// A pass through, [BodyType.static] component, part of -/// a word bonus, which will active its letter once a ball -/// pass through it +/// [BodyType.static] sensor component, part of a word bonus, +/// which will activate its letter after contact with a [Ball]. /// {@endtemplate} class BonusLetter extends BodyComponent with BlocComponent { @@ -25,7 +24,7 @@ class BonusLetter extends BodyComponent paint = Paint()..color = _disableColor; } - /// The area size of this bonus letter + /// The area size of this [BonusLetter]. static final areaSize = Vector2.all(4); static const _activeColor = Colors.green; @@ -76,18 +75,16 @@ class BonusLetter extends BodyComponent void onNewState(GameState state) { final isActive = state.isLetterActivated(_index); - final color = isActive ? _activeColor : _disableColor; - add( ColorEffect( - color, + isActive ? _activeColor : _disableColor, const Offset(0, 1), 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() { final isActive = state?.isLetterActivated(_index) ?? false; if (!isActive) { @@ -96,8 +93,8 @@ class BonusLetter extends BodyComponent } } -/// Handles contact for [Ball] and [BonusLetter], which trigger [BonusLetter] -/// activate method. +/// Triggers [activate] method when a [BonusLetter] and a [Ball] come in +/// contact. class BonusLetterBallContactCallback extends ContactCallback { @override diff --git a/test/game/components/bonus_letter_test.dart b/test/game/components/bonus_letter_test.dart index b0a7513f..9124bc53 100644 --- a/test/game/components/bonus_letter_test.dart +++ b/test/game/components/bonus_letter_test.dart @@ -136,7 +136,7 @@ void main() { ); tester.widgetTest( - "don't add BonusLetterActivated to GameBloc when is already activated", + "doesn't add BonusLetterActivated to GameBloc when already activated", (game, tester) async { const state = GameState( score: 0, @@ -159,7 +159,7 @@ void main() { ); tester.widgetTest( - 'adds a ColorEffect when it gets activated', + 'adds a ColorEffect', (game, tester) async { await game.ready(); await tester.pump(); @@ -184,7 +184,7 @@ void main() { ); 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 { await game.ready(); await tester.pump();