refactor: removed GoogleLetter public index

pull/176/head
alestiago 3 years ago
parent d001d8596e
commit e0fee4ad16

@ -53,21 +53,21 @@ class _GoogleWordController extends ComponentController<GoogleWord>
static const _googleWord = 'Google';
final Set<int> _activatedIndexes = <int>{};
final _activatedLetters = <GoogleLetter>{};
void activate(int index) {
if (!_activatedIndexes.add(index)) return;
void activate(GoogleLetter googleLetter) {
if (!_activatedLetters.add(googleLetter)) return;
component.children.whereType<GoogleLetter>().elementAt(index).activate();
googleLetter.activate();
final activatedBonus = _activatedIndexes.length == _googleWord.length;
final activatedBonus = _activatedLetters.length == _googleWord.length;
if (activatedBonus) {
gameRef.audio.googleBonus();
gameRef.read<GameBloc>().add(const BonusActivated(GameBonus.word));
component.children.whereType<GoogleLetter>().forEach(
(letter) => letter.deactivate(),
);
_activatedIndexes.clear();
_activatedLetters.clear();
}
}
}
@ -77,8 +77,9 @@ class _GoogleLetterBallContactCallback
extends ContactCallback<GoogleLetter, Ball> {
@override
void begin(GoogleLetter googleLetter, _, __) {
(googleLetter.parent! as GoogleWord)
.controller
.activate(googleLetter.index);
final parent = googleLetter.parent;
if (parent is GoogleWord) {
parent.controller.activate(googleLetter);
}
}
}

@ -9,14 +9,11 @@ import 'package:pinball_components/pinball_components.dart';
/// {@endtemplate}
class GoogleLetter extends BodyComponent with InitialPosition {
/// {@macro google_letter}
GoogleLetter(this.index)
GoogleLetter(int index)
: _sprite = _GoogleLetterSprite(
_GoogleLetterSprite.spritePaths[index],
);
/// Index of the letter in the "GOOGLE" word.
final int index;
final _GoogleLetterSprite _sprite;
/// Activates this [GoogleLetter].

@ -41,10 +41,6 @@ void main() {
final letters = googleWord.children.whereType<GoogleLetter>();
expect(letters.length, equals(word.length));
for (var index = 0; index < word.length; index++) {
expect(letters.elementAt(index).index, equals(index));
}
},
);

Loading…
Cancel
Save