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

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

Loading…
Cancel
Save