refactor: changed how Sprites are loaded

pull/205/head
alestiago 3 years ago
parent 85468d6258
commit 773d97ae0c

@ -81,8 +81,7 @@ class _SignPostSpriteComponent
// sprites[spriteState] = Sprite( // sprites[spriteState] = Sprite(
// gameRef.images.fromCache(spriteState.path), // gameRef.images.fromCache(spriteState.path),
// ); // );
sprites[spriteState] = sprites[spriteState] = await gameRef.loadSprite(spriteState.path);
Sprite(await gameRef.images.load(spriteState.path));
} }
current = _SignPostSpriteState.inactive; current = _SignPostSpriteState.inactive;

@ -17,13 +17,6 @@ class SignPostGame extends BasicBallGame with Traceable, TapDetector {
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await Future.wait([
loadSprite(Assets.images.signPost.inactive.keyName),
loadSprite(Assets.images.signPost.active1.keyName),
loadSprite(Assets.images.signPost.active2.keyName),
loadSprite(Assets.images.signPost.active3.keyName),
]);
camera.followVector2(Vector2.zero()); camera.followVector2(Vector2.zero());
await add(SignPost()..priority = 1); await add(SignPost()..priority = 1);
await traceAllBodies(); await traceAllBodies();

@ -7,25 +7,14 @@ import 'package:pinball_components/pinball_components.dart';
import '../../helpers/helpers.dart'; import '../../helpers/helpers.dart';
// TODO(allisonryan0002): Refactor loading assets in test with
// https://github.com/VGVentures/pinball/pull/204
void main() { void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(TestGame.new); final flameTester = FlameTester(TestGame.new);
group('SignPost', () { group('SignPost', () {
final assets = [
Assets.images.signPost.inactive.keyName,
Assets.images.signPost.active1.keyName,
Assets.images.signPost.active2.keyName,
Assets.images.signPost.active3.keyName,
];
flameTester.test( flameTester.test(
'loads correctly', 'loads correctly',
(game) async { (game) async {
await game.images.loadAll(assets);
final signPost = SignPost(); final signPost = SignPost();
await game.ready(); await game.ready();
await game.ensureAdd(signPost); await game.ensureAdd(signPost);
@ -38,7 +27,6 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'inactive sprite', 'inactive sprite',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets);
await game.ensureAdd(SignPost()); await game.ensureAdd(SignPost());
game.camera.followVector2(Vector2.zero()); game.camera.followVector2(Vector2.zero());
}, },
@ -53,8 +41,6 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'active1 sprite', 'active1 sprite',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets);
final signPost = SignPost(); final signPost = SignPost();
await game.ensureAdd(signPost); await game.ensureAdd(signPost);
signPost.progress(); signPost.progress();
@ -72,8 +58,6 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'active2 sprite', 'active2 sprite',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets);
final signPost = SignPost(); final signPost = SignPost();
await game.ensureAdd(signPost); await game.ensureAdd(signPost);
signPost signPost
@ -93,8 +77,6 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'active3 sprite', 'active3 sprite',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets);
final signPost = SignPost(); final signPost = SignPost();
await game.ensureAdd(signPost); await game.ensureAdd(signPost);
signPost signPost
@ -116,7 +98,6 @@ void main() {
flameTester.test( flameTester.test(
'progress changes correctly between four sprites', 'progress changes correctly between four sprites',
(game) async { (game) async {
await game.images.loadAll(assets);
final signPost = SignPost(); final signPost = SignPost();
await game.ready(); await game.ready();
await game.ensureAdd(signPost); await game.ensureAdd(signPost);

Loading…
Cancel
Save