refactor: included BonusBallController

pull/116/head
alestiago 4 years ago
parent 79687c8ea3
commit 5db0c83581

@ -28,19 +28,19 @@ class ControlledBall extends Ball with Controls<BallController> {
ControlledBall.bonus({ ControlledBall.bonus({
required PinballTheme theme, required PinballTheme theme,
}) : super(baseColor: theme.characterTheme.ballColor) { }) : super(baseColor: theme.characterTheme.ballColor) {
controller = BallController(this); controller = BonusBallController(this);
} }
/// [Ball] used in [DebugPinballGame]. /// [Ball] used in [DebugPinballGame].
ControlledBall.debug() : super(baseColor: const Color(0xFFFF0000)) { ControlledBall.debug() : super(baseColor: const Color(0xFFFF0000)) {
controller = BallController(this); controller = BonusBallController(this);
} }
} }
/// {@template ball_controller} /// {@template ball_controller}
/// Controller attached to a [Ball] that handles its game related logic. /// Controller attached to a [Ball] that handles its game related logic.
/// {@endtemplate} /// {@endtemplate}
class BallController extends ComponentController<Ball> { abstract class BallController extends ComponentController<Ball> {
/// {@macro ball_controller} /// {@macro ball_controller}
BallController(Ball ball) : super(ball); BallController(Ball ball) : super(ball);
@ -50,7 +50,19 @@ class BallController extends ComponentController<Ball> {
/// Triggered by [BottomWallBallContactCallback] when the [Ball] falls into /// Triggered by [BottomWallBallContactCallback] when the [Ball] falls into
/// a [BottomWall]. /// a [BottomWall].
/// {@endtemplate} /// {@endtemplate}
@mustCallSuper void lost();
}
/// {@template bonus_ball_controller}
/// {@macro ball_controller}
///
/// A [BonusBallController] doesn't change the [GameState.balls] count.
/// {@endtemplate}
class BonusBallController extends BallController {
/// {@macro bonus_ball_controller}
BonusBallController(Ball<Forge2DGame> component) : super(component);
@override
void lost() { void lost() {
component.shouldRemove = true; component.shouldRemove = true;
} }
@ -68,8 +80,6 @@ class LaunchedBallController extends BallController
/// {@macro ball_controller_lost} /// {@macro ball_controller_lost}
@override @override
void lost() { void lost() {
super.lost();
final bloc = gameRef.read<GameBloc>()..add(const BallLost()); final bloc = gameRef.read<GameBloc>()..add(const BallLost());
// TODO(alestiago): Consider the use of onNewState instead. // TODO(alestiago): Consider the use of onNewState instead.

@ -15,7 +15,7 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(PinballGameTest.create); final flameTester = FlameTester(PinballGameTest.create);
group('BallController', () { group('BonusBallController', () {
late Ball ball; late Ball ball;
setUp(() { setUp(() {
@ -26,7 +26,7 @@ void main() {
'lost removes ball', 'lost removes ball',
(game) async { (game) async {
await game.add(ball); await game.add(ball);
final controller = BallController(ball); final controller = BonusBallController(ball);
await ball.add(controller); await ball.add(controller);
await game.ready(); await game.ready();
@ -118,7 +118,7 @@ void main() {
bonusHistory: [], bonusHistory: [],
), ),
); );
final controller = BallController(ball); final controller = LaunchedBallController(ball);
await ball.add(controller); await ball.add(controller);
await game.add(ball); await game.add(ball);
await game.ready(); await game.ready();

Loading…
Cancel
Save