refactor: assign all priority values

pull/198/head
Allison Ryan 4 years ago
parent e2cc0784dc
commit db8d082d97

@ -42,7 +42,7 @@ class Board extends Component {
// TODO(alestiago): Consider renaming once entire Board is defined. // TODO(alestiago): Consider renaming once entire Board is defined.
class _BottomGroup extends Component { class _BottomGroup extends Component {
/// {@macro bottom_group} /// {@macro bottom_group}
_BottomGroup(); _BottomGroup() : super(priority: PinballPriority.bottomGroup);
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {

@ -18,7 +18,7 @@ class ControlledBall extends Ball with Controls<BallController> {
required PinballTheme theme, required PinballTheme theme,
}) : super(baseColor: theme.characterTheme.ballColor) { }) : super(baseColor: theme.characterTheme.ballColor) {
controller = BallController(this); controller = BallController(this);
priority = Ball.launchRampPriority; priority = PinballPriority.ballOnLaunchRamp;
} }
/// {@template bonus_ball} /// {@template bonus_ball}
@ -30,13 +30,13 @@ class ControlledBall extends Ball with Controls<BallController> {
required PinballTheme theme, required PinballTheme theme,
}) : super(baseColor: theme.characterTheme.ballColor) { }) : super(baseColor: theme.characterTheme.ballColor) {
controller = BallController(this); controller = BallController(this);
priority = Ball.boardPriority; priority = PinballPriority.ballOnBoard;
} }
/// [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 = DebugBallController(this);
priority = Ball.boardPriority; priority = PinballPriority.ballOnBoard;
} }
} }

@ -38,7 +38,7 @@ class PinballGame extends Forge2DGame
Future<void> onLoad() async { Future<void> onLoad() async {
_addContactCallbacks(); _addContactCallbacks();
unawaited(add(ScoreEffectController(this))); // unawaited(add(ScoreEffectController(this)));
unawaited(add(gameFlowController = GameFlowController(this))); unawaited(add(gameFlowController = GameFlowController(this)));
unawaited(add(CameraController(this))); unawaited(add(CameraController(this)));
unawaited(add(Backboard(position: Vector2(0, -88)))); unawaited(add(Backboard(position: Vector2(0, -88))));
@ -172,7 +172,7 @@ class DebugPinballGame extends PinballGame with TapDetector {
anchor: Anchor.center, anchor: Anchor.center,
) )
..position = Vector2(0, -7.8) ..position = Vector2(0, -7.8)
..priority = -2; ..priority = PinballPriority.background;
await add(spriteComponent); await add(spriteComponent);
} }

@ -20,7 +20,8 @@ class AlienBumper extends BodyComponent with InitialPosition {
_minorRadius = minorRadius, _minorRadius = minorRadius,
_activeAssetPath = activeAssetPath, _activeAssetPath = activeAssetPath,
_inactiveAssetPath = inactiveAssetPath, _inactiveAssetPath = inactiveAssetPath,
_spriteComponent = spriteComponent; _spriteComponent = spriteComponent,
super(priority: PinballPriority.alienBumper);
/// {@macro alien_bumper} /// {@macro alien_bumper}
AlienBumper.a() AlienBumper.a()

@ -22,21 +22,6 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
layer = Layer.board; layer = Layer.board;
} }
/// Render priority for the [Ball] while it's on the board.
static const int boardPriority = 0;
/// Render priority for the [Ball] while it's on the [SpaceshipRamp].
static const int spaceshipRampPriority = 4;
/// Render priority for the [Ball] while it's on the [Spaceship].
static const int spaceshipPriority = 4;
/// Render priority for the [Ball] while it's on the [SpaceshipRail].
static const int spaceshipRailPriority = 2;
/// Render priority for the [Ball] while it's on the [LaunchRamp].
static const int launchRampPriority = 0;
/// The size of the [Ball]. /// The size of the [Ball].
static final Vector2 size = Vector2.all(4.13); static final Vector2 size = Vector2.all(4.13);

@ -23,7 +23,7 @@ class Boundaries extends Forge2DBlueprint {
/// {@endtemplate bottom_boundary} /// {@endtemplate bottom_boundary}
class _BottomBoundary extends BodyComponent with InitialPosition { class _BottomBoundary extends BodyComponent with InitialPosition {
/// {@macro bottom_boundary} /// {@macro bottom_boundary}
_BottomBoundary() : super(priority: 2); _BottomBoundary() : super(priority: PinballPriority.bottomBoundary);
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDefs = <FixtureDef>[]; final fixturesDefs = <FixtureDef>[];
@ -88,7 +88,7 @@ class _BottomBoundarySpriteComponent extends SpriteComponent with HasGameRef {
/// {@endtemplate outer_boundary} /// {@endtemplate outer_boundary}
class _OuterBoundary extends BodyComponent with InitialPosition { class _OuterBoundary extends BodyComponent with InitialPosition {
/// {@macro outer_boundary} /// {@macro outer_boundary}
_OuterBoundary() : super(priority: -1); _OuterBoundary() : super(priority: PinballPriority.outerBoudary);
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDefs = <FixtureDef>[]; final fixturesDefs = <FixtureDef>[];

@ -12,10 +12,12 @@ import 'package:pinball_components/pinball_components.dart';
/// {@endtemplate} /// {@endtemplate}
class ChromeDino extends BodyComponent with InitialPosition { class ChromeDino extends BodyComponent with InitialPosition {
/// {@macro chrome_dino} /// {@macro chrome_dino}
ChromeDino() { ChromeDino()
: super(
// TODO(alestiago): Remove once sprites are defined. // TODO(alestiago): Remove once sprites are defined.
paint = Paint()..color = Colors.blue; paint: Paint()..color = Colors.blue,
} priority: PinballPriority.dino,
);
/// The size of the dinosaur mouth. /// The size of the dinosaur mouth.
static final size = Vector2(5, 2.5); static final size = Vector2(5, 2.5);

@ -10,6 +10,7 @@ class DashAnimatronic extends SpriteAnimationComponent with HasGameRef {
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
playing: false, playing: false,
priority: PinballPriority.dashAnimatronic,
); );
@override @override

@ -15,7 +15,8 @@ abstract class DashNestBumper extends BodyComponent with InitialPosition {
required SpriteComponent spriteComponent, required SpriteComponent spriteComponent,
}) : _activeAssetPath = activeAssetPath, }) : _activeAssetPath = activeAssetPath,
_inactiveAssetPath = inactiveAssetPath, _inactiveAssetPath = inactiveAssetPath,
_spriteComponent = spriteComponent; _spriteComponent = spriteComponent,
super(priority: PinballPriority.dashBumper);
final String _activeAssetPath; final String _activeAssetPath;
late final Sprite _activeSprite; late final Sprite _activeSprite;

@ -28,7 +28,7 @@ class DinoWalls extends Forge2DBlueprint {
/// {@endtemplate} /// {@endtemplate}
class _DinoTopWall extends BodyComponent with InitialPosition { class _DinoTopWall extends BodyComponent with InitialPosition {
///{@macro dino_top_wall} ///{@macro dino_top_wall}
_DinoTopWall() : super(priority: 1); _DinoTopWall() : super(priority: PinballPriority.dinoTopWall);
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[]; final fixturesDef = <FixtureDef>[];
@ -124,7 +124,7 @@ class _DinoTopWallSpriteComponent extends SpriteComponent with HasGameRef {
/// {@endtemplate} /// {@endtemplate}
class _DinoBottomWall extends BodyComponent with InitialPosition { class _DinoBottomWall extends BodyComponent with InitialPosition {
///{@macro dino_top_wall} ///{@macro dino_top_wall}
_DinoBottomWall() : super(priority: 1); _DinoBottomWall() : super(priority: PinballPriority.dinoBottomWall);
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[]; final fixturesDef = <FixtureDef>[];

@ -6,6 +6,9 @@ import 'package:pinball_components/pinball_components.dart';
/// A sign, found in the Flutter Forest. /// A sign, found in the Flutter Forest.
/// {@endtemplate} /// {@endtemplate}
class FlutterSignPost extends BodyComponent with InitialPosition { class FlutterSignPost extends BodyComponent with InitialPosition {
/// {@macro flutter_sign_post}
FlutterSignPost() : super(priority: PinballPriority.flutterSignPost);
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();

@ -42,7 +42,7 @@ class _LaunchRampBase extends BodyComponent with InitialPosition, Layered {
/// {@macro launch_ramp_base} /// {@macro launch_ramp_base}
_LaunchRampBase() _LaunchRampBase()
: super( : super(
priority: Ball.launchRampPriority - 1, priority: PinballPriority.launchRamp,
) { ) {
layer = Layer.launcher; layer = Layer.launcher;
} }
@ -148,7 +148,7 @@ class _LaunchRampForegroundRailing extends BodyComponent
/// {@macro launch_ramp_foreground_railing} /// {@macro launch_ramp_foreground_railing}
_LaunchRampForegroundRailing() _LaunchRampForegroundRailing()
: super( : super(
priority: Ball.launchRampPriority + 1, priority: PinballPriority.launchRampForegroundRailing,
) { ) {
layer = Layer.launcher; layer = Layer.launcher;
} }
@ -233,7 +233,7 @@ class _LaunchRampExit extends RampOpening {
super( super(
insideLayer: Layer.launcher, insideLayer: Layer.launcher,
orientation: RampOrientation.down, orientation: RampOrientation.down,
insidePriority: Ball.launchRampPriority, insidePriority: PinballPriority.ballOnLaunchRamp,
); );
final double _rotation; final double _rotation;

@ -14,7 +14,7 @@ class Plunger extends BodyComponent with InitialPosition {
required this.compressionDistance, required this.compressionDistance,
// TODO(ruimiguel): set to priority +1 over LaunchRamp once all priorities // TODO(ruimiguel): set to priority +1 over LaunchRamp once all priorities
// are fixed. // are fixed.
}) : super(priority: 0); }) : super(priority: PinballPriority.plunger);
/// Distance the plunger can lower. /// Distance the plunger can lower.
final double compressionDistance; final double compressionDistance;

@ -35,7 +35,7 @@ abstract class RampOpening extends BodyComponent with InitialPosition, Layered {
}) : _insideLayer = insideLayer, }) : _insideLayer = insideLayer,
_outsideLayer = outsideLayer ?? Layer.board, _outsideLayer = outsideLayer ?? Layer.board,
_insidePriority = insidePriority, _insidePriority = insidePriority,
_outsidePriority = outsidePriority ?? Ball.boardPriority { _outsidePriority = outsidePriority ?? PinballPriority.ballOnBoard {
layer = Layer.opening; layer = Layer.opening;
} }
final Layer _insideLayer; final Layer _insideLayer;

@ -18,7 +18,7 @@ class ScoreText extends TextComponent {
text: text, text: text,
position: position, position: position,
anchor: Anchor.center, anchor: Anchor.center,
priority: Ball.spaceshipRampPriority + 1, priority: PinballPriority.scoreText,
); );
late final Effect _effect; late final Effect _effect;

@ -58,7 +58,7 @@ class Slingshot extends BodyComponent with InitialPosition {
}) : _length = length, }) : _length = length,
_angle = angle, _angle = angle,
_spritePath = spritePath, _spritePath = spritePath,
super(priority: 1); super(priority: PinballPriority.slingshot);
final double _length; final double _length;

@ -34,7 +34,7 @@ class Spaceship extends Forge2DBlueprint {
AndroidHead()..initialPosition = position, AndroidHead()..initialPosition = position,
SpaceshipHole( SpaceshipHole(
outsideLayer: Layer.spaceshipExitRail, outsideLayer: Layer.spaceshipExitRail,
outsidePriority: Ball.spaceshipRailPriority, outsidePriority: PinballPriority.ballOnSpaceshipRail,
)..initialPosition = position - Vector2(5.2, 4.8), )..initialPosition = position - Vector2(5.2, 4.8),
SpaceshipHole()..initialPosition = position - Vector2(-7.2, 0.8), SpaceshipHole()..initialPosition = position - Vector2(-7.2, 0.8),
SpaceshipWall()..initialPosition = position, SpaceshipWall()..initialPosition = position,
@ -47,7 +47,7 @@ class Spaceship extends Forge2DBlueprint {
/// {@endtemplate} /// {@endtemplate}
class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered { class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_saucer} /// {@macro spaceship_saucer}
SpaceshipSaucer() : super(priority: Ball.spaceshipPriority - 1) { SpaceshipSaucer() : super(priority: PinballPriority.spaceshipSaucer) {
layer = Layer.spaceship; layer = Layer.spaceship;
} }
@ -91,7 +91,7 @@ class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered {
/// {@endtemplate} /// {@endtemplate}
class AndroidHead extends BodyComponent with InitialPosition, Layered { class AndroidHead extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_bridge} /// {@macro spaceship_bridge}
AndroidHead() : super(priority: Ball.spaceshipPriority + 1) { AndroidHead() : super(priority: PinballPriority.androidHead) {
layer = Layer.spaceship; layer = Layer.spaceship;
} }
@ -153,7 +153,7 @@ class SpaceshipEntrance extends RampOpening {
: super( : super(
insideLayer: Layer.spaceship, insideLayer: Layer.spaceship,
orientation: RampOrientation.up, orientation: RampOrientation.up,
insidePriority: Ball.spaceshipPriority, insidePriority: PinballPriority.ballOnSpaceship,
) { ) {
layer = Layer.spaceship; layer = Layer.spaceship;
} }
@ -187,7 +187,7 @@ class SpaceshipHole extends RampOpening {
insideLayer: Layer.spaceship, insideLayer: Layer.spaceship,
outsideLayer: outsideLayer, outsideLayer: outsideLayer,
orientation: RampOrientation.up, orientation: RampOrientation.up,
insidePriority: 4, insidePriority: PinballPriority.ballOnSpaceship,
outsidePriority: outsidePriority, outsidePriority: outsidePriority,
) { ) {
renderBody = false; renderBody = false;
@ -238,7 +238,7 @@ class _SpaceshipWallShape extends ChainShape {
/// {@endtemplate} /// {@endtemplate}
class SpaceshipWall extends BodyComponent with InitialPosition, Layered { class SpaceshipWall extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_wall} /// {@macro spaceship_wall}
SpaceshipWall() : super(priority: Ball.spaceshipPriority + 1) { SpaceshipWall() : super(priority: PinballPriority.spaceshipSaucerWall) {
layer = Layer.spaceship; layer = Layer.spaceship;
} }

@ -40,10 +40,7 @@ class SpaceshipRail extends Forge2DBlueprint {
/// Represents the spaceship drop rail from the [Spaceship]. /// Represents the spaceship drop rail from the [Spaceship].
class _SpaceshipRailRamp extends BodyComponent with InitialPosition, Layered { class _SpaceshipRailRamp extends BodyComponent with InitialPosition, Layered {
_SpaceshipRailRamp() _SpaceshipRailRamp() : super(priority: PinballPriority.spaceshipRail) {
: super(
priority: Ball.spaceshipRailPriority - 1,
) {
layer = Layer.spaceshipExitRail; layer = Layer.spaceshipExitRail;
} }
@ -158,7 +155,8 @@ class _SpaceshipRailRampSpriteComponent extends SpriteComponent
} }
class _SpaceshipRailForeground extends SpriteComponent with HasGameRef { class _SpaceshipRailForeground extends SpriteComponent with HasGameRef {
_SpaceshipRailForeground() : super(priority: Ball.spaceshipRailPriority + 1); _SpaceshipRailForeground()
: super(priority: PinballPriority.spaceshipRailForeground);
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
@ -175,13 +173,9 @@ class _SpaceshipRailForeground extends SpriteComponent with HasGameRef {
} }
/// Represents the ground bases of the [_SpaceshipRailRamp]. /// Represents the ground bases of the [_SpaceshipRailRamp].
class _SpaceshipRailBase extends BodyComponent with InitialPosition, Layered { class _SpaceshipRailBase extends BodyComponent with InitialPosition {
_SpaceshipRailBase({required this.radius}) _SpaceshipRailBase({required this.radius}) {
: super(
priority: Ball.spaceshipRailPriority + 1,
) {
renderBody = false; renderBody = false;
layer = Layer.board;
} }
final double radius; final double radius;
@ -210,7 +204,7 @@ class SpaceshipRailExit extends RampOpening {
: super( : super(
orientation: RampOrientation.down, orientation: RampOrientation.down,
insideLayer: Layer.spaceshipExitRail, insideLayer: Layer.spaceshipExitRail,
insidePriority: Ball.spaceshipRailPriority, insidePriority: PinballPriority.ballOnSpaceshipRail,
) { ) {
renderBody = false; renderBody = false;
layer = Layer.spaceshipExitRail; layer = Layer.spaceshipExitRail;

@ -21,15 +21,14 @@ class SpaceshipRamp extends Forge2DBlueprint {
]); ]);
final rightOpening = _SpaceshipRampOpening( final rightOpening = _SpaceshipRampOpening(
// TODO(ruimiguel): set Board priority when defined. outsidePriority: PinballPriority.ballOnBoard,
outsidePriority: 1,
rotation: math.pi, rotation: math.pi,
) )
..initialPosition = Vector2(1.7, 19.8) ..initialPosition = Vector2(1.7, 19.8)
..layer = Layer.opening; ..layer = Layer.opening;
final leftOpening = _SpaceshipRampOpening( final leftOpening = _SpaceshipRampOpening(
outsideLayer: Layer.spaceship, outsideLayer: Layer.spaceship,
outsidePriority: Ball.spaceshipPriority, outsidePriority: PinballPriority.ballOnSpaceship,
rotation: math.pi, rotation: math.pi,
) )
..initialPosition = Vector2(-13.7, 18.6) ..initialPosition = Vector2(-13.7, 18.6)
@ -50,6 +49,7 @@ class SpaceshipRamp extends Forge2DBlueprint {
rightOpening, rightOpening,
leftOpening, leftOpening,
baseRight, baseRight,
_SpaceshipRampBackgroundRailingSpriteComponent(),
spaceshipRamp, spaceshipRamp,
spaceshipRampForegroundRailing, spaceshipRampForegroundRailing,
]); ]);
@ -58,7 +58,7 @@ class SpaceshipRamp extends Forge2DBlueprint {
class _SpaceshipRampBackground extends BodyComponent class _SpaceshipRampBackground extends BodyComponent
with InitialPosition, Layered { with InitialPosition, Layered {
_SpaceshipRampBackground() : super(priority: Ball.spaceshipRampPriority - 1) { _SpaceshipRampBackground() : super(priority: PinballPriority.spaceshipRamp) {
layer = Layer.spaceshipEntranceRamp; layer = Layer.spaceshipEntranceRamp;
} }
@ -119,12 +119,13 @@ class _SpaceshipRampBackground extends BodyComponent
renderBody = false; renderBody = false;
await add(_SpaceshipRampBackgroundRampSpriteComponent()); await add(_SpaceshipRampBackgroundRampSpriteComponent());
await add(_SpaceshipRampBackgroundRailingSpriteComponent());
} }
} }
class _SpaceshipRampBackgroundRailingSpriteComponent extends SpriteComponent class _SpaceshipRampBackgroundRailingSpriteComponent extends SpriteComponent
with HasGameRef { with HasGameRef {
_SpaceshipRampBackgroundRailingSpriteComponent()
: super(priority: PinballPriority.spaceshipRampBackgroundRailing);
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
@ -170,7 +171,7 @@ class _SpaceshipRampBoardOpeningSpriteComponent extends SpriteComponent
class _SpaceshipRampForegroundRailing extends BodyComponent class _SpaceshipRampForegroundRailing extends BodyComponent
with InitialPosition, Layered { with InitialPosition, Layered {
_SpaceshipRampForegroundRailing() _SpaceshipRampForegroundRailing()
: super(priority: Ball.spaceshipRampPriority + 1) { : super(priority: PinballPriority.spaceshipRampForegroundRailing) {
layer = Layer.spaceshipEntranceRamp; layer = Layer.spaceshipEntranceRamp;
} }
@ -290,7 +291,7 @@ class _SpaceshipRampOpening extends RampOpening {
insideLayer: Layer.spaceshipEntranceRamp, insideLayer: Layer.spaceshipEntranceRamp,
outsideLayer: outsideLayer, outsideLayer: outsideLayer,
orientation: RampOrientation.down, orientation: RampOrientation.down,
insidePriority: Ball.spaceshipRampPriority, insidePriority: PinballPriority.ballOnSpaceshipRamp,
outsidePriority: outsidePriority, outsidePriority: outsidePriority,
) { ) {
renderBody = false; renderBody = false;

@ -20,7 +20,8 @@ class SparkyBumper extends BodyComponent with InitialPosition {
_minorRadius = minorRadius, _minorRadius = minorRadius,
_activeAssetPath = activeAssetPath, _activeAssetPath = activeAssetPath,
_inactiveAssetPath = inactiveAssetPath, _inactiveAssetPath = inactiveAssetPath,
_spriteComponent = spriteComponent; _spriteComponent = spriteComponent,
super(priority: PinballPriority.sparkyBumper);
/// {@macro sparky_bumper} /// {@macro sparky_bumper}
SparkyBumper.a() SparkyBumper.a()

@ -22,7 +22,7 @@ class SparkyComputer extends Forge2DBlueprint {
} }
class _ComputerBase extends BodyComponent with InitialPosition { class _ComputerBase extends BodyComponent with InitialPosition {
_ComputerBase(); _ComputerBase() : super(priority: PinballPriority.computerBase);
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[]; final fixturesDef = <FixtureDef>[];
@ -99,7 +99,7 @@ class _ComputerTopSpriteComponent extends SpriteComponent with HasGameRef {
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
position: Vector2(-12.45, -49.75), position: Vector2(-12.45, -49.75),
priority: 1, priority: PinballPriority.computerTop,
); );
@override @override

@ -9,7 +9,7 @@ class LaunchRampGame extends BasicBallGame {
LaunchRampGame() LaunchRampGame()
: super( : super(
color: Colors.blue, color: Colors.blue,
ballPriority: Ball.launchRampPriority, ballPriority: PinballPriority.ballOnLaunchRamp,
ballLayer: Layer.launcher, ballLayer: Layer.launcher,
); );

@ -9,7 +9,7 @@ class SpaceshipRailGame extends BasicBallGame {
SpaceshipRailGame() SpaceshipRailGame()
: super( : super(
color: Colors.blue, color: Colors.blue,
ballPriority: Ball.spaceshipRailPriority, ballPriority: PinballPriority.ballOnSpaceshipRail,
ballLayer: Layer.spaceshipExitRail, ballLayer: Layer.spaceshipExitRail,
); );

@ -9,7 +9,7 @@ class SpaceshipRampGame extends BasicBallGame {
SpaceshipRampGame() SpaceshipRampGame()
: super( : super(
color: Colors.blue, color: Colors.blue,
ballPriority: Ball.spaceshipRampPriority, ballPriority: PinballPriority.ballOnSpaceshipRamp,
ballLayer: Layer.spaceshipEntranceRamp, ballLayer: Layer.spaceshipEntranceRamp,
); );

Loading…
Cancel
Save