chore: properties renamed and removed unused

pull/213/head
RuiAlonso 3 years ago
parent 37196c8b2f
commit 82f67ca44a

@ -19,14 +19,14 @@ class GameBloc extends Bloc<GameEvent, GameState> {
void _onBallLost(BallLost event, Emitter emit) { void _onBallLost(BallLost event, Emitter emit) {
var score = state.score; var score = state.score;
var multiplier = state.multiplier; var multiplier = state.multiplier;
var ballsLeft = event.balls; var ballsLeft = event.ballsLeft;
var rounds = state.rounds; var roundsLeft = state.rounds;
if (ballsLeft < 1) { if (ballsLeft < 1) {
score = score * state.multiplier; score = score * state.multiplier;
multiplier = 1; multiplier = 1;
ballsLeft = 1; ballsLeft = 1;
rounds = state.rounds - 1; roundsLeft = state.rounds - 1;
} }
emit( emit(
@ -34,7 +34,7 @@ class GameBloc extends Bloc<GameEvent, GameState> {
score: score, score: score,
multiplier: multiplier, multiplier: multiplier,
balls: ballsLeft, balls: ballsLeft,
rounds: rounds, rounds: roundsLeft,
), ),
); );
} }

@ -13,13 +13,13 @@ abstract class GameEvent extends Equatable {
class BallLost extends GameEvent { class BallLost extends GameEvent {
/// {@macro ball_lost_game_event} /// {@macro ball_lost_game_event}
const BallLost({ const BallLost({
required this.balls, required this.ballsLeft,
}) : assert(balls >= 0, "Balls left can't be negative"); }) : assert(ballsLeft >= 0, "Balls left can't be negative");
final int balls; final int ballsLeft;
@override @override
List<Object?> get props => [balls]; List<Object?> get props => [ballsLeft];
} }
/// {@template scored_game_event} /// {@template scored_game_event}

@ -36,7 +36,7 @@ class ControlledBall extends Ball with Controls<BallController> {
/// [Ball] used in [DebugPinballGame]. /// [Ball] used in [DebugPinballGame].
ControlledBall.debug() : super(baseColor: const Color(0xFFFF0000)) { ControlledBall.debug() : super(baseColor: const Color(0xFFFF0000)) {
controller = DebugBallController(this); controller = BallController(this);
priority = RenderPriority.ballOnBoard; priority = RenderPriority.ballOnBoard;
} }
} }
@ -77,12 +77,6 @@ class BallController extends ComponentController<Ball>
void onRemove() { void onRemove() {
super.onRemove(); super.onRemove();
final remainingBalls = gameRef.children.whereType<Ball>().length; final remainingBalls = gameRef.children.whereType<Ball>().length;
gameRef.read<GameBloc>().add(BallLost(balls: remainingBalls)); gameRef.read<GameBloc>().add(BallLost(ballsLeft: remainingBalls));
}
} }
/// {@macro ball_controller}
class DebugBallController extends BallController {
/// {@macro ball_controller}
DebugBallController(Ball<Forge2DGame> component) : super(component);
} }

@ -181,11 +181,8 @@ class _DebugGameBallsController extends _GameBallsController {
@override @override
bool listenWhen(GameState? previousState, GameState newState) { bool listenWhen(GameState? previousState, GameState newState) {
final noBallsLeft = component final noBallsLeft =
.descendants() component.descendants().whereType<ControlledBall>().isEmpty;
.whereType<ControlledBall>()
.where((ball) => ball.controller is! DebugBallController)
.isEmpty;
final canBallRespawn = newState.balls > 0; final canBallRespawn = newState.balls > 0;
return noBallsLeft && canBallRespawn; return noBallsLeft && canBallRespawn;

@ -16,7 +16,7 @@ void main() {
'decreases number of balls', 'decreases number of balls',
build: GameBloc.new, build: GameBloc.new,
act: (bloc) { act: (bloc) {
bloc.add(const BallLost(balls: 0)); bloc.add(const BallLost(ballsLeft: 0));
}, },
expect: () => [ expect: () => [
const GameState( const GameState(
@ -41,7 +41,7 @@ void main() {
bonusHistory: [], bonusHistory: [],
), ),
act: (bloc) { act: (bloc) {
bloc.add(const BallLost(balls: 0)); bloc.add(const BallLost(ballsLeft: 0));
}, },
expect: () => [ expect: () => [
isA<GameState>() isA<GameState>()
@ -62,7 +62,7 @@ void main() {
bonusHistory: [], bonusHistory: [],
), ),
act: (bloc) { act: (bloc) {
bloc.add(const BallLost(balls: 0)); bloc.add(const BallLost(ballsLeft: 0));
}, },
expect: () => [ expect: () => [
isA<GameState>() isA<GameState>()
@ -104,7 +104,7 @@ void main() {
build: GameBloc.new, build: GameBloc.new,
act: (bloc) { act: (bloc) {
for (var i = 0; i < bloc.state.rounds; i++) { for (var i = 0; i < bloc.state.rounds; i++) {
bloc.add(const BallLost(balls: 0)); bloc.add(const BallLost(ballsLeft: 0));
} }
bloc.add(const Scored(points: 2)); bloc.add(const Scored(points: 2));
}, },
@ -191,7 +191,7 @@ void main() {
build: GameBloc.new, build: GameBloc.new,
act: (bloc) { act: (bloc) {
for (var i = 0; i < bloc.state.rounds; i++) { for (var i = 0; i < bloc.state.rounds; i++) {
bloc.add(const BallLost(balls: 0)); bloc.add(const BallLost(ballsLeft: 0));
} }
bloc.add(const MultiplierIncreased()); bloc.add(const MultiplierIncreased());
}, },

@ -7,17 +7,17 @@ void main() {
group('GameEvent', () { group('GameEvent', () {
group('BallLost', () { group('BallLost', () {
test('can be instantiated', () { test('can be instantiated', () {
expect(const BallLost(balls: 1), isNotNull); expect(const BallLost(ballsLeft: 1), isNotNull);
}); });
test('supports value equality', () { test('supports value equality', () {
expect( expect(
BallLost(balls: 1), BallLost(ballsLeft: 1),
equals(const BallLost(balls: 1)), equals(const BallLost(ballsLeft: 1)),
); );
expect( expect(
BallLost(balls: 2), BallLost(ballsLeft: 2),
isNot(equals(const BallLost(balls: 1))), isNot(equals(const BallLost(ballsLeft: 1))),
); );
}); });
}); });

@ -62,7 +62,7 @@ void main() {
controller.lost(); controller.lost();
}, },
verify: (game, tester) async { verify: (game, tester) async {
verify(() => gameBloc.add(const BallLost(balls: 0))).called(1); verify(() => gameBloc.add(const BallLost(ballsLeft: 0))).called(1);
}, },
); );

Loading…
Cancel
Save