feat: add explicit render priorities (#198)

* feat: static priorities

* refactor: assign all priority values

* chore: rocket and plunger priorities

* chore: rename priority class

* chore: add todo

* chore: remove todo

* refactor: move to separate file

* chore: uncomment score effects

* chore: revert spacing change

* refactor: update spaceship rail priority

* fix: issue in test from merge

* chore: add todos

* feat: add fire animation priority
pull/211/head
Allison Ryan 2 years ago committed by GitHub
parent 14f7034d13
commit 12d20b8dbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -18,7 +18,7 @@ class ControlledBall extends Ball with Controls<BallController> {
required PinballTheme theme,
}) : super(baseColor: theme.characterTheme.ballColor) {
controller = BallController(this);
priority = Ball.launchRampPriority;
priority = RenderPriority.ballOnLaunchRamp;
layer = Layer.launcher;
}
@ -31,13 +31,13 @@ class ControlledBall extends Ball with Controls<BallController> {
required PinballTheme theme,
}) : super(baseColor: theme.characterTheme.ballColor) {
controller = BallController(this);
priority = Ball.boardPriority;
priority = RenderPriority.ballOnBoard;
}
/// [Ball] used in [DebugPinballGame].
ControlledBall.debug() : super(baseColor: const Color(0xFFFF0000)) {
controller = DebugBallController(this);
priority = Ball.boardPriority;
priority = RenderPriority.ballOnBoard;
}
}

@ -164,7 +164,7 @@ class DebugPinballGame extends PinballGame with TapDetector {
anchor: Anchor.center,
)
..position = Vector2(0, -7.8)
..priority = -4;
..priority = RenderPriority.background;
await add(spriteComponent);
}

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

@ -29,21 +29,6 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
renderBody = false;
}
/// 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 = -2;
/// The size of the [Ball].
static final Vector2 size = Vector2.all(4.13);
@ -152,7 +137,7 @@ class _TurboChargeSpriteAnimationComponent extends SpriteAnimationComponent
_TurboChargeSpriteAnimationComponent()
: super(
anchor: const Anchor(0.53, 0.72),
priority: Ball.boardPriority + 1,
priority: RenderPriority.turboChargeFlame,
removeOnFinish: true,
);

@ -26,8 +26,7 @@ class _BottomBoundary extends BodyComponent with InitialPosition {
/// {@macro bottom_boundary}
_BottomBoundary()
: super(
// TODO(ruimiguel): set final priority when RenderPriority PR merged.
priority: Ball.boardPriority + 2,
priority: RenderPriority.bottomBoundary,
children: [_BottomBoundarySpriteComponent()],
) {
renderBody = false;
@ -91,7 +90,7 @@ class _OuterBoundary extends BodyComponent with InitialPosition {
/// {@macro outer_boundary}
_OuterBoundary()
: super(
priority: Ball.launchRampPriority - 1,
priority: RenderPriority.outerBoudary,
children: [_OuterBoundarySpriteComponent()],
) {
renderBody = false;

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

@ -21,6 +21,7 @@ export 'launch_ramp.dart';
export 'layer.dart';
export 'layer_sensor.dart';
export 'plunger.dart';
export 'render_priority.dart';
export 'rocket.dart';
export 'score_text.dart';
export 'shapes/shapes.dart';

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

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

@ -31,8 +31,7 @@ class _DinoTopWall extends BodyComponent with InitialPosition {
///{@macro dino_top_wall}
_DinoTopWall()
: super(
// TODO(ruimiguel): set final priority when RenderPriority PR merged.
priority: Ball.boardPriority + 1,
priority: RenderPriority.dinoTopWall,
children: [_DinoTopWallSpriteComponent()],
) {
renderBody = false;
@ -127,8 +126,7 @@ class _DinoBottomWall extends BodyComponent with InitialPosition {
///{@macro dino_top_wall}
_DinoBottomWall()
: super(
// TODO(ruimiguel): set final priority when RenderPriority PR merged.
priority: Ball.boardPriority + 1,
priority: RenderPriority.dinoBottomWall,
children: [_DinoBottomWallSpriteComponent()],
) {
renderBody = false;

@ -9,6 +9,7 @@ class FlutterSignPost extends BodyComponent with InitialPosition {
/// {@macro flutter_sign_post}
FlutterSignPost()
: super(
priority: RenderPriority.flutterSignPost,
children: [_FlutterSignPostSpriteComponent()],
) {
renderBody = false;

@ -44,7 +44,7 @@ class _LaunchRampBase extends BodyComponent with InitialPosition, Layered {
/// {@macro launch_ramp_base}
_LaunchRampBase()
: super(
priority: Ball.launchRampPriority - 1,
priority: RenderPriority.launchRamp,
children: [
_LaunchRampBackgroundRailingSpriteComponent(),
_LaunchRampBaseSpriteComponent(),
@ -166,7 +166,7 @@ class _LaunchRampForegroundRailing extends BodyComponent with InitialPosition {
/// {@macro launch_ramp_foreground_railing}
_LaunchRampForegroundRailing()
: super(
priority: Ball.launchRampPriority + 1,
priority: RenderPriority.launchRampForegroundRailing,
children: [_LaunchRampForegroundRailingSpriteComponent()],
) {
renderBody = false;
@ -265,8 +265,8 @@ class _LaunchRampExit extends LayerSensor {
insideLayer: Layer.launcher,
outsideLayer: Layer.board,
orientation: LayerEntranceOrientation.down,
insidePriority: Ball.launchRampPriority,
outsidePriority: 0,
insidePriority: RenderPriority.ballOnLaunchRamp,
outsidePriority: RenderPriority.ballOnBoard,
) {
layer = Layer.launcher;
renderBody = false;

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

@ -14,7 +14,7 @@ class Plunger extends BodyComponent with InitialPosition, Layered {
required this.compressionDistance,
// TODO(ruimiguel): set to priority +1 over LaunchRamp once all priorities
// are fixed.
}) : super(priority: 0) {
}) : super(priority: RenderPriority.plunger) {
layer = Layer.launcher;
}

@ -0,0 +1,114 @@
// ignore_for_file: public_member_api_docs
import 'package:pinball_components/pinball_components.dart';
/// {@template render_priority}
/// Priorities for the component rendering order in the pinball game.
/// {@endtemplate}
// TODO(allisonryan0002): find alternative to section comments.
abstract class RenderPriority {
static const _base = 0;
static const _above = 1;
static const _below = -1;
// Ball
/// Render priority for the [Ball] while it's on the board.
static const int ballOnBoard = _base;
/// Render priority for the [Ball] while it's on the [SpaceshipRamp].
static const int ballOnSpaceshipRamp =
_above + spaceshipRampBackgroundRailing;
/// Render priority for the [Ball] while it's on the [Spaceship].
static const int ballOnSpaceship = _above + spaceshipSaucer;
/// Render priority for the [Ball] while it's on the [SpaceshipRail].
static const int ballOnSpaceshipRail = _below + spaceshipSaucer;
/// Render priority for the [Ball] while it's on the [LaunchRamp].
static const int ballOnLaunchRamp = _above + launchRamp;
// Background
// TODO(allisonryan0002): fix this magic priority. Could bump all priorities
// so there are no negatives.
static const int background = 3 * _below + _base;
// Boundaries
static const int bottomBoundary = _above + dinoBottomWall;
static const int outerBoudary = _above + background;
// Bottom Group
static const int bottomGroup = _above + ballOnBoard;
// Launcher
static const int launchRamp = _above + outerBoudary;
static const int launchRampForegroundRailing = _above + ballOnLaunchRamp;
static const int plunger = _above + launchRamp;
static const int rocket = _above + bottomBoundary;
// Dino Land
static const int dinoTopWall = _above + ballOnBoard;
static const int dino = _above + dinoTopWall;
static const int dinoBottomWall = _above + dino;
static const int slingshot = _above + ballOnBoard;
// Flutter Forest
static const int flutterSignPost = _above + launchRampForegroundRailing;
static const int dashBumper = _above + ballOnBoard;
static const int dashAnimatronic = _above + launchRampForegroundRailing;
// Sparky Fire Zone
static const int computerBase = _below + ballOnBoard;
static const int computerTop = _above + ballOnBoard;
static const int sparkyAnimatronic = _above + spaceshipRampForegroundRailing;
static const int sparkyBumper = _above + ballOnBoard;
static const int turboChargeFlame = _above + ballOnBoard;
// Android Spaceship
static const int spaceshipRail = _above + bottomGroup;
static const int spaceshipRailForeground = _above + spaceshipRail;
static const int spaceshipSaucer = _above + spaceshipRail;
static const int spaceshipSaucerWall = _above + spaceshipSaucer;
static const int androidHead = _above + spaceshipSaucer;
static const int spaceshipRamp = _above + ballOnBoard;
static const int spaceshipRampBackgroundRailing = _above + spaceshipRamp;
static const int spaceshipRampForegroundRailing =
_above + ballOnSpaceshipRamp;
static const int spaceshipRampBoardOpening = _below + ballOnBoard;
static const int alienBumper = _above + ballOnBoard;
// Score Text
static const int scoreText = _above + spaceshipRampForegroundRailing;
}

@ -9,7 +9,7 @@ class RocketSpriteComponent extends SpriteComponent with HasGameRef {
// TODO(ruimiguel): change this priority to be over launcher ramp and bottom
// wall.
/// {@macro rocket_sprite_component}
RocketSpriteComponent() : super(priority: 5);
RocketSpriteComponent() : super(priority: RenderPriority.rocket);
@override
Future<void> onLoad() async {

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

@ -43,7 +43,7 @@ class Slingshot extends BodyComponent with InitialPosition {
}) : _length = length,
_angle = angle,
super(
priority: 1,
priority: RenderPriority.slingshot,
children: [_SlinghsotSpriteComponent(spritePath, angle: angle)],
) {
renderBody = false;

@ -35,9 +35,12 @@ class Spaceship extends Forge2DBlueprint {
AndroidHead()..initialPosition = position,
_SpaceshipHole(
outsideLayer: Layer.spaceshipExitRail,
outsidePriority: Ball.spaceshipRailPriority,
outsidePriority: RenderPriority.ballOnSpaceshipRail,
)..initialPosition = position - Vector2(5.2, -4.8),
_SpaceshipHole()..initialPosition = position - Vector2(-7.2, -0.8),
_SpaceshipHole(
outsideLayer: Layer.board,
outsidePriority: RenderPriority.ballOnBoard,
)..initialPosition = position - Vector2(-7.2, -0.8),
SpaceshipWall()..initialPosition = position,
]);
}
@ -48,7 +51,7 @@ class Spaceship extends Forge2DBlueprint {
/// {@endtemplate}
class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_saucer}
SpaceshipSaucer() : super(priority: Ball.spaceshipPriority - 1) {
SpaceshipSaucer() : super(priority: RenderPriority.spaceshipSaucer) {
layer = Layer.spaceship;
}
@ -94,7 +97,7 @@ class AndroidHead extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_bridge}
AndroidHead()
: super(
priority: Ball.spaceshipPriority + 1,
priority: RenderPriority.androidHead,
children: [_AndroidHeadSpriteAnimation()],
) {
renderBody = false;
@ -145,7 +148,7 @@ class _SpaceshipEntrance extends LayerSensor {
: super(
insideLayer: Layer.spaceship,
orientation: LayerEntranceOrientation.up,
insidePriority: Ball.spaceshipPriority,
insidePriority: RenderPriority.ballOnSpaceship,
) {
layer = Layer.spaceship;
}
@ -169,12 +172,12 @@ class _SpaceshipEntrance extends LayerSensor {
}
class _SpaceshipHole extends LayerSensor {
_SpaceshipHole({Layer? outsideLayer, int? outsidePriority = 1})
_SpaceshipHole({required Layer outsideLayer, required int outsidePriority})
: super(
insideLayer: Layer.spaceship,
outsideLayer: outsideLayer,
orientation: LayerEntranceOrientation.down,
insidePriority: 4,
insidePriority: RenderPriority.ballOnSpaceship,
outsidePriority: outsidePriority,
) {
renderBody = false;
@ -225,7 +228,7 @@ class _SpaceshipWallShape extends ChainShape {
/// {@endtemplate}
class SpaceshipWall extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_wall}
SpaceshipWall() : super(priority: Ball.spaceshipPriority + 1) {
SpaceshipWall() : super(priority: RenderPriority.spaceshipSaucerWall) {
layer = Layer.spaceship;
}

@ -41,10 +41,7 @@ class SpaceshipRail extends Forge2DBlueprint {
/// Represents the spaceship drop rail from the [Spaceship].
class _SpaceshipRailRamp extends BodyComponent with InitialPosition, Layered {
_SpaceshipRailRamp()
: super(
priority: Ball.spaceshipRailPriority - 1,
) {
_SpaceshipRailRamp() : super(priority: RenderPriority.spaceshipRail) {
layer = Layer.spaceshipExitRail;
}
@ -160,7 +157,8 @@ class _SpaceshipRailRampSpriteComponent extends SpriteComponent
}
class _SpaceshipRailForeground extends SpriteComponent with HasGameRef {
_SpaceshipRailForeground() : super(priority: Ball.spaceshipRailPriority + 1);
_SpaceshipRailForeground()
: super(priority: RenderPriority.spaceshipRailForeground);
@override
Future<void> onLoad() async {
@ -177,13 +175,9 @@ class _SpaceshipRailForeground extends SpriteComponent with HasGameRef {
}
/// Represents the ground bases of the [_SpaceshipRailRamp].
class _SpaceshipRailBase extends BodyComponent with InitialPosition, Layered {
_SpaceshipRailBase({required this.radius})
: super(
priority: Ball.spaceshipRailPriority + 1,
) {
class _SpaceshipRailBase extends BodyComponent with InitialPosition {
_SpaceshipRailBase({required this.radius}) {
renderBody = false;
layer = Layer.board;
}
final double radius;
@ -206,7 +200,7 @@ class _SpaceshipRailExit extends LayerSensor {
: super(
orientation: LayerEntranceOrientation.down,
insideLayer: Layer.spaceshipExitRail,
insidePriority: Ball.spaceshipRailPriority,
insidePriority: RenderPriority.ballOnSpaceshipRail,
) {
renderBody = false;
layer = Layer.spaceshipExitRail;

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

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

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

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

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

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

@ -148,7 +148,7 @@ void main() {
callback.begin(ball, sensor, MockContact());
verify(() => ball.layer = Layer.board);
verify(() => ball.priority = Ball.boardPriority).called(1);
verify(() => ball.priority = RenderPriority.ballOnBoard).called(1);
verify(ball.reorderChildren).called(1);
});
@ -174,7 +174,7 @@ void main() {
callback.begin(ball, sensor, MockContact());
verify(() => ball.layer = Layer.board);
verify(() => ball.priority = Ball.boardPriority).called(1);
verify(() => ball.priority = RenderPriority.ballOnBoard).called(1);
verify(ball.reorderChildren).called(1);
});
});

Loading…
Cancel
Save