refactor: renamed GoogleLetterState

pull/286/head
alestiago 3 years ago
parent f78edd3bb6
commit 0dcfacea85

@ -17,7 +17,7 @@ class GoogleWordBonusBehavior extends Component
// https://github.com/flame-engine/flame/pull/1538 // https://github.com/flame-engine/flame/pull/1538
letter.bloc.stream.listen((_) { letter.bloc.stream.listen((_) {
final achievedBonus = googleLetters final achievedBonus = googleLetters
.every((letter) => letter.bloc.state == GoogleLetterState.active); .every((letter) => letter.bloc.state == GoogleLetterState.lit);
if (achievedBonus) { if (achievedBonus) {
gameRef.audio.googleBonus(); gameRef.audio.googleBonus();

@ -5,13 +5,13 @@ import 'package:bloc/bloc.dart';
part 'google_letter_state.dart'; part 'google_letter_state.dart';
class GoogleLetterCubit extends Cubit<GoogleLetterState> { class GoogleLetterCubit extends Cubit<GoogleLetterState> {
GoogleLetterCubit() : super(GoogleLetterState.inactive); GoogleLetterCubit() : super(GoogleLetterState.dimmed);
void onBallContacted() { void onBallContacted() {
emit(GoogleLetterState.active); emit(GoogleLetterState.lit);
} }
void onReset() { void onReset() {
emit(GoogleLetterState.inactive); emit(GoogleLetterState.dimmed);
} }
} }

@ -1,10 +1,8 @@
// ignore_for_file: public_member_api_docs
part of 'google_letter_cubit.dart'; part of 'google_letter_cubit.dart';
/// Indicates the [GoogleLetterCubit]'s current state.
enum GoogleLetterState { enum GoogleLetterState {
/// A lit up letter. lit,
active, dimmed,
/// A dimmed letter.
inactive,
} }

@ -29,9 +29,9 @@ class GoogleLetter extends BodyComponent with InitialPosition {
children: [ children: [
_GoogleLetterSpriteGroupComponent( _GoogleLetterSpriteGroupComponent(
activeAssetPath: _GoogleLetterSpriteGroupComponent activeAssetPath: _GoogleLetterSpriteGroupComponent
.spritePaths[index][GoogleLetterState.active]!, .spritePaths[index][GoogleLetterState.lit]!,
inactiveAssetPath: _GoogleLetterSpriteGroupComponent inactiveAssetPath: _GoogleLetterSpriteGroupComponent
.spritePaths[index][GoogleLetterState.inactive]!, .spritePaths[index][GoogleLetterState.dimmed]!,
current: bloc.state, current: bloc.state,
), ),
GoogleLetterBallContactBehavior(), GoogleLetterBallContactBehavior(),
@ -96,33 +96,33 @@ class _GoogleLetterSpriteGroupComponent
static final spritePaths = <Map<GoogleLetterState, String>>[ static final spritePaths = <Map<GoogleLetterState, String>>[
{ {
GoogleLetterState.active: Assets.images.googleWord.letter1.active.keyName, GoogleLetterState.lit: Assets.images.googleWord.letter1.active.keyName,
GoogleLetterState.inactive: GoogleLetterState.dimmed:
Assets.images.googleWord.letter1.inactive.keyName, Assets.images.googleWord.letter1.inactive.keyName,
}, },
{ {
GoogleLetterState.active: Assets.images.googleWord.letter2.active.keyName, GoogleLetterState.lit: Assets.images.googleWord.letter2.active.keyName,
GoogleLetterState.inactive: GoogleLetterState.dimmed:
Assets.images.googleWord.letter2.inactive.keyName, Assets.images.googleWord.letter2.inactive.keyName,
}, },
{ {
GoogleLetterState.active: Assets.images.googleWord.letter3.active.keyName, GoogleLetterState.lit: Assets.images.googleWord.letter3.active.keyName,
GoogleLetterState.inactive: GoogleLetterState.dimmed:
Assets.images.googleWord.letter3.inactive.keyName, Assets.images.googleWord.letter3.inactive.keyName,
}, },
{ {
GoogleLetterState.active: Assets.images.googleWord.letter4.active.keyName, GoogleLetterState.lit: Assets.images.googleWord.letter4.active.keyName,
GoogleLetterState.inactive: GoogleLetterState.dimmed:
Assets.images.googleWord.letter4.inactive.keyName, Assets.images.googleWord.letter4.inactive.keyName,
}, },
{ {
GoogleLetterState.active: Assets.images.googleWord.letter5.active.keyName, GoogleLetterState.lit: Assets.images.googleWord.letter5.active.keyName,
GoogleLetterState.inactive: GoogleLetterState.dimmed:
Assets.images.googleWord.letter5.inactive.keyName, Assets.images.googleWord.letter5.inactive.keyName,
}, },
{ {
GoogleLetterState.active: Assets.images.googleWord.letter6.active.keyName, GoogleLetterState.lit: Assets.images.googleWord.letter6.active.keyName,
GoogleLetterState.inactive: GoogleLetterState.dimmed:
Assets.images.googleWord.letter6.inactive.keyName, Assets.images.googleWord.letter6.inactive.keyName,
}, },
]; ];
@ -133,10 +133,10 @@ class _GoogleLetterSpriteGroupComponent
parent.bloc.stream.listen((state) => current = state); parent.bloc.stream.listen((state) => current = state);
final sprites = { final sprites = {
GoogleLetterState.active: Sprite( GoogleLetterState.lit: Sprite(
gameRef.images.fromCache(_activeAssetPath), gameRef.images.fromCache(_activeAssetPath),
), ),
GoogleLetterState.inactive: Sprite( GoogleLetterState.dimmed: Sprite(
gameRef.images.fromCache(_inactiveAssetPath), gameRef.images.fromCache(_inactiveAssetPath),
), ),
}; };

@ -31,7 +31,7 @@ void main() {
whenListen( whenListen(
bloc, bloc,
const Stream<GoogleLetterState>.empty(), const Stream<GoogleLetterState>.empty(),
initialState: GoogleLetterState.active, initialState: GoogleLetterState.lit,
); );
final googleLetter = GoogleLetter.test(bloc: bloc); final googleLetter = GoogleLetter.test(bloc: bloc);

@ -10,14 +10,14 @@ void main() {
'onBallContacted emits active', 'onBallContacted emits active',
build: GoogleLetterCubit.new, build: GoogleLetterCubit.new,
act: (bloc) => bloc.onBallContacted(), act: (bloc) => bloc.onBallContacted(),
expect: () => [GoogleLetterState.active], expect: () => [GoogleLetterState.lit],
); );
blocTest<GoogleLetterCubit, GoogleLetterState>( blocTest<GoogleLetterCubit, GoogleLetterState>(
'onReset emits inactive', 'onReset emits inactive',
build: GoogleLetterCubit.new, build: GoogleLetterCubit.new,
act: (bloc) => bloc.onReset(), act: (bloc) => bloc.onReset(),
expect: () => [GoogleLetterState.inactive], expect: () => [GoogleLetterState.dimmed],
); );
}, },
); );

@ -108,7 +108,7 @@ void main() {
whenListen( whenListen(
bloc, bloc,
const Stream<GoogleLetterState>.empty(), const Stream<GoogleLetterState>.empty(),
initialState: GoogleLetterState.active, initialState: GoogleLetterState.lit,
); );
when(bloc.close).thenAnswer((_) async {}); when(bloc.close).thenAnswer((_) async {});
final googleLetter = GoogleLetter.test(bloc: bloc); final googleLetter = GoogleLetter.test(bloc: bloc);

Loading…
Cancel
Save