You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pinball/lib/game/components/multipliers/behaviors/multipliers_behavior.dart

26 lines
826 B

feat: implemented `Multipliers` (#231) * feat: added multipliers * feat: added multipliers to sandbox * test: tests and golden tests for multipliers * feat: multipliers controller * fix: missed assets load * refactor: multiplier refactored and tested * refactor: changed sandbox for multipliers * feat: multiplier controller * refactor: moved assets to constructor at sandbox * test: coverage for multipliers * test: removed test * refactor: coverage for multiplier * test: coverage for multiplier * chore: multiplier doc * Update packages/pinball_components/sandbox/lib/stories/multipliers/multipliers_game.dart Co-authored-by: Alejandro Santiago <dev@alestiago.com> * chore: little code refactor, doc * refactor: multiplier creation refactored * test: fixed tests for multipliers * refactor: changed properties names * refactor: multipliers cubit * test: refactored tests for multipliers * refactored: sandbow for multipliers * refactor: multipliers controller * test: tests for multiplier behavior * chore: analysis errors * feat: multipliers behavior with multiplier from gamebloc * refactor: changed toggle to next at multipliers * test: coverage for cubit * refactor: refactored multipliers and coverage * refactor: sandbox * test: flamebloctester * Update lib/game/components/multipliers/multipliers.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update packages/pinball_components/lib/src/components/multiplier/cubit/multiplier_cubit.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/multipliers/multipliers.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update packages/pinball_components/lib/src/components/multiplier/cubit/multiplier_state.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update packages/pinball_components/lib/src/components/multiplier/cubit/multiplier_state.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/multipliers/behaviors/multipliers_behavior_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * test: fixed test names and golden files * test: golden tests * fix: fixed bloc bug for tests on multiplier behavior * chore: renamed rotation * chore: doc ignore * test: grouped * test: golden tests dir * Update packages/pinball_components/sandbox/lib/stories/multipliers/stories.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: moved extension for multiplier value * chore: multiplier extension equalsTo name * fixed: missed method rename Co-authored-by: Alejandro Santiago <dev@alestiago.com> Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
2 years ago
import 'package:flame/components.dart';
import 'package:flame_bloc/flame_bloc.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// Toggle each [Multiplier] when GameState.multiplier changes.
class MultipliersBehavior extends Component
with
HasGameRef<PinballGame>,
ParentIsA<Multipliers>,
BlocComponent<GameBloc, GameState> {
@override
bool listenWhen(GameState? previousState, GameState newState) {
return previousState?.multiplier != newState.multiplier;
}
@override
void onNewState(GameState state) {
final multipliers = parent.children.whereType<Multiplier>();
for (final multiplier in multipliers) {
multiplier.bloc.next(state.multiplier);
}
}
}