mirror of https://github.com/flutter/pinball.git
feat: add board background asset (#270)
* feat: add board background sprite
* test: board background sprite
* fix: ignore coverage for dead code
* fix: swap comment order for lint
* fix: comment unused code
* fix: remove unused import 🤦♀️
pull/272/head
parent
920c8b51d8
commit
3991207d62
After Width: | Height: | Size: 1.3 MiB |
@ -0,0 +1,26 @@
|
|||||||
|
// ignore_for_file: public_member_api_docs
|
||||||
|
|
||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
class BoardBackgroundSpriteComponent extends SpriteComponent with HasGameRef {
|
||||||
|
BoardBackgroundSpriteComponent()
|
||||||
|
: super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
priority: RenderPriority.boardBackground,
|
||||||
|
position: Vector2(0, -1),
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
|
||||||
|
final sprite = Sprite(
|
||||||
|
gameRef.images.fromCache(
|
||||||
|
Assets.images.boardBackground.keyName,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
this.sprite = sprite;
|
||||||
|
size = sprite.originalSize / 10;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame/components.dart';
|
||||||
|
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() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final assets = [
|
||||||
|
Assets.images.boardBackground.keyName,
|
||||||
|
];
|
||||||
|
final flameTester = FlameTester(() => TestGame(assets));
|
||||||
|
|
||||||
|
group('BoardBackgroundSpriteComponent', () {
|
||||||
|
flameTester.test(
|
||||||
|
'loads correctly',
|
||||||
|
(game) async {
|
||||||
|
final boardBackground = BoardBackgroundSpriteComponent();
|
||||||
|
await game.ensureAdd(boardBackground);
|
||||||
|
|
||||||
|
expect(game.contains(boardBackground), isTrue);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.testGameWidget(
|
||||||
|
'renders correctly',
|
||||||
|
setUp: (game, tester) async {
|
||||||
|
await game.images.loadAll(assets);
|
||||||
|
final boardBackground = BoardBackgroundSpriteComponent();
|
||||||
|
await game.ensureAdd(boardBackground);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
game.camera
|
||||||
|
..followVector2(Vector2.zero())
|
||||||
|
..zoom = 3.7;
|
||||||
|
},
|
||||||
|
verify: (game, tester) async {
|
||||||
|
await expectLater(
|
||||||
|
find.byGame<TestGame>(),
|
||||||
|
matchesGoldenFile('golden/board-background.png'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
After Width: | Height: | Size: 1.5 MiB |
Loading…
Reference in new issue