refactor: moved renderBody to super call

pull/234/head
alestiago 3 years ago
parent d809145152
commit 318da8c23a

@ -25,13 +25,13 @@ class ScoringBehaviour extends Component
// TODO(alestiago): Refactor once the following is merged: // TODO(alestiago): Refactor once the following is merged:
// https://github.com/flame-engine/flame/pull/1566 // https://github.com/flame-engine/flame/pull/1566
final parent = this.parent; final parent = this.parent;
if (parent is BodyComponent) { if (parent is! BodyComponent) return;
final userData = parent.body.userData;
if (userData is ContactCallbacks) { final userData = parent.body.userData;
userData.add(this); if (userData is ContactCallbacks) {
} else { userData.add(this);
parent.body.userData = this; } else {
} parent.body.userData = this;
} }
} }

@ -62,9 +62,7 @@ class SparkyFireZone extends Blueprint {
class SparkyComputerSensor extends BodyComponent class SparkyComputerSensor extends BodyComponent
with InitialPosition, ContactCallbacks { with InitialPosition, ContactCallbacks {
/// {@macro sparky_computer_sensor} /// {@macro sparky_computer_sensor}
SparkyComputerSensor() { SparkyComputerSensor() : super(renderBody: false);
renderBody = false;
}
@override @override
Body createBody() { Body createBody() {

@ -27,9 +27,8 @@ class AlienBumper extends BodyComponent with InitialPosition {
), ),
if (children != null) ...children, if (children != null) ...children,
], ],
) { renderBody: false,
renderBody = false; );
}
/// {@macro alien_bumper} /// {@macro alien_bumper}
AlienBumper.a({ AlienBumper.a({

@ -19,6 +19,7 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
children: [ children: [
_BallSpriteComponent()..tint(baseColor.withOpacity(0.5)), _BallSpriteComponent()..tint(baseColor.withOpacity(0.5)),
], ],
renderBody: false,
) { ) {
// TODO(ruimiguel): while developing Ball can be launched by clicking mouse, // TODO(ruimiguel): while developing Ball can be launched by clicking mouse,
// and default layer is Layer.all. But on final game Ball will be always be // and default layer is Layer.all. But on final game Ball will be always be
@ -26,7 +27,6 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
// We need to see what happens if Ball appears from other place like nest // We need to see what happens if Ball appears from other place like nest
// bumper, it will need to explicit change layer to Layer.board then. // bumper, it will need to explicit change layer to Layer.board then.
layer = Layer.board; layer = Layer.board;
renderBody = false;
} }
/// The size of the [Ball]. /// The size of the [Ball].

@ -14,9 +14,8 @@ class Baseboard extends BodyComponent with InitialPosition {
}) : _side = side, }) : _side = side,
super( super(
children: [_BaseboardSpriteComponent(side: side)], children: [_BaseboardSpriteComponent(side: side)],
) { renderBody: false,
renderBody = false; );
}
/// Whether the [Baseboard] is on the left or right side of the board. /// Whether the [Baseboard] is on the left or right side of the board.
final BoardSide _side; final BoardSide _side;

@ -28,9 +28,8 @@ class _BottomBoundary extends BodyComponent with InitialPosition {
: super( : super(
priority: RenderPriority.bottomBoundary, priority: RenderPriority.bottomBoundary,
children: [_BottomBoundarySpriteComponent()], children: [_BottomBoundarySpriteComponent()],
) { renderBody: false,
renderBody = false; );
}
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final bottomLeftCurve = BezierCurveShape( final bottomLeftCurve = BezierCurveShape(
@ -93,12 +92,9 @@ class _OuterBoundary extends BodyComponent with InitialPosition {
_OuterBoundary() _OuterBoundary()
: super( : super(
priority: RenderPriority.outerBoundary, priority: RenderPriority.outerBoundary,
children: [ children: [_OuterBoundarySpriteComponent()],
_OuterBoundarySpriteComponent(), renderBody: false,
], );
) {
renderBody = false;
}
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final topWall = EdgeShape() final topWall = EdgeShape()

@ -29,9 +29,8 @@ class DashNestBumper extends BodyComponent with InitialPosition {
), ),
if (children != null) ...children, if (children != null) ...children,
], ],
) { renderBody: false,
renderBody = false; );
}
/// {@macro dash_nest_bumper} /// {@macro dash_nest_bumper}
DashNestBumper.main({ DashNestBumper.main({

@ -29,9 +29,8 @@ class _DinoTopWall extends BodyComponent with InitialPosition {
: super( : super(
priority: RenderPriority.dinoTopWall, priority: RenderPriority.dinoTopWall,
children: [_DinoTopWallSpriteComponent()], children: [_DinoTopWallSpriteComponent()],
) { renderBody: false,
renderBody = false; );
}
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final topStraightShape = EdgeShape() final topStraightShape = EdgeShape()
@ -128,9 +127,8 @@ class _DinoBottomWall extends BodyComponent with InitialPosition {
: super( : super(
priority: RenderPriority.dinoBottomWall, priority: RenderPriority.dinoBottomWall,
children: [_DinoBottomWallSpriteComponent()], children: [_DinoBottomWallSpriteComponent()],
) { renderBody: false,
renderBody = false; );
}
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
const restitution = 1.0; const restitution = 1.0;

@ -15,9 +15,8 @@ class Flipper extends BodyComponent with KeyboardHandler, InitialPosition {
required this.side, required this.side,
}) : super( }) : super(
children: [_FlipperSpriteComponent(side: side)], children: [_FlipperSpriteComponent(side: side)],
) { renderBody: false,
renderBody = false; );
}
/// The size of the [Flipper]. /// The size of the [Flipper].
static final size = Vector2(13.5, 4.3); static final size = Vector2(13.5, 4.3);

@ -19,9 +19,8 @@ class Kicker extends BodyComponent with InitialPosition {
}) : _side = side, }) : _side = side,
super( super(
children: [_KickerSpriteComponent(side: side)], children: [_KickerSpriteComponent(side: side)],
) { renderBody: false,
renderBody = false; );
}
/// The size of the [Kicker] body. /// The size of the [Kicker] body.
static final Vector2 size = Vector2(4.4, 15); static final Vector2 size = Vector2(4.4, 15);

@ -36,9 +36,9 @@ class _LaunchRampBase extends BodyComponent with Layered {
_LaunchRampBackgroundRailingSpriteComponent(), _LaunchRampBackgroundRailingSpriteComponent(),
_LaunchRampBaseSpriteComponent(), _LaunchRampBaseSpriteComponent(),
], ],
renderBody: false,
) { ) {
layer = Layer.launcher; layer = Layer.launcher;
renderBody = false;
} }
// TODO(ruimiguel): final asset differs slightly from the current shape. We // TODO(ruimiguel): final asset differs slightly from the current shape. We
@ -150,9 +150,8 @@ class _LaunchRampForegroundRailing extends BodyComponent {
: super( : super(
priority: RenderPriority.launchRampForegroundRailing, priority: RenderPriority.launchRampForegroundRailing,
children: [_LaunchRampForegroundRailingSpriteComponent()], children: [_LaunchRampForegroundRailingSpriteComponent()],
) { renderBody: false,
renderBody = false; );
}
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[]; final fixturesDef = <FixtureDef>[];
@ -211,9 +210,8 @@ class _LaunchRampForegroundRailingSpriteComponent extends SpriteComponent
} }
class _LaunchRampCloseWall extends BodyComponent with InitialPosition, Layered { class _LaunchRampCloseWall extends BodyComponent with InitialPosition, Layered {
_LaunchRampCloseWall() { _LaunchRampCloseWall() : super(renderBody: false) {
layer = Layer.board; layer = Layer.board;
renderBody = false;
} }
@override @override
@ -245,7 +243,6 @@ class _LaunchRampExit extends LayerSensor {
outsidePriority: RenderPriority.ballOnBoard, outsidePriority: RenderPriority.ballOnBoard,
) { ) {
layer = Layer.launcher; layer = Layer.launcher;
renderBody = false;
} }
static final Vector2 _size = Vector2(1.6, 0.1); static final Vector2 _size = Vector2(1.6, 0.1);

@ -17,9 +17,6 @@ enum LayerEntranceOrientation {
/// {@template layer_sensor} /// {@template layer_sensor}
/// [BodyComponent] located at the entrance and exit of a [Layer]. /// [BodyComponent] located at the entrance and exit of a [Layer].
/// ///
/// [LayerSensorBallContactCallback] detects when a [Ball] passes
/// through this sensor.
///
/// By default the base [layer] is set to [Layer.board] and the /// By default the base [layer] is set to [Layer.board] and the
/// [outsidePriority] is set to the lowest possible [Layer]. /// [outsidePriority] is set to the lowest possible [Layer].
/// {@endtemplate} /// {@endtemplate}
@ -35,7 +32,8 @@ abstract class LayerSensor extends BodyComponent
}) : _insideLayer = insideLayer, }) : _insideLayer = insideLayer,
_outsideLayer = outsideLayer ?? Layer.board, _outsideLayer = outsideLayer ?? Layer.board,
_insidePriority = insidePriority, _insidePriority = insidePriority,
_outsidePriority = outsidePriority ?? RenderPriority.ballOnBoard { _outsidePriority = outsidePriority ?? RenderPriority.ballOnBoard,
super(renderBody: false) {
layer = Layer.opening; layer = Layer.opening;
} }
final Layer _insideLayer; final Layer _insideLayer;

@ -14,9 +14,11 @@ class Plunger extends BodyComponent with InitialPosition, Layered {
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: RenderPriority.plunger) { }) : super(
priority: RenderPriority.plunger,
renderBody: false,
) {
layer = Layer.launcher; layer = Layer.launcher;
renderBody = false;
} }
/// Distance the plunger can lower. /// Distance the plunger can lower.

@ -54,9 +54,8 @@ class Signpost extends BodyComponent with InitialPosition {
_SignpostSpriteComponent(), _SignpostSpriteComponent(),
if (children != null) ...children, if (children != null) ...children,
], ],
) { renderBody: false,
renderBody = false; );
}
/// Forwards the sprite to the next [SignpostSpriteState]. /// Forwards the sprite to the next [SignpostSpriteState].
/// ///

@ -40,9 +40,8 @@ class Slingshot extends BodyComponent with InitialPosition {
super( super(
priority: RenderPriority.slingshot, priority: RenderPriority.slingshot,
children: [_SlinghsotSpriteComponent(spritePath, angle: angle)], children: [_SlinghsotSpriteComponent(spritePath, angle: angle)],
) { renderBody: false,
renderBody = false; );
}
final double _length; final double _length;

@ -45,9 +45,9 @@ class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered {
children: [ children: [
_SpaceshipSaucerSpriteComponent(), _SpaceshipSaucerSpriteComponent(),
], ],
renderBody: false,
) { ) {
layer = Layer.spaceship; layer = Layer.spaceship;
renderBody = false;
} }
@override @override
@ -95,8 +95,8 @@ class AndroidHead extends BodyComponent with InitialPosition, Layered {
: super( : super(
priority: RenderPriority.androidHead, priority: RenderPriority.androidHead,
children: [_AndroidHeadSpriteAnimation()], children: [_AndroidHeadSpriteAnimation()],
renderBody: false,
) { ) {
renderBody = false;
layer = Layer.spaceship; layer = Layer.spaceship;
} }
@ -151,7 +151,6 @@ class _SpaceshipEntrance extends LayerSensor {
@override @override
Shape get shape { Shape get shape {
renderBody = false;
final radius = Spaceship.size.y / 2; final radius = Spaceship.size.y / 2;
return PolygonShape() return PolygonShape()
..setAsEdge( ..setAsEdge(
@ -176,7 +175,6 @@ class _SpaceshipHole extends LayerSensor {
insidePriority: RenderPriority.ballOnSpaceship, insidePriority: RenderPriority.ballOnSpaceship,
outsidePriority: outsidePriority, outsidePriority: outsidePriority,
) { ) {
renderBody = false;
layer = Layer.spaceship; layer = Layer.spaceship;
} }
@ -224,14 +222,16 @@ 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: RenderPriority.spaceshipSaucerWall) { SpaceshipWall()
: super(
priority: RenderPriority.spaceshipSaucerWall,
renderBody: false,
) {
layer = Layer.spaceship; layer = Layer.spaceship;
} }
@override @override
Body createBody() { Body createBody() {
renderBody = false;
final shape = _SpaceshipWallShape(); final shape = _SpaceshipWallShape();
final fixtureDef = FixtureDef(shape); final fixtureDef = FixtureDef(shape);

@ -30,9 +30,9 @@ class _SpaceshipRailRamp extends BodyComponent with Layered {
: super( : super(
priority: RenderPriority.spaceshipRail, priority: RenderPriority.spaceshipRail,
children: [_SpaceshipRailRampSpriteComponent()], children: [_SpaceshipRailRampSpriteComponent()],
renderBody: false,
) { ) {
layer = Layer.spaceshipExitRail; layer = Layer.spaceshipExitRail;
renderBody = false;
} }
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
@ -152,9 +152,7 @@ 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 { class _SpaceshipRailBase extends BodyComponent with InitialPosition {
_SpaceshipRailBase({required this.radius}) { _SpaceshipRailBase({required this.radius}) : super(renderBody: false);
renderBody = false;
}
final double radius; final double radius;
@ -177,7 +175,6 @@ class _SpaceshipRailExit extends LayerSensor {
insideLayer: Layer.spaceshipExitRail, insideLayer: Layer.spaceshipExitRail,
insidePriority: RenderPriority.ballOnSpaceshipRail, insidePriority: RenderPriority.ballOnSpaceshipRail,
) { ) {
renderBody = false;
layer = Layer.spaceshipExitRail; layer = Layer.spaceshipExitRail;
} }

@ -101,9 +101,9 @@ class _SpaceshipRampBackground extends BodyComponent
children: [ children: [
_SpaceshipRampBackgroundRampSpriteComponent(), _SpaceshipRampBackgroundRampSpriteComponent(),
], ],
renderBody: false,
) { ) {
layer = Layer.spaceshipEntranceRamp; layer = Layer.spaceshipEntranceRamp;
renderBody = false;
} }
/// Width between walls of the ramp. /// Width between walls of the ramp.
@ -248,9 +248,9 @@ class _SpaceshipRampForegroundRailing extends BodyComponent
: super( : super(
priority: RenderPriority.spaceshipRampForegroundRailing, priority: RenderPriority.spaceshipRampForegroundRailing,
children: [_SpaceshipRampForegroundRailingSpriteComponent()], children: [_SpaceshipRampForegroundRailingSpriteComponent()],
renderBody: false,
) { ) {
layer = Layer.spaceshipEntranceRamp; layer = Layer.spaceshipEntranceRamp;
renderBody = false;
} }
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
@ -313,8 +313,7 @@ class _SpaceshipRampForegroundRailingSpriteComponent extends SpriteComponent
} }
class _SpaceshipRampBase extends BodyComponent with InitialPosition, Layered { class _SpaceshipRampBase extends BodyComponent with InitialPosition, Layered {
_SpaceshipRampBase() { _SpaceshipRampBase() : super(renderBody: false) {
renderBody = false;
layer = Layer.board; layer = Layer.board;
} }
@ -355,9 +354,7 @@ class _SpaceshipRampOpening extends LayerSensor {
orientation: LayerEntranceOrientation.down, orientation: LayerEntranceOrientation.down,
insidePriority: RenderPriority.ballOnSpaceshipRamp, insidePriority: RenderPriority.ballOnSpaceshipRamp,
outsidePriority: outsidePriority, outsidePriority: outsidePriority,
) { );
renderBody = false;
}
final double _rotation; final double _rotation;

@ -29,9 +29,8 @@ class SparkyBumper extends BodyComponent with InitialPosition {
), ),
if (children != null) ...children, if (children != null) ...children,
], ],
) { renderBody: false,
renderBody = false; );
}
/// {@macro sparky_bumper} /// {@macro sparky_bumper}
SparkyBumper.a({ SparkyBumper.a({
@ -74,8 +73,6 @@ class SparkyBumper extends BodyComponent with InitialPosition {
@override @override
Body createBody() { Body createBody() {
renderBody = false;
final shape = EllipseShape( final shape = EllipseShape(
center: Vector2.zero(), center: Vector2.zero(),
majorRadius: _majorRadius, majorRadius: _majorRadius,

@ -24,9 +24,8 @@ class _ComputerBase extends BodyComponent with InitialPosition {
: super( : super(
priority: RenderPriority.computerBase, priority: RenderPriority.computerBase,
children: [_ComputerBaseSpriteComponent()], children: [_ComputerBaseSpriteComponent()],
) { renderBody: false,
renderBody = false; );
}
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final leftEdge = EdgeShape() final leftEdge = EdgeShape()

Loading…
Cancel
Save