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:
// https://github.com/flame-engine/flame/pull/1566
final parent = this.parent;
if (parent is BodyComponent) {
final userData = parent.body.userData;
if (userData is ContactCallbacks) {
userData.add(this);
} else {
parent.body.userData = this;
}
if (parent is! BodyComponent) return;
final userData = parent.body.userData;
if (userData is ContactCallbacks) {
userData.add(this);
} else {
parent.body.userData = this;
}
}

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

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

@ -19,6 +19,7 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
children: [
_BallSpriteComponent()..tint(baseColor.withOpacity(0.5)),
],
renderBody: false,
) {
// 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
@ -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
// bumper, it will need to explicit change layer to Layer.board then.
layer = Layer.board;
renderBody = false;
}
/// The size of the [Ball].

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

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

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

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

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

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

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

@ -17,9 +17,6 @@ enum LayerEntranceOrientation {
/// {@template layer_sensor}
/// [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
/// [outsidePriority] is set to the lowest possible [Layer].
/// {@endtemplate}
@ -35,7 +32,8 @@ abstract class LayerSensor extends BodyComponent
}) : _insideLayer = insideLayer,
_outsideLayer = outsideLayer ?? Layer.board,
_insidePriority = insidePriority,
_outsidePriority = outsidePriority ?? RenderPriority.ballOnBoard {
_outsidePriority = outsidePriority ?? RenderPriority.ballOnBoard,
super(renderBody: false) {
layer = Layer.opening;
}
final Layer _insideLayer;

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

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

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

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

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

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

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

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

Loading…
Cancel
Save