From 2095e90f8aef43d470365e819c2e4685905f4260 Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Thu, 31 Mar 2022 18:20:28 +0200 Subject: [PATCH] fix: modified rampopening for priority changes --- lib/game/components/launcher_ramp.dart | 1 + lib/game/components/spaceship_exit_rail.dart | 1 + .../lib/src/components/ramp_opening.dart | 22 ++++++++++++++++--- .../lib/src/components/spaceship.dart | 12 +++++----- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/game/components/launcher_ramp.dart b/lib/game/components/launcher_ramp.dart index b3f3cb23..9b5c9334 100644 --- a/lib/game/components/launcher_ramp.dart +++ b/lib/game/components/launcher_ramp.dart @@ -124,6 +124,7 @@ class _LauncherRampOpening extends RampOpening { super( pathwayLayer: Layer.launcher, orientation: RampOrientation.down, + pathwayPriority: 4, ); final double _rotation; diff --git a/lib/game/components/spaceship_exit_rail.dart b/lib/game/components/spaceship_exit_rail.dart index 0dc38322..617f092a 100644 --- a/lib/game/components/spaceship_exit_rail.dart +++ b/lib/game/components/spaceship_exit_rail.dart @@ -171,6 +171,7 @@ class SpaceshipExitRailEnd extends RampOpening { : super( pathwayLayer: Layer.spaceshipExitRail, orientation: RampOrientation.down, + pathwayPriority: 3, ) { layer = Layer.spaceshipExitRail; } diff --git a/packages/pinball_components/lib/src/components/ramp_opening.dart b/packages/pinball_components/lib/src/components/ramp_opening.dart index 8f33e813..cf7e611c 100644 --- a/packages/pinball_components/lib/src/components/ramp_opening.dart +++ b/packages/pinball_components/lib/src/components/ramp_opening.dart @@ -27,12 +27,18 @@ abstract class RampOpening extends BodyComponent with InitialPosition, Layered { /// {@macro ramp_opening} RampOpening({ required Layer pathwayLayer, + required int pathwayPriority, Layer? outsideLayer, + int? outsidePriority, required this.orientation, }) : _pathwayLayer = pathwayLayer, - _outsideLayer = outsideLayer ?? Layer.board { + _outsideLayer = outsideLayer ?? Layer.board, + _pathwayPriority = pathwayPriority, + _outsidePriority = outsidePriority ?? 1 { layer = Layer.board; } + final int _pathwayPriority; + final int _outsidePriority; final Layer _pathwayLayer; final Layer _outsideLayer; @@ -42,6 +48,12 @@ abstract class RampOpening extends BodyComponent with InitialPosition, Layered { /// Mask of category bits for collision outside pathway. Layer get outsideLayer => _outsideLayer; + /// Mask of category bits for collision outside pathway. + int get pathwayPriority => _pathwayPriority; + + /// Mask of category bits for collision outside pathway. + int get outsidePriority => _outsidePriority; + /// The [Shape] of the [RampOpening]. Shape get shape; @@ -82,7 +94,9 @@ class RampOpeningBallContactCallback if (!_ballsInside.contains(ball)) { layer = opening.pathwayLayer; _ballsInside.add(ball); - ball.layer = layer; + ball + ..layer = layer + ..priority = opening.pathwayPriority; } else { _ballsInside.remove(ball); } @@ -103,7 +117,9 @@ class RampOpeningBallContactCallback ball.body.linearVelocity.y > 0); if (isBallOutsideOpening) { - ball.layer = opening.outsideLayer; + ball + ..layer = opening.outsideLayer + ..priority = opening.outsidePriority; _ballsInside.remove(ball); } } diff --git a/packages/pinball_components/lib/src/components/spaceship.dart b/packages/pinball_components/lib/src/components/spaceship.dart index 7e9d097e..86a1616b 100644 --- a/packages/pinball_components/lib/src/components/spaceship.dart +++ b/packages/pinball_components/lib/src/components/spaceship.dart @@ -149,14 +149,11 @@ class SpaceshipEntrance extends RampOpening { : super( pathwayLayer: Layer.spaceship, orientation: RampOrientation.up, + pathwayPriority: 4, ) { layer = Layer.spaceship; } - /// Priority order for [SpaceshipHole] on enter. - // TODO(ruimiguel): apply Elevated when PR merged. - final int onEnterElevation = 4; - @override Shape get shape { renderBody = false; @@ -186,6 +183,8 @@ class SpaceshipHole extends RampOpening { pathwayLayer: Layer.spaceship, outsideLayer: onExitLayer, orientation: RampOrientation.up, + pathwayPriority: 4, + outsidePriority: onExitElevation, ) { layer = Layer.spaceship; } @@ -269,8 +268,7 @@ class SpaceshipEntranceBallContactCallback @override void begin(SpaceshipEntrance entrance, Ball ball, _) { ball - // TODO(ruimiguel): apply Elevated when PR merged. - ..priority = entrance.onEnterElevation + ..priority = entrance.pathwayPriority ..gameRef.reorderChildren() ..layer = Layer.spaceship; } @@ -287,7 +285,7 @@ class SpaceshipHoleBallContactCallback void begin(SpaceshipHole hole, Ball ball, _) { ball // TODO(ruimiguel): apply Elevated when PR merged. - ..priority = hole.onExitElevation + ..priority = hole.outsidePriority ..gameRef.reorderChildren() ..layer = hole.outsideLayer; }