Skip to content

Commit

Permalink
refactor: Deprecate fromAtlas in favour of atlasFromAssets and `a…
Browse files Browse the repository at this point in the history
…tlasFromStorage` (#3098)

Originally, the function was named `fromAtlas` because there was another
function named `fromJson` that loaded `.json` files. but since that one
is gone, and now every function is loading a `.atlas` it make sense to
have `fromAssets` and `fromStorage`

---------

Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
  • Loading branch information
Yayo-Arellano and spydon committed Mar 27, 2024
1 parent b946ba7 commit 6c8190b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/flame_texturepacker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Import the plugin like this:
Load the TextureAtlas passing the path of the sprite sheet atlas file:

```Dart
final atlas = await fromAtlas('atlas_map.atlas');
final atlas = await atlasFromAssets('atlas_map.atlas');
```


Expand All @@ -66,7 +66,7 @@ If you are using file storage, grab your atlas file like this:

```Dart
final documentsPath = (await getApplicationDocumentsDirectory()).path;
final atlas = await fromAtlas('$documentsPath/atlas_map.atlas', fromStorage: true);
final atlas = await atlasFromStorage('$documentsPath/atlas_map.atlas');
```

Get a list of sprites ordered by their index, you can use the list to generate an animation:
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_texturepacker/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MyGame extends FlameGame {
super.onLoad();

// Load the atlasMap.
final atlas = await fromAtlas('atlas_map.atlas');
final atlas = await atlasFromAssets('atlas_map.atlas');

// Get a list of sprites ordered by their index
final walkingSprites = atlas.findSpritesByName('robot_walk');
Expand Down
11 changes: 11 additions & 0 deletions packages/flame_texturepacker/lib/flame_texturepacker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ export 'package:flame_texturepacker/src/texture_packer_sprite.dart';
extension TexturepackerLoader on Game {
/// Loads the specified pack file.
/// Uses the parent directory of the pack file to find the page images.
@Deprecated('Use [atlasFromAssets] or [atlasFromStorage] instead')
Future<TexturePackerAtlas> fromAtlas(
String assetsPath, {
bool fromStorage = false,
}) async =>
TexturePackerAtlas.load(assetsPath, fromStorage: fromStorage);

/// Loads the specified pack file from assets
/// Uses the parent directory of the pack file to find the page images.
Future<TexturePackerAtlas> atlasFromAssets(String assetsPath) async =>
TexturePackerAtlas.load(assetsPath);

/// Loads the specified pack file from storage
/// Uses the parent directory of the pack file to find the page images.
Future<TexturePackerAtlas> atlasFromStorage(String storagePath) async =>
TexturePackerAtlas.load(storagePath, fromStorage: true);
}

0 comments on commit 6c8190b

Please sign in to comment.