Merge branch 'main' into refactor/ball-priority

pull/183/head
Allison Ryan 4 years ago
commit 51808d3a97

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 MiB

After

Width:  |  Height:  |  Size: 9.7 MiB

@ -37,6 +37,7 @@ extension PinballGameAssetsX on PinballGame {
images.load(components.Assets.images.spaceship.saucer.keyName),
images.load(components.Assets.images.spaceship.bridge.keyName),
images.load(components.Assets.images.spaceship.ramp.main.keyName),
images.load(components.Assets.images.spaceship.ramp.boardOpening.keyName),
images.load(
components.Assets.images.spaceship.ramp.railingBackground.keyName,
),

@ -20,10 +20,18 @@
"@start": {
"description": "Text displayed on the character selection page start button"
},
"select": "Select",
"@select": {
"description": "Text displayed on the character selection page select button"
},
"characterSelectionTitle": "Choose your character!",
"@characterSelectionTitle": {
"description": "Title text displayed on the character selection page"
},
"characterSelectionSubtitle": "Theres no wrong answer",
"@characterSelectionSubtitle": {
"description": "Text displayed on the selecting character dialog at game beginning"
},
"gameOver": "Game Over",
"@gameOver": {
"description": "Text displayed on the ending dialog when game finishes"

@ -36,7 +36,7 @@ extension LeaderboardEntryDataX on LeaderboardEntryData {
rank: position.toString(),
playerInitials: playerInitials,
score: score,
character: character.toTheme.characterAsset,
character: character.toTheme.character,
);
}
}

@ -122,7 +122,7 @@ class CharacterImageButton extends StatelessWidget {
),
child: Padding(
padding: const EdgeInsets.all(8),
child: characterTheme.characterAsset.image(),
child: characterTheme.character.image(),
),
),
);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 MiB

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

@ -283,6 +283,10 @@ class $AssetsImagesSpaceshipRailGen {
class $AssetsImagesSpaceshipRampGen {
const $AssetsImagesSpaceshipRampGen();
/// File path: assets/images/spaceship/ramp/board-opening.png
AssetGenImage get boardOpening =>
const AssetGenImage('assets/images/spaceship/ramp/board-opening.png');
/// File path: assets/images/spaceship/ramp/main.png
AssetGenImage get main =>
const AssetGenImage('assets/images/spaceship/ramp/main.png');

@ -1,4 +1,4 @@
// ignore_for_file: avoid_renaming_method_parameters, comment_references
// ignore_for_file: avoid_renaming_method_parameters
import 'dart:math' as math;
@ -8,7 +8,7 @@ import 'package:pinball_components/gen/assets.gen.dart';
import 'package:pinball_components/pinball_components.dart' hide Assets;
/// {@template spaceship_ramp}
/// A [Blueprint] which creates the [_SpaceshipRampBackground].
/// A [Blueprint] which creates the ramp leading into the [Spaceship].
/// {@endtemplate}
class SpaceshipRamp extends Forge2DBlueprint {
/// {@macro spaceship_ramp}
@ -25,23 +25,28 @@ class SpaceshipRamp extends Forge2DBlueprint {
outsidePriority: 1,
rotation: math.pi,
)
..initialPosition = Vector2(1.7, 19)
..initialPosition = Vector2(1.7, 19.8)
..layer = Layer.opening;
final leftOpening = _SpaceshipRampOpening(
outsideLayer: Layer.spaceship,
outsidePriority: Ball.spaceshipPriority,
rotation: math.pi,
)
..initialPosition = Vector2(-13.7, 19)
..initialPosition = Vector2(-13.7, 18.6)
..layer = Layer.spaceshipEntranceRamp;
final spaceshipRamp = _SpaceshipRampBackground();
final spaceshipRampBoardOpeningSprite =
_SpaceshipRampBoardOpeningSpriteComponent()
..position = Vector2(3.4, -39.5);
final spaceshipRampForegroundRailing = _SpaceshipRampForegroundRailing();
final baseRight = _SpaceshipRampBase()..initialPosition = Vector2(1.7, 20);
addAll([
spaceshipRampBoardOpeningSprite,
rightOpening,
leftOpening,
baseRight,
@ -51,8 +56,6 @@ class SpaceshipRamp extends Forge2DBlueprint {
}
}
/// Represents the upper left blue ramp of the [Board] with its background
/// railing.
class _SpaceshipRampBackground extends BodyComponent
with InitialPosition, Layered {
_SpaceshipRampBackground() : super(priority: Ball.spaceshipRampPriority - 1) {
@ -67,7 +70,7 @@ class _SpaceshipRampBackground extends BodyComponent
final outerLeftCurveShape = BezierCurveShape(
controlPoints: [
Vector2(-30.95, 38),
Vector2(-30.75, 37.3),
Vector2(-32.5, 71.25),
Vector2(-14.2, 71.25),
],
@ -79,14 +82,22 @@ class _SpaceshipRampBackground extends BodyComponent
final outerRightCurveShape = BezierCurveShape(
controlPoints: [
outerLeftCurveShape.vertices.last,
Vector2(4.7, 71.25),
Vector2(6.3, 40),
Vector2(2.5, 71.9),
Vector2(6.1, 44.9),
],
);
final outerRightCurveFixtureDef = FixtureDef(outerRightCurveShape);
fixturesDef.add(outerRightCurveFixtureDef);
final boardOpeningEdgeShape = EdgeShape()
..set(
outerRightCurveShape.vertices.last,
Vector2(7.3, 41.1),
);
final boardOpeningEdgeShapeFixtureDef = FixtureDef(boardOpeningEdgeShape);
fixturesDef.add(boardOpeningEdgeShapeFixtureDef);
return fixturesDef;
}
@ -107,8 +118,8 @@ class _SpaceshipRampBackground extends BodyComponent
await super.onLoad();
renderBody = false;
await add(_SpaceshipRampBackgroundRailingSpriteComponent());
await add(_SpaceshipRampBackgroundRampSpriteComponent());
await add(_SpaceshipRampBackgroundRailingSpriteComponent());
}
}
@ -121,9 +132,9 @@ class _SpaceshipRampBackgroundRailingSpriteComponent extends SpriteComponent
Assets.images.spaceship.ramp.railingBackground.keyName,
);
this.sprite = sprite;
size = Vector2(38.3, 35.1);
size = sprite.originalSize / 10;
anchor = Anchor.center;
position = Vector2(-12.2, -54.5);
position = Vector2(-11.7, -54.3);
}
}
@ -138,11 +149,24 @@ class _SpaceshipRampBackgroundRampSpriteComponent extends SpriteComponent
this.sprite = sprite;
size = sprite.originalSize / 10;
anchor = Anchor.center;
position = Vector2(-12.2, -53.5);
position = Vector2(-11.7, -53.6);
}
}
class _SpaceshipRampBoardOpeningSpriteComponent extends SpriteComponent
with HasGameRef {
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite(
Assets.images.spaceship.ramp.boardOpening.keyName,
);
this.sprite = sprite;
size = sprite.originalSize / 10;
anchor = Anchor.center;
}
}
/// Represents the foreground of the railing upper left blue ramp.
class _SpaceshipRampForegroundRailing extends BodyComponent
with InitialPosition, Layered {
_SpaceshipRampForegroundRailing()
@ -167,14 +191,22 @@ class _SpaceshipRampForegroundRailing extends BodyComponent
final innerRightCurveShape = BezierCurveShape(
controlPoints: [
innerLeftCurveShape.vertices.last,
Vector2(-1, 64.5),
Vector2(0.1, 39.5),
Vector2(-2.5, 66.2),
Vector2(0, 44.5),
],
);
final innerRightCurveFixtureDef = FixtureDef(innerRightCurveShape);
fixturesDef.add(innerRightCurveFixtureDef);
final boardOpeningEdgeShape = EdgeShape()
..set(
innerRightCurveShape.vertices.last,
Vector2(-0.85, 40.8),
);
final boardOpeningEdgeShapeFixtureDef = FixtureDef(boardOpeningEdgeShape);
fixturesDef.add(boardOpeningEdgeShapeFixtureDef);
return fixturesDef;
}
@ -208,13 +240,12 @@ class _SpaceshipRampForegroundRailingSpriteComponent extends SpriteComponent
Assets.images.spaceship.ramp.railingForeground.keyName,
);
this.sprite = sprite;
size = Vector2(26.1, 28.3);
size = sprite.originalSize / 10;
anchor = Anchor.center;
position = Vector2(-12.2, -52.5);
position = Vector2(-12.3, -52.5);
}
}
/// Represents the ground right base of the [SpaceshipRamp].
class _SpaceshipRampBase extends BodyComponent with InitialPosition, Layered {
_SpaceshipRampBase() {
renderBody = false;
@ -223,14 +254,14 @@ class _SpaceshipRampBase extends BodyComponent with InitialPosition, Layered {
@override
Body createBody() {
const baseWidth = 6;
const baseWidth = 9;
final baseShape = BezierCurveShape(
controlPoints: [
Vector2(initialPosition.x - baseWidth / 2, initialPosition.y),
Vector2(initialPosition.x - baseWidth / 2, initialPosition.y) +
Vector2(2, 2),
Vector2(2, 5),
Vector2(initialPosition.x + baseWidth / 2, initialPosition.y) +
Vector2(-2, 2),
Vector2(-2, 5),
Vector2(initialPosition.x + baseWidth / 2, initialPosition.y)
],
);
@ -267,7 +298,7 @@ class _SpaceshipRampOpening extends RampOpening {
final double _rotation;
static final Vector2 _size = Vector2(_SpaceshipRampBackground.width / 4, .1);
static final Vector2 _size = Vector2(_SpaceshipRampBackground.width / 3, .1);
@override
Shape get shape {

@ -12,8 +12,6 @@ extension BodyTrace on BodyComponent {
unawaited(
mounted.whenComplete(() {
children.whereType<SpriteComponent>().first.setOpacity(0.5);
descendants().whereType<JointAnchor>().forEach((anchor) {
final fixtureDef = FixtureDef(CircleShape()..radius = 0.5);
anchor.body.createFixture(fixtureDef);
@ -32,9 +30,13 @@ mixin Traceable on Forge2DGame {
}) async {
if (trace) {
await ready();
children
descendants()
.whereType<BodyComponent>()
.forEach((bodyComponent) => bodyComponent.trace());
descendants()
.whereType<SpriteComponent>()
.forEach((sprite) => sprite.setOpacity(0.5));
}
}
}

@ -17,6 +17,8 @@ void main() {
addEffectsStories(dashbook);
addFlipperStories(dashbook);
addSpaceshipStories(dashbook);
addSpaceshipRampStories(dashbook);
addSpaceshipRailStories(dashbook);
addBaseboardStories(dashbook);
addChromeDinoStories(dashbook);
addDashNestBumperStories(dashbook);
@ -28,8 +30,6 @@ void main() {
addZoomStories(dashbook);
addBoundariesStories(dashbook);
addGoogleWordStories(dashbook);
addSpaceshipRampStories(dashbook);
addSpaceshipRailStories(dashbook);
addLaunchRampStories(dashbook);
addScoreTextStories(dashbook);

@ -14,7 +14,7 @@ class SpaceshipRampGame extends BasicBallGame {
);
static const info = '''
Shows how SpaceshipRamp are rendered.
Shows how SpaceshipRamp is rendered.
- Activate the "trace" parameter to overlay the body.
- Tap anywhere on the screen to spawn a ball into the game.
@ -23,12 +23,8 @@ class SpaceshipRampGame extends BasicBallGame {
@override
Future<void> onLoad() async {
await super.onLoad();
camera.followVector2(Vector2(-10, -20));
final spaceshipRamp = SpaceshipRamp();
unawaited(addFromBlueprint(spaceshipRamp));
await addFromBlueprint(SpaceshipRamp());
camera.followVector2(Vector2(-12, -50));
await traceAllBodies();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 913 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 894 KiB

After

Width:  |  Height:  |  Size: 844 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

@ -1,5 +1,6 @@
// ignore_for_file: cascade_invocations
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball_components/pinball_components.dart';
@ -8,20 +9,22 @@ import '../../helpers/helpers.dart';
void main() {
group('SpaceshipRamp', () {
TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(TestGame.new);
final tester = FlameTester(TestGame.new);
flameTester.test(
'loads correctly',
(game) async {
final spaceshipEntranceRamp = SpaceshipRamp();
await game.addFromBlueprint(spaceshipEntranceRamp);
tester.testGameWidget(
'renders correctly',
setUp: (game, tester) async {
await game.addFromBlueprint(SpaceshipRamp());
await game.ready();
for (final element in spaceshipEntranceRamp.components) {
expect(game.contains(element), isTrue);
}
game.camera.followVector2(Vector2(-13, -50));
},
// TODO(allisonryan0002): enable test when workflows are fixed.
// verify: (game, tester) async {
// await expectLater(
// find.byGame<Forge2DGame>(),
// matchesGoldenFile('golden/spaceship-ramp.png'),
// );
// },
);
});
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 308 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 223 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@ -3,15 +3,88 @@
/// FlutterGen
/// *****************************************************
// ignore_for_file: directives_ordering,unnecessary_import
import 'package:flutter/widgets.dart';
class $AssetsImagesGen {
const $AssetsImagesGen();
AssetGenImage get android => const AssetGenImage('assets/images/android.png');
AssetGenImage get dash => const AssetGenImage('assets/images/dash.png');
AssetGenImage get dino => const AssetGenImage('assets/images/dino.png');
AssetGenImage get sparky => const AssetGenImage('assets/images/sparky.png');
$AssetsImagesAndroidGen get android => const $AssetsImagesAndroidGen();
$AssetsImagesDashGen get dash => const $AssetsImagesDashGen();
$AssetsImagesDinoGen get dino => const $AssetsImagesDinoGen();
/// File path: assets/images/pinball_button.png
AssetGenImage get pinballButton =>
const AssetGenImage('assets/images/pinball_button.png');
/// File path: assets/images/select_character_background.png
AssetGenImage get selectCharacterBackground =>
const AssetGenImage('assets/images/select_character_background.png');
$AssetsImagesSparkyGen get sparky => const $AssetsImagesSparkyGen();
}
class $AssetsImagesAndroidGen {
const $AssetsImagesAndroidGen();
/// File path: assets/images/android/background.png
AssetGenImage get background =>
const AssetGenImage('assets/images/android/background.png');
/// File path: assets/images/android/character.png
AssetGenImage get character =>
const AssetGenImage('assets/images/android/character.png');
/// File path: assets/images/android/icon.png
AssetGenImage get icon =>
const AssetGenImage('assets/images/android/icon.png');
}
class $AssetsImagesDashGen {
const $AssetsImagesDashGen();
/// File path: assets/images/dash/background.png
AssetGenImage get background =>
const AssetGenImage('assets/images/dash/background.png');
/// File path: assets/images/dash/character.png
AssetGenImage get character =>
const AssetGenImage('assets/images/dash/character.png');
/// File path: assets/images/dash/icon.png
AssetGenImage get icon => const AssetGenImage('assets/images/dash/icon.png');
}
class $AssetsImagesDinoGen {
const $AssetsImagesDinoGen();
/// File path: assets/images/dino/background.png
AssetGenImage get background =>
const AssetGenImage('assets/images/dino/background.png');
/// File path: assets/images/dino/character.png
AssetGenImage get character =>
const AssetGenImage('assets/images/dino/character.png');
/// File path: assets/images/dino/icon.png
AssetGenImage get icon => const AssetGenImage('assets/images/dino/icon.png');
}
class $AssetsImagesSparkyGen {
const $AssetsImagesSparkyGen();
/// File path: assets/images/sparky/background.png
AssetGenImage get background =>
const AssetGenImage('assets/images/sparky/background.png');
/// File path: assets/images/sparky/character.png
AssetGenImage get character =>
const AssetGenImage('assets/images/sparky/character.png');
/// File path: assets/images/sparky/icon.png
AssetGenImage get icon =>
const AssetGenImage('assets/images/sparky/icon.png');
}
class Assets {

@ -8,9 +8,18 @@ class AndroidTheme extends CharacterTheme {
/// {@macro android_theme}
const AndroidTheme();
@override
String get name => 'Android';
@override
Color get ballColor => Colors.green;
@override
AssetGenImage get characterAsset => Assets.images.android;
AssetGenImage get character => Assets.images.android.character;
@override
AssetGenImage get background => Assets.images.android.background;
@override
AssetGenImage get icon => Assets.images.android.icon;
}

@ -12,12 +12,27 @@ abstract class CharacterTheme extends Equatable {
/// {@macro character_theme}
const CharacterTheme();
/// Name of character.
String get name;
/// Ball color for this theme.
Color get ballColor;
/// Asset for the theme character.
AssetGenImage get characterAsset;
AssetGenImage get character;
/// Asset for the background.
AssetGenImage get background;
/// Icon asset.
AssetGenImage get icon;
@override
List<Object?> get props => [ballColor];
List<Object?> get props => [
name,
ballColor,
character,
background,
icon,
];
}

@ -8,9 +8,18 @@ class DashTheme extends CharacterTheme {
/// {@macro dash_theme}
const DashTheme();
@override
String get name => 'Dash';
@override
Color get ballColor => Colors.blue;
@override
AssetGenImage get characterAsset => Assets.images.dash;
AssetGenImage get character => Assets.images.dash.character;
@override
AssetGenImage get background => Assets.images.dash.background;
@override
AssetGenImage get icon => Assets.images.dash.icon;
}

@ -8,9 +8,18 @@ class DinoTheme extends CharacterTheme {
/// {@macro dino_theme}
const DinoTheme();
@override
String get name => 'Dino';
@override
Color get ballColor => Colors.grey;
@override
AssetGenImage get characterAsset => Assets.images.dino;
AssetGenImage get character => Assets.images.dino.character;
@override
AssetGenImage get background => Assets.images.dino.background;
@override
AssetGenImage get icon => Assets.images.dino.icon;
}

@ -12,5 +12,14 @@ class SparkyTheme extends CharacterTheme {
Color get ballColor => Colors.orange;
@override
AssetGenImage get characterAsset => Assets.images.sparky;
String get name => 'Sparky';
@override
AssetGenImage get character => Assets.images.sparky.character;
@override
AssetGenImage get background => Assets.images.sparky.background;
@override
AssetGenImage get icon => Assets.images.sparky.icon;
}

@ -21,9 +21,15 @@ flutter:
generate: true
assets:
- assets/images/
- assets/images/android/
- assets/images/dash/
- assets/images/dino/
- assets/images/sparky/
flutter_gen:
assets:
package_parameter_enabled: true
output: lib/src/generated/
line_length: 80
integrations:
flutter_svg: true

@ -18,8 +18,22 @@ void main() {
expect(AndroidTheme().ballColor, equals(Colors.green));
});
test('characterAsset is correct', () {
expect(AndroidTheme().characterAsset, equals(Assets.images.android));
test('character asset is correct', () {
expect(
AndroidTheme().character,
equals(Assets.images.android.character),
);
});
test('background asset is correct', () {
expect(
AndroidTheme().background,
equals(Assets.images.android.background),
);
});
test('icon asset is correct', () {
expect(AndroidTheme().icon, equals(Assets.images.android.icon));
});
});
}

@ -18,8 +18,22 @@ void main() {
expect(DashTheme().ballColor, equals(Colors.blue));
});
test('characterAsset is correct', () {
expect(DashTheme().characterAsset, equals(Assets.images.dash));
test('character asset is correct', () {
expect(
DashTheme().character,
equals(Assets.images.dash.character),
);
});
test('background asset is correct', () {
expect(
DashTheme().background,
equals(Assets.images.dash.background),
);
});
test('icon asset is correct', () {
expect(DashTheme().icon, equals(Assets.images.dash.icon));
});
});
}

@ -18,8 +18,22 @@ void main() {
expect(DinoTheme().ballColor, equals(Colors.grey));
});
test('characterAsset is correct', () {
expect(DinoTheme().characterAsset, equals(Assets.images.dino));
test('character asset is correct', () {
expect(
DinoTheme().character,
equals(Assets.images.dino.character),
);
});
test('background asset is correct', () {
expect(
DinoTheme().background,
equals(Assets.images.dino.background),
);
});
test('icon asset is correct', () {
expect(DinoTheme().icon, equals(Assets.images.dino.icon));
});
});
}

@ -18,8 +18,22 @@ void main() {
expect(SparkyTheme().ballColor, equals(Colors.orange));
});
test('characterAsset is correct', () {
expect(SparkyTheme().characterAsset, equals(Assets.images.sparky));
test('character asset is correct', () {
expect(
SparkyTheme().character,
equals(Assets.images.sparky.character),
);
});
test('background asset is correct', () {
expect(
SparkyTheme().background,
equals(Assets.images.sparky.background),
);
});
test('icon asset is correct', () {
expect(SparkyTheme().icon, equals(Assets.images.sparky.icon));
});
});
}

@ -30,7 +30,7 @@ void main() {
rank: '1',
playerInitials: 'ABC',
score: 1500,
character: DashTheme().characterAsset,
character: DashTheme().character,
);
test(

@ -121,7 +121,7 @@ void main() {
rank: '1',
playerInitials: 'ABC',
score: 10000,
character: DashTheme().characterAsset,
character: DashTheme().character,
),
],
),

Loading…
Cancel
Save