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) {
var score = state.score;
var multiplier = state.multiplier;
var ballsLeft = event.balls;
var rounds = state.rounds;
var ballsLeft = event.ballsLeft;
var roundsLeft = state.rounds;
if (ballsLeft < 1) {
score = score * state.multiplier;
multiplier = 1;
ballsLeft = 1;
rounds = state.rounds - 1;
roundsLeft = state.rounds - 1;
}
emit(
@ -34,7 +34,7 @@ class GameBloc extends Bloc<GameEvent, GameState> {
score: score,
multiplier: multiplier,
balls: ballsLeft,
rounds: rounds,
rounds: roundsLeft,
),
);
}

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

@ -36,7 +36,7 @@ class ControlledBall extends Ball with Controls<BallController> {
/// [Ball] used in [DebugPinballGame].
ControlledBall.debug() : super(baseColor: const Color(0xFFFF0000)) {
controller = DebugBallController(this);
controller = BallController(this);
priority = RenderPriority.ballOnBoard;
}
}
@ -77,12 +77,6 @@ class BallController extends ComponentController<Ball>
void onRemove() {
super.onRemove();
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
bool listenWhen(GameState? previousState, GameState newState) {
final noBallsLeft = component
.descendants()
.whereType<ControlledBall>()
.where((ball) => ball.controller is! DebugBallController)
.isEmpty;
final noBallsLeft =
component.descendants().whereType<ControlledBall>().isEmpty;
final canBallRespawn = newState.balls > 0;
return noBallsLeft && canBallRespawn;

@ -16,7 +16,7 @@ void main() {
'decreases number of balls',
build: GameBloc.new,
act: (bloc) {
bloc.add(const BallLost(balls: 0));
bloc.add(const BallLost(ballsLeft: 0));
},
expect: () => [
const GameState(
@ -41,7 +41,7 @@ void main() {
bonusHistory: [],
),
act: (bloc) {
bloc.add(const BallLost(balls: 0));
bloc.add(const BallLost(ballsLeft: 0));
},
expect: () => [
isA<GameState>()
@ -62,7 +62,7 @@ void main() {
bonusHistory: [],
),
act: (bloc) {
bloc.add(const BallLost(balls: 0));
bloc.add(const BallLost(ballsLeft: 0));
},
expect: () => [
isA<GameState>()
@ -104,7 +104,7 @@ void main() {
build: GameBloc.new,
act: (bloc) {
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));
},
@ -191,7 +191,7 @@ void main() {
build: GameBloc.new,
act: (bloc) {
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());
},

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

@ -62,7 +62,7 @@ void main() {
controller.lost();
},
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