#API changes for bevy_asset_loader

2 messages · Page 1 of 1 (latest)

lucid ridge
#

I am toying with an API change in bevy_asset_loader and am hoping for some criticism/bike shedding.
The current API has separate extension methods on Bevy's App to add a loading state and to configure it with, for example, collections. The configuration extension methods require some ugly generics and all take the state.

The new API only has two methods on App: add_loading_state and configure_loading_state. Both allow to add any number of asset collections and other configuration.

This is the diff for adding some collections and a dynamic asset file directly to a loading state:

         .add_loading_state(
-            LoadingState::new(MyStates::AssetLoading).continue_to_state(MyStates::Next),
+            LoadingState::new(MyStates::AssetLoading)
+                .continue_to_state(MyStates::Next)
+                .with_dynamic_assets_file::<StandardDynamicAssetCollection>(
+                    "dynamic_asset.assets.ron",
+                )
+                .load_collection::<ImageAssets>()
+                .load_collection::<AudioAssets>(),
         )
-        .add_dynamic_collection_to_loading_state::<_, StandardDynamicAssetCollection>(
-            MyStates::AssetLoading,
-            "dynamic_asset.assets.ron",
-        )
-        .add_collection_to_loading_state::<_, ImageAssets>(MyStates::AssetLoading)
-        .add_collection_to_loading_state::<_, AudioAssets>(MyStates::AssetLoading)

Any opinions on the changes? Anything you ever wanted changed about the API of bevy_asset_loader?
The full WIP changes can be seen in a draft PR.

GitHub

GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.

#

One can also use configure_loading_state somewhere else in the application if the loadign state was previously added:

struct PlayerAndMusicPlugin;

impl Plugin for PlayerAndMusicPlugin {
    fn build(&self, app: &mut App) {
        app
            // We can add all kinds of things to the loading state here. This method can be called from any plugin any number of times.
            .configure_loading_state(
                LoadingStateConfig::new(MyStates::AssetLoading)
                    .load_collection::<AudioAssets>()
                    .load_collection::<ImageAssets>()
                    .init_resource::<ExampleResource>(),
            );
    }
}