From 8d408da582258b844f55b90fa81249f5e573b9de Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Thu, 17 Mar 2022 12:13:35 +0100 Subject: [PATCH] refactor: rampopening with layered mixin --- lib/game/components/jetpack_ramp.dart | 9 ++++++--- lib/game/components/launcher_ramp.dart | 9 ++++++--- lib/game/components/ramp_opening.dart | 17 +++++------------ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/game/components/jetpack_ramp.dart b/lib/game/components/jetpack_ramp.dart index 715d155a..b31ac6e7 100644 --- a/lib/game/components/jetpack_ramp.dart +++ b/lib/game/components/jetpack_ramp.dart @@ -47,11 +47,15 @@ class JetpackRamp extends Component with HasGameRef { final leftOpening = JetpackRampOpening( orientation: RampOrientation.down, rotation: radians(15), - )..initialPosition = position + Vector2(-11, 1); + ) + ..initialPosition = position + Vector2(-11, 1) + ..layer = Layer.opening; final rightOpening = JetpackRampOpening( orientation: RampOrientation.down, rotation: radians(-9), - )..initialPosition = position + Vector2(20.5, 3.4); + ) + ..initialPosition = position + Vector2(20.5, 3.4) + ..layer = Layer.opening; await addAll([ curvePath, @@ -74,7 +78,6 @@ class JetpackRampOpening extends RampOpening { _orientation = orientation, super( pathwayLayer: Layer.jetpack, - openingLayer: Layer.opening, ); /// Orientation of entrance/exit of [JetpackRamp] where diff --git a/lib/game/components/launcher_ramp.dart b/lib/game/components/launcher_ramp.dart index aee9d804..0c6b703d 100644 --- a/lib/game/components/launcher_ramp.dart +++ b/lib/game/components/launcher_ramp.dart @@ -52,10 +52,14 @@ class LauncherRamp extends Component with HasGameRef { final leftOpening = LauncherRampOpening( orientation: RampOrientation.down, rotation: radians(13), - )..initialPosition = position + Vector2(-46.5, -8.5); + ) + ..initialPosition = position + Vector2(-46.5, -8.5) + ..layer = Layer.opening; final rightOpening = LauncherRampOpening( orientation: RampOrientation.down, - )..initialPosition = position + Vector2(4, 0); + ) + ..initialPosition = position + Vector2(4, 0) + ..layer = Layer.opening; await addAll([ straightPath, @@ -79,7 +83,6 @@ class LauncherRampOpening extends RampOpening { _orientation = orientation, super( pathwayLayer: Layer.launcher, - openingLayer: Layer.opening, ); /// Orientation of entrance/exit of [LauncherRamp] where diff --git a/lib/game/components/ramp_opening.dart b/lib/game/components/ramp_opening.dart index 64adf1eb..e8f926af 100644 --- a/lib/game/components/ramp_opening.dart +++ b/lib/game/components/ramp_opening.dart @@ -21,20 +21,15 @@ enum RampOrientation { /// through this opening. By default openings are [Layer.board] that /// means opening are at ground level, not over board. /// {@endtemplate} -abstract class RampOpening extends BodyComponent with InitialPosition { +abstract class RampOpening extends BodyComponent with InitialPosition, Layered { /// {@macro ramp_opening} RampOpening({ required Layer pathwayLayer, - Layer? openingLayer, - }) : _pathwayLayer = pathwayLayer, - _openingLayer = openingLayer ?? Layer.board; - - final Layer _openingLayer; + }) : _pathwayLayer = pathwayLayer { + layer = Layer.board; + } final Layer _pathwayLayer; - /// Mask of category bits for collision with [RampOpening]. - Layer get openingLayer => _openingLayer; - /// Mask of category bits for collision inside [Pathway]. Layer get pathwayLayer => _pathwayLayer; @@ -48,9 +43,7 @@ abstract class RampOpening extends BodyComponent with InitialPosition { @override Body createBody() { - final fixtureDef = FixtureDef(shape) - ..isSensor = true - ..filter.categoryBits = _openingLayer.maskBits; + final fixtureDef = FixtureDef(shape)..isSensor = true; final bodyDef = BodyDef() ..userData = this