refactor: move JetpackRamp to pinball_components as SpaceshipEntranceRamp (#129)

* refactor: renamed JetpackRamp to SpaceshipEntranceRamp

* refactor: renamed Layer.jetpack to Layer.spaceshipEntranceRamp

* refactor: moved spaceship entrance ramp and assets to pinball components

* test: tests for spaceship ramp

* refactor: renamed SpaceshipEntranceRamp to SpaceshipRamp
pull/138/head
Rui Miguel Alonso 4 years ago committed by GitHub
parent b67b08a18d
commit 61c347c72d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,7 +3,6 @@ export 'bonus_word.dart';
export 'controlled_ball.dart';
export 'controlled_flipper.dart';
export 'flutter_forest.dart';
export 'jetpack_ramp.dart';
export 'launcher_ramp.dart';
export 'plunger.dart';
export 'score_points.dart';

@ -14,7 +14,7 @@ class SpaceshipExitRail extends Forge2DBlueprint {
/// {@macro spaceship_exit_rail}
SpaceshipExitRail();
/// Base priority for wall while be on jetpack ramp.
/// Base priority for wall while be on [_SpaceshipExitRailRamp].
static const ballPriorityWhenOnSpaceshipExitRail = 2;
@override

@ -21,10 +21,14 @@ extension PinballGameAssetsX on PinballGame {
images.load(components.Assets.images.dashBumper.b.inactive.keyName),
images.load(components.Assets.images.dashBumper.main.active.keyName),
images.load(components.Assets.images.dashBumper.main.inactive.keyName),
images.load(components.Assets.images.spaceshipRamp.spaceshipRamp.keyName),
images.load(
components.Assets.images.spaceshipRamp.spaceshipRailingBg.keyName,
),
images.load(
components.Assets.images.spaceshipRamp.spaceshipRailingFg.keyName,
),
images.load(Assets.images.components.background.path),
images.load(Assets.images.components.spaceshipRamp.path),
images.load(Assets.images.components.spaceshipRailingBg.path),
images.load(Assets.images.components.spaceshipRailingFg.path),
images.load(Assets.images.components.spaceshipDropTube.path),
]);
}

@ -92,9 +92,7 @@ class PinballGame extends Forge2DGame
}
Future<void> _addPaths() async {
unawaited(
addFromBlueprint(Jetpack()),
);
unawaited(addFromBlueprint(SpaceshipRamp()));
unawaited(addFromBlueprint(Launcher()));
}

@ -24,18 +24,6 @@ class $AssetsImagesComponentsGen {
/// File path: assets/images/components/spaceship-drop-tube.png
AssetGenImage get spaceshipDropTube =>
const AssetGenImage('assets/images/components/spaceship-drop-tube.png');
/// File path: assets/images/components/spaceship_railing_bg.png
AssetGenImage get spaceshipRailingBg =>
const AssetGenImage('assets/images/components/spaceship_railing_bg.png');
/// File path: assets/images/components/spaceship_railing_fg.png
AssetGenImage get spaceshipRailingFg =>
const AssetGenImage('assets/images/components/spaceship_railing_fg.png');
/// File path: assets/images/components/spaceship_ramp.png
AssetGenImage get spaceshipRamp =>
const AssetGenImage('assets/images/components/spaceship_ramp.png');
}
class Assets {

@ -27,6 +27,9 @@ class $AssetsImagesGen {
AssetGenImage get spaceshipBridge =>
const AssetGenImage('assets/images/spaceship_bridge.png');
$AssetsImagesSpaceshipRampGen get spaceshipRamp =>
const $AssetsImagesSpaceshipRampGen();
/// File path: assets/images/spaceship_saucer.png
AssetGenImage get spaceshipSaucer =>
const AssetGenImage('assets/images/spaceship_saucer.png');
@ -77,6 +80,22 @@ class $AssetsImagesFlipperGen {
const AssetGenImage('assets/images/flipper/right.png');
}
class $AssetsImagesSpaceshipRampGen {
const $AssetsImagesSpaceshipRampGen();
/// File path: assets/images/spaceship_ramp/spaceship_railing_bg.png
AssetGenImage get spaceshipRailingBg => const AssetGenImage(
'assets/images/spaceship_ramp/spaceship_railing_bg.png');
/// File path: assets/images/spaceship_ramp/spaceship_railing_fg.png
AssetGenImage get spaceshipRailingFg => const AssetGenImage(
'assets/images/spaceship_ramp/spaceship_railing_fg.png');
/// File path: assets/images/spaceship_ramp/spaceship_ramp.png
AssetGenImage get spaceshipRamp =>
const AssetGenImage('assets/images/spaceship_ramp/spaceship_ramp.png');
}
class $AssetsImagesDashBumperAGen {
const $AssetsImagesDashBumperAGen();

@ -15,3 +15,4 @@ export 'layer.dart';
export 'ramp_opening.dart';
export 'shapes/shapes.dart';
export 'spaceship.dart';
export 'spaceship_ramp.dart';

@ -53,8 +53,8 @@ enum Layer {
/// Collide only with ramps opening elements.
opening,
/// Collide only with Jetpack group elements.
jetpack,
/// Collide only with Spaceship entrance ramp group elements.
spaceshipEntranceRamp,
/// Collide only with Launcher group elements.
launcher,
@ -86,7 +86,7 @@ extension LayerMaskBits on Layer {
return 0x0001;
case Layer.opening:
return 0x0007;
case Layer.jetpack:
case Layer.spaceshipEntranceRamp:
return 0x0002;
case Layer.launcher:
return 0x0005;

@ -1,63 +1,66 @@
// ignore_for_file: public_member_api_docs, avoid_renaming_method_parameters
// ignore_for_file: avoid_renaming_method_parameters, comment_references
import 'dart:math' as math;
import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/gen/assets.gen.dart';
import 'package:pinball_components/gen/assets.gen.dart';
import 'package:pinball_components/pinball_components.dart' hide Assets;
/// A [Blueprint] which creates the [JetpackRamp].
class Jetpack extends Forge2DBlueprint {
/// {@macro spaceship}
Jetpack();
/// {@template spaceship_ramp}
/// A [Blueprint] which creates the [_SpaceshipRampBackground].
/// {@endtemplate}
class SpaceshipRamp extends Forge2DBlueprint {
/// {@macro spaceship_ramp}
SpaceshipRamp();
/// Base priority for wall while be in the ramp.
static const int ballPriorityInsideRamp = 4;
@override
void build(_) {
addAllContactCallback([
RampOpeningBallContactCallback<_JetpackRampOpening>(),
RampOpeningBallContactCallback<_SpaceshipRampOpening>(),
]);
final rightOpening = _JetpackRampOpening(
final rightOpening = _SpaceshipRampOpening(
// TODO(ruimiguel): set Board priority when defined.
outsidePriority: 1,
rotation: math.pi,
)
..initialPosition = Vector2(1.7, 19)
..layer = Layer.opening;
final leftOpening = _JetpackRampOpening(
final leftOpening = _SpaceshipRampOpening(
outsideLayer: Layer.spaceship,
outsidePriority: Spaceship.ballPriorityWhenOnSpaceship,
rotation: math.pi,
)
..initialPosition = Vector2(-13.7, 19)
..layer = Layer.jetpack;
..layer = Layer.spaceshipEntranceRamp;
final jetpackRamp = JetpackRamp();
final spaceshipRamp = _SpaceshipRampBackground();
final jetpackRampWallFg = _JetpackRampForegroundRailing();
final spaceshipRampForegroundRailing = _SpaceshipRampForegroundRailing();
final baseRight = _JetpackBase()..initialPosition = Vector2(1.7, 20);
final baseRight = _SpaceshipRampBase()..initialPosition = Vector2(1.7, 20);
addAll([
rightOpening,
leftOpening,
baseRight,
jetpackRamp,
jetpackRampWallFg,
spaceshipRamp,
spaceshipRampForegroundRailing,
]);
}
}
/// {@template jetpack_ramp}
/// Represents the upper left blue ramp of the [Board].
/// {@endtemplate}
class JetpackRamp extends BodyComponent with InitialPosition, Layered {
JetpackRamp() : super(priority: Jetpack.ballPriorityInsideRamp - 1) {
layer = Layer.jetpack;
/// Represents the upper left blue ramp of the [Board] with its background
/// railing.
class _SpaceshipRampBackground extends BodyComponent
with InitialPosition, Layered {
_SpaceshipRampBackground()
: super(priority: SpaceshipRamp.ballPriorityInsideRamp - 1) {
layer = Layer.spaceshipEntranceRamp;
}
/// Width between walls of the ramp.
@ -113,7 +116,7 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
Future<void> _loadSprites() async {
final spriteRamp = await gameRef.loadSprite(
Assets.images.components.spaceshipRamp.path,
Assets.images.spaceshipRamp.spaceshipRamp.keyName,
);
final spriteRampComponent = SpriteComponent(
@ -124,7 +127,7 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
);
final spriteRailingBg = await gameRef.loadSprite(
Assets.images.components.spaceshipRailingBg.path,
Assets.images.spaceshipRamp.spaceshipRailingBg.keyName,
);
final spriteRailingBgComponent = SpriteComponent(
sprite: spriteRailingBg,
@ -140,11 +143,12 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
}
}
class _JetpackRampForegroundRailing extends BodyComponent
/// Represents the foreground of the railing upper left blue ramp.
class _SpaceshipRampForegroundRailing extends BodyComponent
with InitialPosition, Layered {
_JetpackRampForegroundRailing()
: super(priority: Jetpack.ballPriorityInsideRamp + 1) {
layer = Layer.jetpack;
_SpaceshipRampForegroundRailing()
: super(priority: SpaceshipRamp.ballPriorityInsideRamp + 1) {
layer = Layer.spaceshipEntranceRamp;
}
List<FixtureDef> _createFixtureDefs() {
@ -197,7 +201,7 @@ class _JetpackRampForegroundRailing extends BodyComponent
Future<void> _loadSprites() async {
final spriteRailingFg = await gameRef.loadSprite(
Assets.images.components.spaceshipRailingFg.path,
Assets.images.spaceshipRamp.spaceshipRailingFg.keyName,
);
final spriteRailingFgComponent = SpriteComponent(
sprite: spriteRailingFg,
@ -210,8 +214,9 @@ class _JetpackRampForegroundRailing extends BodyComponent
}
}
class _JetpackBase extends BodyComponent with InitialPosition, Layered {
_JetpackBase() {
/// Represents the ground right base of the [SpaceshipRamp].
class _SpaceshipRampBase extends BodyComponent with InitialPosition, Layered {
_SpaceshipRampBase() {
layer = Layer.board;
}
@ -240,28 +245,28 @@ class _JetpackBase extends BodyComponent with InitialPosition, Layered {
}
}
/// {@template jetpack_ramp_opening}
/// [RampOpening] with [Layer.jetpack] to filter [Ball] collisions
/// inside [JetpackRamp].
/// {@template spaceship_ramp_opening}
/// [RampOpening] with [Layer.spaceshipEntranceRamp] to filter [Ball] collisions
/// inside [_SpaceshipRampBackground].
/// {@endtemplate}
class _JetpackRampOpening extends RampOpening {
/// {@macro jetpack_ramp_opening}
_JetpackRampOpening({
class _SpaceshipRampOpening extends RampOpening {
/// {@macro spaceship_ramp_opening}
_SpaceshipRampOpening({
Layer? outsideLayer,
int? outsidePriority,
required double rotation,
}) : _rotation = rotation,
super(
insideLayer: Layer.jetpack,
insideLayer: Layer.spaceshipEntranceRamp,
outsideLayer: outsideLayer,
orientation: RampOrientation.down,
insidePriority: Jetpack.ballPriorityInsideRamp,
insidePriority: SpaceshipRamp.ballPriorityInsideRamp,
outsidePriority: outsidePriority,
);
final double _rotation;
static final Vector2 _size = Vector2(JetpackRamp.width / 4, .1);
static final Vector2 _size = Vector2(_SpaceshipRampBackground.width / 4, .1);
@override
Shape get shape {

@ -32,6 +32,7 @@ flutter:
- assets/images/dash_bumper/a/
- assets/images/dash_bumper/b/
- assets/images/dash_bumper/main/
- assets/images/spaceship_ramp/
flutter_gen:
line_length: 80

@ -35,7 +35,7 @@ class BigSquare extends BodyComponent with InitialPosition, Layered {
paint = Paint()
..color = const Color.fromARGB(255, 8, 218, 241)
..style = PaintingStyle.stroke;
layer = Layer.jetpack;
layer = Layer.spaceshipEntranceRamp;
}
@override

@ -25,7 +25,7 @@ class BasicSpaceship extends BasicGame with TapDetector {
add(
Ball(baseColor: Colors.blue)
..initialPosition = info.eventPosition.game
..layer = Layer.jetpack,
..layer = Layer.spaceshipEntranceRamp,
);
}
}

@ -46,14 +46,15 @@ void main() {
});
test('correctly sets and gets', () {
final component = TestLayeredBodyComponent()..layer = Layer.jetpack;
expect(component.layer, Layer.jetpack);
final component = TestLayeredBodyComponent()
..layer = Layer.spaceshipEntranceRamp;
expect(component.layer, Layer.spaceshipEntranceRamp);
});
flameTester.test(
'layers correctly before being loaded',
(game) async {
const expectedLayer = Layer.jetpack;
const expectedLayer = Layer.spaceshipEntranceRamp;
final component = TestLayeredBodyComponent()..layer = expectedLayer;
await game.ensureAdd(component);
// TODO(alestiago): modify once component.loaded is available.
@ -71,7 +72,8 @@ void main() {
'when multiple different sets',
(game) async {
const expectedLayer = Layer.launcher;
final component = TestLayeredBodyComponent()..layer = Layer.jetpack;
final component = TestLayeredBodyComponent()
..layer = Layer.spaceshipEntranceRamp;
expect(component.layer, isNot(equals(expectedLayer)));
component.layer = expectedLayer;
@ -90,7 +92,7 @@ void main() {
flameTester.test(
'layers correctly after being loaded',
(game) async {
const expectedLayer = Layer.jetpack;
const expectedLayer = Layer.spaceshipEntranceRamp;
final component = TestLayeredBodyComponent();
await game.ensureAdd(component);
component.layer = expectedLayer;
@ -109,7 +111,7 @@ void main() {
final component = TestLayeredBodyComponent();
await game.ensureAdd(component);
component.layer = Layer.jetpack;
component.layer = Layer.spaceshipEntranceRamp;
expect(component.layer, isNot(equals(expectedLayer)));
component.layer = expectedLayer;
@ -133,7 +135,7 @@ void main() {
flameTester.test(
'nested Layered children will keep their layer',
(game) async {
const parentLayer = Layer.jetpack;
const parentLayer = Layer.spaceshipEntranceRamp;
const childLayer = Layer.board;
final component = TestLayeredBodyComponent()..layer = parentLayer;
@ -152,7 +154,7 @@ void main() {
flameTester.test(
'nested children will keep their layer',
(game) async {
const parentLayer = Layer.jetpack;
const parentLayer = Layer.spaceshipEntranceRamp;
final component = TestLayeredBodyComponent()..layer = parentLayer;
final childComponent = TestBodyComponent();

@ -44,7 +44,7 @@ void main() {
(game) async {
final ramp = TestRampOpening(
orientation: RampOrientation.down,
pathwayLayer: Layer.jetpack,
pathwayLayer: Layer.spaceshipEntranceRamp,
);
await game.ready();
await game.ensureAdd(ramp);
@ -59,7 +59,7 @@ void main() {
(game) async {
final ramp = TestRampOpening(
orientation: RampOrientation.down,
pathwayLayer: Layer.jetpack,
pathwayLayer: Layer.spaceshipEntranceRamp,
);
await game.ensureAdd(ramp);
@ -68,7 +68,7 @@ void main() {
);
group('first fixture', () {
const pathwayLayer = Layer.jetpack;
const pathwayLayer = Layer.spaceshipEntranceRamp;
const openingLayer = Layer.opening;
flameTester.test(
@ -124,7 +124,7 @@ void main() {
final body = MockBody();
final area = TestRampOpening(
orientation: RampOrientation.down,
pathwayLayer: Layer.jetpack,
pathwayLayer: Layer.spaceshipEntranceRamp,
);
final callback = TestRampOpeningBallContactCallback();
@ -145,7 +145,7 @@ void main() {
final body = MockBody();
final area = TestRampOpening(
orientation: RampOrientation.up,
pathwayLayer: Layer.jetpack,
pathwayLayer: Layer.spaceshipEntranceRamp,
);
final callback = TestRampOpeningBallContactCallback();
@ -165,7 +165,7 @@ void main() {
final body = MockBody();
final area = TestRampOpening(
orientation: RampOrientation.down,
pathwayLayer: Layer.jetpack,
pathwayLayer: Layer.spaceshipEntranceRamp,
)..initialPosition = Vector2(0, 10);
final callback = TestRampOpeningBallContactCallback();
@ -189,7 +189,7 @@ void main() {
final body = MockBody();
final area = TestRampOpening(
orientation: RampOrientation.up,
pathwayLayer: Layer.jetpack,
pathwayLayer: Layer.spaceshipEntranceRamp,
)..initialPosition = Vector2(0, 10);
final callback = TestRampOpeningBallContactCallback();
@ -213,7 +213,7 @@ void main() {
final body = MockBody();
final area = TestRampOpening(
orientation: RampOrientation.down,
pathwayLayer: Layer.jetpack,
pathwayLayer: Layer.spaceshipEntranceRamp,
)..initialPosition = Vector2(0, 10);
final callback = TestRampOpeningBallContactCallback();

@ -0,0 +1,27 @@
// ignore_for_file: cascade_invocations
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball_components/pinball_components.dart';
import '../../helpers/helpers.dart';
void main() {
group('SpaceshipRamp', () {
TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(TestGame.new);
flameTester.test(
'loads correctly',
(game) async {
final spaceshipEntranceRamp = SpaceshipRamp();
await game.addFromBlueprint(spaceshipEntranceRamp);
await game.ready();
for (final element in spaceshipEntranceRamp.components) {
expect(game.contains(element), isTrue);
}
},
);
});
}
Loading…
Cancel
Save