Skip to content

Commit

Permalink
feat: Adding getter for the atlas image on flame fire atlas
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzanardo committed Oct 2, 2024
1 parent 7746f2f commit 2f5e93d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/flame_fire_atlas/lib/flame_fire_atlas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,9 @@ class FireAtlas {
loop: selection.loop,
);
}

/// Returns the atlas image.
///
/// Throws if called before the image is loaded.
Image get atlasImage => _assertImageLoaded();
}
26 changes: 26 additions & 0 deletions packages/flame_fire_atlas/test/flame_fire_atlas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@ void main() {
expect(atlas.id, 'cave_ace');
});

test('atlasImage returns the loaded image', () async {
final atlas = await _readTestAtlas();
final image = atlas.atlasImage;
expect(image, isA<Image>());
});

test('atlasImage throws when the image is not loaded', () async {
final atlas = FireAtlas(
id: '',
tileWidth: 0,
tileHeight: 0,
imageData: '',
);

expect(
() => atlas.atlasImage,
throwsA(
isA<Exception>().having(
(e) => e.toString(),
'toString',
'Exception: Atlas is not loaded yet, call "load" before using it',
),
),
);
});

test('can load the asset using the global assets/images', () async {
final assetsMock = _AssetsCacheMock();

Expand Down

0 comments on commit 2f5e93d

Please sign in to comment.