refactor: renamed PinballCanvas to ZCanvas

pull/282/head
alestiago 3 years ago
parent 344568e919
commit 7d37e14969

@ -9,7 +9,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// The [BottomGroup] consists of [Flipper]s, [Baseboard]s and [Kicker]s.
/// {@endtemplate}
// TODO(allisonryan0002): Consider renaming.
class BottomGroup extends Component with Rendering {
class BottomGroup extends Component with ZIndex {
/// {@macro bottom_group}
BottomGroup()
: super(

@ -11,7 +11,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// Area positioned at the top right of the board where the [Ball] can bounce
/// off [DashNestBumper]s.
/// {@endtemplate}
class FlutterForest extends Component with Rendering {
class FlutterForest extends Component with ZIndex {
/// {@macro flutter_forest}
FlutterForest()
: super(

@ -8,7 +8,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template google_word}
/// Loads all [GoogleLetter]s to compose a [GoogleWord].
/// {@endtemplate}
class GoogleWord extends Component with Rendering {
class GoogleWord extends Component with ZIndex {
/// {@macro google_word}
GoogleWord({
required Vector2 position,

@ -8,7 +8,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template multipliers}
/// A group for the multipliers on the board.
/// {@endtemplate}
class Multipliers extends Component with Rendering {
class Multipliers extends Component with ZIndex {
/// {@macro multipliers}
Multipliers()
: super(

@ -24,7 +24,7 @@ class ScoringBehavior extends ContactBehavior with HasGameRef<PinballGame> {
gameRef.read<GameBloc>().add(Scored(points: _points));
gameRef.audio.score();
gameRef.firstChild<PinballCanvasComponent>()?.add(
gameRef.firstChild<ZCanvasComponent>()?.add(
ScoreText(
text: _points.toString(),
position: other.body.position,

@ -67,7 +67,7 @@ class PinballGame extends Forge2DGame
];
await add(
PinballCanvasComponent(
ZCanvasComponent(
children: [
...machine,
...decals,
@ -169,7 +169,7 @@ class _GameBallsController extends ComponentController<PinballGame>
Vector2(41.1, 43).x,
Vector2(41.1, 45).y - Ball.size.y,
);
component.firstChild<PinballCanvasComponent>()?.add(ball);
component.firstChild<ZCanvasComponent>()?.add(ball);
}
}
@ -197,7 +197,7 @@ class DebugPinballGame extends PinballGame with FPSCounter {
if (info.raw.kind == PointerDeviceKind.mouse) {
final ball = ControlledBall.debug()
..initialPosition = info.eventPosition.game;
firstChild<PinballCanvasComponent>()?.add(ball);
firstChild<ZCanvasComponent>()?.add(ball);
}
}
}

@ -12,7 +12,7 @@ export 'cubit/android_bumper_cubit.dart';
/// {@template android_bumper}
/// Bumper for area under the [AndroidSpaceship].
/// {@endtemplate}
class AndroidBumper extends BodyComponent with InitialPosition, Rendering {
class AndroidBumper extends BodyComponent with InitialPosition, ZIndex {
/// {@macro android_bumper}
AndroidBumper._({
required double majorRadius,

@ -65,7 +65,7 @@ class _SpaceshipSaucerShape extends ChainShape {
}
class _SpaceshipSaucerSpriteAnimationComponent extends SpriteAnimationComponent
with HasGameRef, Rendering {
with HasGameRef, ZIndex {
_SpaceshipSaucerSpriteAnimationComponent()
: super(
anchor: Anchor.center,
@ -103,7 +103,7 @@ class _SpaceshipSaucerSpriteAnimationComponent extends SpriteAnimationComponent
// TODO(allisonryan0002): add pulsing behavior.
class _LightBeamSpriteComponent extends SpriteComponent
with HasGameRef, Rendering {
with HasGameRef, ZIndex {
_LightBeamSpriteComponent()
: super(
anchor: Anchor.center,
@ -124,8 +124,7 @@ class _LightBeamSpriteComponent extends SpriteComponent
}
}
class _AndroidHead extends BodyComponent
with InitialPosition, Layered, Rendering {
class _AndroidHead extends BodyComponent with InitialPosition, Layered, ZIndex {
_AndroidHead()
: super(
children: [_AndroidHeadSpriteAnimationComponent()],

@ -12,7 +12,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// A solid, [BodyType.dynamic] sphere that rolls and bounces around.
/// {@endtemplate}
class Ball<T extends Forge2DGame> extends BodyComponent<T>
with Layered, InitialPosition, Rendering {
with Layered, InitialPosition, ZIndex {
/// {@macro ball}
Ball({
required this.baseColor,
@ -134,7 +134,7 @@ class _BallSpriteComponent extends SpriteComponent with HasGameRef {
}
class _TurboChargeSpriteAnimationComponent extends SpriteAnimationComponent
with HasGameRef, Rendering {
with HasGameRef, ZIndex {
_TurboChargeSpriteAnimationComponent()
: super(
anchor: const Anchor(0.53, 0.72),

@ -5,7 +5,7 @@ import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
class BoardBackgroundSpriteComponent extends SpriteComponent
with HasGameRef, Rendering {
with HasGameRef, ZIndex {
BoardBackgroundSpriteComponent()
: super(
anchor: Anchor.center,

@ -22,7 +22,7 @@ class Boundaries extends Component {
/// Curved boundary at the bottom of the board where the [Ball] exits the field
/// of play.
/// {@endtemplate bottom_boundary}
class _BottomBoundary extends BodyComponent with InitialPosition, Rendering {
class _BottomBoundary extends BodyComponent with InitialPosition, ZIndex {
/// {@macro bottom_boundary}
_BottomBoundary()
: super(
@ -90,7 +90,7 @@ class _BottomBoundarySpriteComponent extends SpriteComponent with HasGameRef {
/// The right side of the board is closed by the barrier the [LaunchRamp]
/// creates.
/// {@endtemplate outer_boundary}
class _OuterBoundary extends BodyComponent with InitialPosition, Rendering {
class _OuterBoundary extends BodyComponent with InitialPosition, ZIndex {
/// {@macro outer_boundary}
_OuterBoundary()
: super(
@ -193,7 +193,7 @@ class _OuterBoundarySpriteComponent extends SpriteComponent with HasGameRef {
}
class _OuterBottomBoundarySpriteComponent extends SpriteComponent
with HasGameRef, Rendering {
with HasGameRef, ZIndex {
_OuterBottomBoundarySpriteComponent()
: super(
anchor: Anchor.center,

@ -11,7 +11,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// Upon eating a [Ball], the dino rotates and spits the [Ball] out in a
/// different direction.
/// {@endtemplate}
class ChromeDino extends BodyComponent with InitialPosition, Rendering {
class ChromeDino extends BodyComponent with InitialPosition, ZIndex {
/// {@macro chrome_dino}
ChromeDino()
: super(

@ -23,7 +23,7 @@ class DinoWalls extends Component {
/// {@template dino_top_wall}
/// Wall segment located above [ChromeDino].
/// {@endtemplate}
class _DinoTopWall extends BodyComponent with InitialPosition, Rendering {
class _DinoTopWall extends BodyComponent with InitialPosition, ZIndex {
///{@macro dino_top_wall}
_DinoTopWall()
: super(
@ -117,7 +117,7 @@ class _DinoTopWallSpriteComponent extends SpriteComponent with HasGameRef {
/// {@template dino_bottom_wall}
/// Wall segment located below [ChromeDino].
/// {@endtemplate}
class _DinoBottomWall extends BodyComponent with InitialPosition, Rendering {
class _DinoBottomWall extends BodyComponent with InitialPosition, ZIndex {
///{@macro dino_top_wall}
_DinoBottomWall()
: super(

@ -23,7 +23,7 @@ class LaunchRamp extends Component {
);
}
class _LaunchRampBase extends BodyComponent with Layered, Rendering {
class _LaunchRampBase extends BodyComponent with Layered, ZIndex {
_LaunchRampBase()
: super(
renderBody: false,
@ -135,7 +135,7 @@ class _LaunchRampBackgroundRailingSpriteComponent extends SpriteComponent
}
}
class _LaunchRampForegroundRailing extends BodyComponent with Rendering {
class _LaunchRampForegroundRailing extends BodyComponent with ZIndex {
_LaunchRampForegroundRailing()
: super(
children: [_LaunchRampForegroundRailingSpriteComponent()],

@ -9,7 +9,7 @@ import 'package:pinball_flame/pinball_flame.dart';
///
/// [Plunger] ignores gravity so the player controls its downward [pull].
/// {@endtemplate}
class Plunger extends BodyComponent with InitialPosition, Layered, Rendering {
class Plunger extends BodyComponent with InitialPosition, Layered, ZIndex {
/// {@macro plunger}
Plunger({
required this.compressionDistance,

@ -6,7 +6,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template rocket_sprite_component}
/// A [SpriteComponent] for the rocket over [Plunger].
/// {@endtemplate}
class RocketSpriteComponent extends SpriteComponent with HasGameRef, Rendering {
class RocketSpriteComponent extends SpriteComponent with HasGameRef, ZIndex {
/// {@macro rocket_sprite_component}
RocketSpriteComponent() : super(anchor: Anchor.center) {
zIndex = RenderPriority.rocket;

@ -9,7 +9,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template score_text}
/// A [TextComponent] that spawns at a given [position] with a moving animation.
/// {@endtemplate}
class ScoreText extends TextComponent with Rendering {
class ScoreText extends TextComponent with ZIndex {
/// {@macro score_text}
ScoreText({
required String text,

@ -6,7 +6,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template slingshots}
/// A collection of [Slingshot]s.
/// {@endtemplate}
class Slingshots extends Component with Rendering {
class Slingshots extends Component with ZIndex {
/// {@macro slingshots}
Slingshots()
: super(

@ -20,7 +20,7 @@ class SpaceshipRail extends Component {
);
}
class _SpaceshipRail extends BodyComponent with Layered, Rendering {
class _SpaceshipRail extends BodyComponent with Layered, ZIndex {
_SpaceshipRail()
: super(
children: [_SpaceshipRailSpriteComponent()],
@ -125,7 +125,7 @@ class _SpaceshipRailSpriteComponent extends SpriteComponent with HasGameRef {
}
class _SpaceshipRailExitSpriteComponent extends SpriteComponent
with HasGameRef, Rendering {
with HasGameRef, ZIndex {
_SpaceshipRailExitSpriteComponent()
: super(
anchor: Anchor.center,

@ -92,7 +92,7 @@ extension on SpaceshipRampArrowSpriteState {
}
class _SpaceshipRampBackground extends BodyComponent
with InitialPosition, Layered, Rendering {
with InitialPosition, Layered, ZIndex {
_SpaceshipRampBackground()
: super(
renderBody: false,
@ -146,7 +146,7 @@ class _SpaceshipRampBackground extends BodyComponent
}
class _SpaceshipRampBackgroundRailingSpriteComponent extends SpriteComponent
with HasGameRef, Rendering {
with HasGameRef, ZIndex {
_SpaceshipRampBackgroundRailingSpriteComponent()
: super(
anchor: Anchor.center,
@ -196,7 +196,7 @@ class _SpaceshipRampBackgroundRampSpriteComponent extends SpriteComponent
/// {@endtemplate}
class _SpaceshipRampArrowSpriteComponent
extends SpriteGroupComponent<SpaceshipRampArrowSpriteState>
with HasGameRef, Rendering {
with HasGameRef, ZIndex {
/// {@macro spaceship_ramp_arrow_sprite_component}
_SpaceshipRampArrowSpriteComponent()
: super(
@ -226,7 +226,7 @@ class _SpaceshipRampArrowSpriteComponent
}
class _SpaceshipRampBoardOpeningSpriteComponent extends SpriteComponent
with HasGameRef, Rendering {
with HasGameRef, ZIndex {
_SpaceshipRampBoardOpeningSpriteComponent() : super(anchor: Anchor.center) {
zIndex = RenderPriority.spaceshipRampBoardOpening;
}
@ -245,7 +245,7 @@ class _SpaceshipRampBoardOpeningSpriteComponent extends SpriteComponent
}
class _SpaceshipRampForegroundRailing extends BodyComponent
with InitialPosition, Layered, Rendering {
with InitialPosition, Layered, ZIndex {
_SpaceshipRampForegroundRailing()
: super(
renderBody: false,

@ -6,7 +6,7 @@ import 'package:pinball_flame/pinball_flame.dart';
/// Animated Sparky that sits on top of the [SparkyComputer].
/// {@endtemplate}
class SparkyAnimatronic extends SpriteAnimationComponent
with HasGameRef, Rendering {
with HasGameRef, ZIndex {
/// {@macro sparky_animatronic}
SparkyAnimatronic()
: super(

@ -12,7 +12,7 @@ export 'cubit/sparky_bumper_cubit.dart';
/// {@template sparky_bumper}
/// Bumper for Sparky area.
/// {@endtemplate}
class SparkyBumper extends BodyComponent with InitialPosition, Rendering {
class SparkyBumper extends BodyComponent with InitialPosition, ZIndex {
/// {@macro sparky_bumper}
SparkyBumper._({
required double majorRadius,

@ -20,7 +20,7 @@ class SparkyComputer extends Component {
);
}
class _ComputerBase extends BodyComponent with InitialPosition, Rendering {
class _ComputerBase extends BodyComponent with InitialPosition, ZIndex {
_ComputerBase()
: super(
renderBody: false,
@ -85,7 +85,7 @@ class _ComputerBaseSpriteComponent extends SpriteComponent with HasGameRef {
}
class _ComputerTopSpriteComponent extends SpriteComponent
with HasGameRef, Rendering {
with HasGameRef, ZIndex {
_ComputerTopSpriteComponent()
: super(
anchor: Anchor.center,
@ -109,7 +109,7 @@ class _ComputerTopSpriteComponent extends SpriteComponent
}
class _ComputerGlowSpriteComponent extends SpriteComponent
with HasGameRef, Rendering {
with HasGameRef, ZIndex {
_ComputerGlowSpriteComponent()
: super(
anchor: Anchor.center,

@ -27,7 +27,7 @@ void main() {
'renders correctly',
setUp: (game, tester) async {
await game.images.loadAll(assets);
final canvas = PinballCanvasComponent(
final canvas = ZCanvasComponent(
children: [AndroidSpaceship(position: Vector2.zero())],
);
await game.ensureAdd(canvas);

@ -29,7 +29,7 @@ void main() {
'render correctly',
setUp: (game, tester) async {
await game.images.loadAll(assets);
final canvas = PinballCanvasComponent(children: [Boundaries()]);
final canvas = ZCanvasComponent(children: [Boundaries()]);
await game.ensureAdd(canvas);
game.camera.followVector2(Vector2.zero());

@ -40,7 +40,7 @@ void main() {
setUp: (game, tester) async {
await game.images.loadAll(assets);
final component = SpaceshipRamp();
final canvas = PinballCanvasComponent(children: [component]);
final canvas = ZCanvasComponent(children: [component]);
await game.ensureAdd(canvas);
await tester.pump();
@ -65,7 +65,7 @@ void main() {
setUp: (game, tester) async {
await game.images.loadAll(assets);
final component = SpaceshipRamp();
final canvas = PinballCanvasComponent(children: [component]);
final canvas = ZCanvasComponent(children: [component]);
await game.ensureAdd(canvas);
component.progress();
@ -91,7 +91,7 @@ void main() {
setUp: (game, tester) async {
await game.images.loadAll(assets);
final component = SpaceshipRamp();
final canvas = PinballCanvasComponent(children: [component]);
final canvas = ZCanvasComponent(children: [component]);
await game.ensureAdd(canvas);
component
@ -119,7 +119,7 @@ void main() {
setUp: (game, tester) async {
await game.images.loadAll(assets);
final component = SpaceshipRamp();
final canvas = PinballCanvasComponent(children: [component]);
final canvas = ZCanvasComponent(children: [component]);
await game.ensureAdd(canvas);
component
@ -148,7 +148,7 @@ void main() {
setUp: (game, tester) async {
await game.images.loadAll(assets);
final component = SpaceshipRamp();
final canvas = PinballCanvasComponent(children: [component]);
final canvas = ZCanvasComponent(children: [component]);
await game.ensureAdd(canvas);
component
@ -178,7 +178,7 @@ void main() {
setUp: (game, tester) async {
await game.images.loadAll(assets);
final component = SpaceshipRamp();
final canvas = PinballCanvasComponent(children: [component]);
final canvas = ZCanvasComponent(children: [component]);
await game.ensureAdd(canvas);
component

@ -1,3 +1,3 @@
export 'pinball_canvas.dart';
export 'pinball_canvas_component.dart';
export 'rendering_mixin.dart';
export 'z_canvas.dart';
export 'z_canvas_component.dart';
export 'z_index.dart';

@ -6,12 +6,12 @@ import 'dart:ui';
import 'package:flame/components.dart';
import 'package:pinball_flame/src/rendering/rendering.dart';
class PinballCanvas implements Canvas {
class ZCanvas implements Canvas {
late Canvas canvas;
final List<Rendering> _zBuffer = [];
final List<ZIndex> _zBuffer = [];
void buffer(Rendering rendering) => _zBuffer.add(rendering);
void buffer(ZIndex rendering) => _zBuffer.add(rendering);
void render() => _zBuffer
..sort((a, b) => a.zIndex.compareTo(b.zIndex))

@ -5,13 +5,13 @@ import 'dart:ui' show Canvas;
import 'package:flame/components.dart';
import 'package:pinball_flame/src/rendering/rendering.dart';
class PinballCanvasComponent extends Component {
PinballCanvasComponent({
class ZCanvasComponent extends Component {
ZCanvasComponent({
Iterable<Component>? children,
}) : _pinballCanvas = PinballCanvas(),
}) : _pinballCanvas = ZCanvas(),
super(children: children);
final PinballCanvas _pinballCanvas;
final ZCanvas _pinballCanvas;
@override
void renderTree(Canvas canvas) {

@ -4,14 +4,14 @@ import 'dart:ui';
import 'package:flame/components.dart';
import 'package:pinball_flame/src/rendering/rendering.dart';
mixin Rendering on Component {
mixin ZIndex on Component {
int zIndex = 0;
@override
void renderTree(
Canvas canvas,
) {
if (canvas is PinballCanvas) {
if (canvas is ZCanvas) {
canvas.buffer(this);
} else {
super.renderTree(canvas);
Loading…
Cancel
Save