test: golden test updated

pull/208/head
RuiAlonso 3 years ago
commit 8474bbda74

@ -47,6 +47,7 @@ extension PinballGameAssetsX on PinballGame {
images.load(components.Assets.images.plunger.rocket.keyName), images.load(components.Assets.images.plunger.rocket.keyName),
images.load(components.Assets.images.boundary.bottom.keyName), images.load(components.Assets.images.boundary.bottom.keyName),
images.load(components.Assets.images.boundary.outer.keyName), images.load(components.Assets.images.boundary.outer.keyName),
images.load(components.Assets.images.boundary.outerBottom.keyName),
images.load(components.Assets.images.spaceship.saucer.keyName), images.load(components.Assets.images.spaceship.saucer.keyName),
images.load(components.Assets.images.spaceship.bridge.keyName), images.load(components.Assets.images.spaceship.bridge.keyName),
images.load(components.Assets.images.spaceship.ramp.boardOpening.keyName), images.load(components.Assets.images.spaceship.ramp.boardOpening.keyName),

@ -2,6 +2,7 @@
import 'dart:async'; import 'dart:async';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart'; import 'package:flame/input.dart';
import 'package:flame_bloc/flame_bloc.dart'; import 'package:flame_bloc/flame_bloc.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
@ -134,7 +135,7 @@ class _GameBallsController extends ComponentController<PinballGame>
} }
} }
class DebugPinballGame extends PinballGame with TapDetector { class DebugPinballGame extends PinballGame with FPSCounter, TapDetector {
DebugPinballGame({ DebugPinballGame({
required PinballTheme theme, required PinballTheme theme,
required PinballAudio audio, required PinballAudio audio,
@ -149,6 +150,7 @@ class DebugPinballGame extends PinballGame with TapDetector {
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await _loadBackground(); await _loadBackground();
await add(_DebugInformation());
} }
// TODO(alestiago): Move to PinballGame once we have the real background // TODO(alestiago): Move to PinballGame once we have the real background
@ -191,3 +193,35 @@ class _DebugGameBallsController extends _GameBallsController {
return noBallsLeft && canBallRespawn; return noBallsLeft && canBallRespawn;
} }
} }
class _DebugInformation extends Component with HasGameRef<DebugPinballGame> {
_DebugInformation() : super(priority: RenderPriority.debugInfo);
@override
PositionType get positionType => PositionType.widget;
final _debugTextPaint = TextPaint(
style: const TextStyle(
color: Colors.green,
fontSize: 10,
),
);
final _debugBackgroundPaint = Paint()..color = Colors.white;
@override
void render(Canvas canvas) {
final debugText = [
'FPS: ${gameRef.fps().toStringAsFixed(1)}',
'BALLS: ${gameRef.descendants().whereType<ControlledBall>().length}',
].join(' | ');
final height = _debugTextPaint.measureTextHeight(debugText);
final position = Vector2(0, gameRef.camera.canvasSize.y - height);
canvas.drawRect(
position & Vector2(gameRef.camera.canvasSize.x, height),
_debugBackgroundPaint,
);
_debugTextPaint.render(canvas, debugText, position);
}
}

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

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

@ -86,6 +86,10 @@ class $AssetsImagesBoundaryGen {
AssetGenImage get bottom => AssetGenImage get bottom =>
const AssetGenImage('assets/images/boundary/bottom.png'); const AssetGenImage('assets/images/boundary/bottom.png');
/// File path: assets/images/boundary/outer-bottom.png
AssetGenImage get outerBottom =>
const AssetGenImage('assets/images/boundary/outer-bottom.png');
/// File path: assets/images/boundary/outer.png /// File path: assets/images/boundary/outer.png
AssetGenImage get outer => AssetGenImage get outer =>
const AssetGenImage('assets/images/boundary/outer.png'); const AssetGenImage('assets/images/boundary/outer.png');

@ -13,6 +13,7 @@ class Boundaries extends Blueprint {
components: [ components: [
_BottomBoundary(), _BottomBoundary(),
_OuterBoundary(), _OuterBoundary(),
_OuterBottomBoundarySpriteComponent(),
], ],
); );
} }
@ -91,8 +92,10 @@ class _OuterBoundary extends BodyComponent with InitialPosition {
/// {@macro outer_boundary} /// {@macro outer_boundary}
_OuterBoundary() _OuterBoundary()
: super( : super(
priority: RenderPriority.outerBoudary, priority: RenderPriority.outerBoundary,
children: [_OuterBoundarySpriteComponent()], children: [
_OuterBoundarySpriteComponent(),
],
) { ) {
renderBody = false; renderBody = false;
} }
@ -157,3 +160,25 @@ class _OuterBoundarySpriteComponent extends SpriteComponent with HasGameRef {
size = sprite.originalSize / 10; size = sprite.originalSize / 10;
} }
} }
class _OuterBottomBoundarySpriteComponent extends SpriteComponent
with HasGameRef {
_OuterBottomBoundarySpriteComponent()
: super(
priority: RenderPriority.outerBottomBoundary,
anchor: Anchor.center,
position: Vector2(0, 71),
);
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = Sprite(
gameRef.images.fromCache(
Assets.images.boundary.outerBottom.keyName,
),
);
this.sprite = sprite;
size = sprite.originalSize / 10;
}
}

@ -39,7 +39,9 @@ abstract class RenderPriority {
static const int bottomBoundary = _above + dinoBottomWall; static const int bottomBoundary = _above + dinoBottomWall;
static const int outerBoudary = _above + background; static const int outerBoundary = _above + background;
static const int outerBottomBoundary = _above + rocket;
// Bottom Group // Bottom Group
@ -47,7 +49,7 @@ abstract class RenderPriority {
// Launcher // Launcher
static const int launchRamp = _above + outerBoudary; static const int launchRamp = _above + outerBoundary;
static const int launchRampForegroundRailing = _below + ballOnBoard; static const int launchRampForegroundRailing = _below + ballOnBoard;
@ -113,4 +115,7 @@ abstract class RenderPriority {
// Score Text // Score Text
static const int scoreText = _above + spaceshipRampForegroundRailing; static const int scoreText = _above + spaceshipRampForegroundRailing;
// Debug information
static const int debugInfo = _above + scoreText;
} }

@ -18,6 +18,7 @@ class BoundariesGame extends BasicBallGame with Traceable {
await images.loadAll([ await images.loadAll([
Assets.images.boundary.outer.keyName, Assets.images.boundary.outer.keyName,
Assets.images.boundary.outerBottom.keyName,
Assets.images.boundary.bottom.keyName, Assets.images.boundary.bottom.keyName,
]); ]);

@ -10,20 +10,24 @@ import '../../helpers/helpers.dart';
void main() { void main() {
group('Boundaries', () { group('Boundaries', () {
TestWidgetsFlutterBinding.ensureInitialized();
final assets = [ final assets = [
Assets.images.boundary.outer.keyName, Assets.images.boundary.outer.keyName,
Assets.images.boundary.outerBottom.keyName,
Assets.images.boundary.bottom.keyName, Assets.images.boundary.bottom.keyName,
]; ];
final tester = FlameTester(TestGame.new); final flameTester = FlameTester(TestGame.new);
tester.testGameWidget( flameTester.testGameWidget(
'render correctly', 'render correctly',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets); await game.images.loadAll(assets);
await game.addFromBlueprint(Boundaries()); await game.addFromBlueprint(Boundaries());
await game.ready();
game.camera.followVector2(Vector2.zero()); game.camera.followVector2(Vector2.zero());
game.camera.zoom = 3.2; game.camera.zoom = 3.2;
await tester.pump();
}, },
verify: (game, tester) async { verify: (game, tester) async {
await expectLater( await expectLater(

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

@ -28,6 +28,10 @@ class $AssetsImagesGen {
class $AssetsImagesAndroidGen { class $AssetsImagesAndroidGen {
const $AssetsImagesAndroidGen(); const $AssetsImagesAndroidGen();
/// File path: assets/images/android/animation.png
AssetGenImage get animation =>
const AssetGenImage('assets/images/android/animation.png');
/// File path: assets/images/android/background.png /// File path: assets/images/android/background.png
AssetGenImage get background => AssetGenImage get background =>
const AssetGenImage('assets/images/android/background.png'); const AssetGenImage('assets/images/android/background.png');
@ -48,6 +52,10 @@ class $AssetsImagesAndroidGen {
class $AssetsImagesDashGen { class $AssetsImagesDashGen {
const $AssetsImagesDashGen(); const $AssetsImagesDashGen();
/// File path: assets/images/dash/animation.png
AssetGenImage get animation =>
const AssetGenImage('assets/images/dash/animation.png');
/// File path: assets/images/dash/background.png /// File path: assets/images/dash/background.png
AssetGenImage get background => AssetGenImage get background =>
const AssetGenImage('assets/images/dash/background.png'); const AssetGenImage('assets/images/dash/background.png');
@ -67,6 +75,10 @@ class $AssetsImagesDashGen {
class $AssetsImagesDinoGen { class $AssetsImagesDinoGen {
const $AssetsImagesDinoGen(); const $AssetsImagesDinoGen();
/// File path: assets/images/dino/animation.png
AssetGenImage get animation =>
const AssetGenImage('assets/images/dino/animation.png');
/// File path: assets/images/dino/background.png /// File path: assets/images/dino/background.png
AssetGenImage get background => AssetGenImage get background =>
const AssetGenImage('assets/images/dino/background.png'); const AssetGenImage('assets/images/dino/background.png');
@ -86,6 +98,10 @@ class $AssetsImagesDinoGen {
class $AssetsImagesSparkyGen { class $AssetsImagesSparkyGen {
const $AssetsImagesSparkyGen(); const $AssetsImagesSparkyGen();
/// File path: assets/images/sparky/animation.png
AssetGenImage get animation =>
const AssetGenImage('assets/images/sparky/animation.png');
/// File path: assets/images/sparky/background.png /// File path: assets/images/sparky/background.png
AssetGenImage get background => AssetGenImage get background =>
const AssetGenImage('assets/images/sparky/background.png'); const AssetGenImage('assets/images/sparky/background.png');

@ -14,9 +14,6 @@ class AndroidTheme extends CharacterTheme {
@override @override
Color get ballColor => Colors.green; Color get ballColor => Colors.green;
@override
AssetGenImage get character => Assets.images.android.character;
@override @override
AssetGenImage get background => Assets.images.android.background; AssetGenImage get background => Assets.images.android.background;
@ -25,4 +22,7 @@ class AndroidTheme extends CharacterTheme {
@override @override
AssetGenImage get leaderboardIcon => Assets.images.android.leaderboardIcon; AssetGenImage get leaderboardIcon => Assets.images.android.leaderboardIcon;
@override
AssetGenImage get animation => Assets.images.android.animation;
} }

@ -18,9 +18,6 @@ abstract class CharacterTheme extends Equatable {
/// Ball color for this theme. /// Ball color for this theme.
Color get ballColor; Color get ballColor;
/// Asset for the theme character.
AssetGenImage get character;
/// Asset for the background. /// Asset for the background.
AssetGenImage get background; AssetGenImage get background;
@ -30,13 +27,16 @@ abstract class CharacterTheme extends Equatable {
/// Icon asset for the leaderboard. /// Icon asset for the leaderboard.
AssetGenImage get leaderboardIcon; AssetGenImage get leaderboardIcon;
/// Asset for the the idle character animation.
AssetGenImage get animation;
@override @override
List<Object?> get props => [ List<Object?> get props => [
name, name,
ballColor, ballColor,
character,
background, background,
icon, icon,
leaderboardIcon, leaderboardIcon,
animation,
]; ];
} }

@ -14,9 +14,6 @@ class DashTheme extends CharacterTheme {
@override @override
Color get ballColor => Colors.blue; Color get ballColor => Colors.blue;
@override
AssetGenImage get character => Assets.images.dash.character;
@override @override
AssetGenImage get background => Assets.images.dash.background; AssetGenImage get background => Assets.images.dash.background;
@ -25,4 +22,7 @@ class DashTheme extends CharacterTheme {
@override @override
AssetGenImage get leaderboardIcon => Assets.images.dash.leaderboardIcon; AssetGenImage get leaderboardIcon => Assets.images.dash.leaderboardIcon;
@override
AssetGenImage get animation => Assets.images.dash.animation;
} }

@ -14,9 +14,6 @@ class DinoTheme extends CharacterTheme {
@override @override
Color get ballColor => Colors.grey; Color get ballColor => Colors.grey;
@override
AssetGenImage get character => Assets.images.dino.character;
@override @override
AssetGenImage get background => Assets.images.dino.background; AssetGenImage get background => Assets.images.dino.background;
@ -25,4 +22,7 @@ class DinoTheme extends CharacterTheme {
@override @override
AssetGenImage get leaderboardIcon => Assets.images.dino.leaderboardIcon; AssetGenImage get leaderboardIcon => Assets.images.dino.leaderboardIcon;
@override
AssetGenImage get animation => Assets.images.dino.animation;
} }

@ -14,9 +14,6 @@ class SparkyTheme extends CharacterTheme {
@override @override
String get name => 'Sparky'; String get name => 'Sparky';
@override
AssetGenImage get character => Assets.images.sparky.character;
@override @override
AssetGenImage get background => Assets.images.sparky.background; AssetGenImage get background => Assets.images.sparky.background;
@ -25,4 +22,7 @@ class SparkyTheme extends CharacterTheme {
@override @override
AssetGenImage get leaderboardIcon => Assets.images.sparky.leaderboardIcon; AssetGenImage get leaderboardIcon => Assets.images.sparky.leaderboardIcon;
@override
AssetGenImage get animation => Assets.images.sparky.animation;
} }

@ -7,14 +7,14 @@ packages:
name: _fe_analyzer_shared name: _fe_analyzer_shared
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "39.0.0" version: "31.0.0"
analyzer: analyzer:
dependency: transitive dependency: transitive
description: description:
name: analyzer name: analyzer
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.0.0" version: "2.8.0"
args: args:
dependency: transitive dependency: transitive
description: description:
@ -71,6 +71,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.1" version: "1.3.1"
cli_util:
dependency: transitive
description:
name: cli_util
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.5"
clock: clock:
dependency: transitive dependency: transitive
description: description:
@ -314,7 +321,7 @@ packages:
name: js name: js
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.6.4" version: "0.6.3"
json_annotation: json_annotation:
dependency: transitive dependency: transitive
description: description:
@ -349,7 +356,7 @@ packages:
name: material_color_utilities name: material_color_utilities
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.4" version: "0.1.3"
meta: meta:
dependency: transitive dependency: transitive
description: description:
@ -412,7 +419,7 @@ packages:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.1" version: "1.8.0"
path_provider: path_provider:
dependency: transitive dependency: transitive
description: description:
@ -585,7 +592,7 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.2" version: "1.8.1"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
@ -627,21 +634,21 @@ packages:
name: test name: test
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.21.1" version: "1.19.5"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.9" version: "0.4.8"
test_core: test_core:
dependency: transitive dependency: transitive
description: description:
name: test_core name: test_core
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.13" version: "0.4.9"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
@ -662,7 +669,7 @@ packages:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.2" version: "2.1.1"
very_good_analysis: very_good_analysis:
dependency: "direct dev" dependency: "direct dev"
description: description:

@ -50,6 +50,7 @@ void main() {
Assets.images.flipper.left.keyName, Assets.images.flipper.left.keyName,
Assets.images.flipper.right.keyName, Assets.images.flipper.right.keyName,
Assets.images.boundary.outer.keyName, Assets.images.boundary.outer.keyName,
Assets.images.boundary.outerBottom.keyName,
Assets.images.boundary.bottom.keyName, Assets.images.boundary.bottom.keyName,
Assets.images.slingshot.upper.keyName, Assets.images.slingshot.upper.keyName,
Assets.images.slingshot.lower.keyName, Assets.images.slingshot.lower.keyName,

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

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

Loading…
Cancel
Save