diff --git a/bevy_asset_loader/examples/atlas_from_grid.rs b/bevy_asset_loader/examples/atlas_from_grid.rs index 39c3325..8ad4f6b 100644 --- a/bevy_asset_loader/examples/atlas_from_grid.rs +++ b/bevy_asset_loader/examples/atlas_from_grid.rs @@ -13,7 +13,7 @@ fn main() { LoadingState::new(MyStates::AssetLoading).continue_to_state(MyStates::Next), ) .configure_loading_state( - LoadingStateConfig::new(MyStates::AssetLoading).with_collection::(), + LoadingStateConfig::new(MyStates::AssetLoading).add_collection::(), ) .add_systems(OnEnter(MyStates::Next), draw_atlas) .add_systems( diff --git a/bevy_asset_loader/examples/init_resource.rs b/bevy_asset_loader/examples/init_resource.rs index 9987a71..3df8306 100644 --- a/bevy_asset_loader/examples/init_resource.rs +++ b/bevy_asset_loader/examples/init_resource.rs @@ -1,4 +1,5 @@ use bevy::prelude::*; +use bevy_asset_loader::loading_state::LoadingStateConfig; use bevy_asset_loader::prelude::*; /// This example demonstrates how you can use [`App::init_resource_after_loading_state`] to initialize @@ -13,8 +14,11 @@ fn main() { .add_loading_state( LoadingState::new(MyStates::AssetLoading).continue_to_state(MyStates::Next), ) - .add_collection_to_loading_state::<_, ImageAssets>(MyStates::AssetLoading) - .init_resource_after_loading_state::<_, CombinedImage>(MyStates::AssetLoading) + .configure_loading_state( + LoadingStateConfig::new(MyStates::AssetLoading) + .add_collection::() + .init_resource::(), + ) .add_systems(OnEnter(MyStates::Next), draw) .run(); } diff --git a/bevy_asset_loader/src/loading_state.rs b/bevy_asset_loader/src/loading_state.rs index 3adb122..ba38e71 100644 --- a/bevy_asset_loader/src/loading_state.rs +++ b/bevy_asset_loader/src/loading_state.rs @@ -587,6 +587,10 @@ pub trait LoadingStateAppExt { /// # pub tree: Handle, /// # } /// ``` + #[deprecated( + since = "0.19.0", + note = "Use configure_loading_state and [`LoadingStateConfig::add_collection`] instead." + )] fn add_collection_to_loading_state( &mut self, loading_state: S, @@ -660,6 +664,10 @@ pub trait LoadingStateAppExt { /// # pub array: Handle, /// # } /// ``` + #[deprecated( + since = "0.19.0", + note = "Use configure_loading_state and [`LoadingStateConfig::init_resource`] instead." + )] fn init_resource_after_loading_state( &mut self, loading_state: S, @@ -673,23 +681,25 @@ pub trait LoadingStateAppExt { pub struct LoadingStateConfig { state: S, - start_loading: Vec, - check_loading: Vec, + on_enter_loading_assets: Vec, + on_update: Vec, + on_enter_finalize: Vec, } impl LoadingStateConfig { pub fn new(state: S) -> Self { Self { state, - start_loading: vec![], - check_loading: vec![], + on_enter_loading_assets: vec![], + on_update: vec![], + on_enter_finalize: vec![], } } - pub fn with_collection(mut self) -> Self { - self.start_loading + pub fn add_collection(mut self) -> Self { + self.on_enter_loading_assets .push(start_loading_collection::.into_configs()); - self.check_loading.push( + self.on_update.push( check_loading_collection:: .in_set(InternalLoadingStateSet::CheckAssets) .into_configs(), @@ -698,8 +708,17 @@ impl LoadingStateConfig { self } + /// The resource will be initialized at the end of the loading state using its [`FromWorld`] implementation. + /// All asset collections will be available at that point and fully loaded. + pub fn init_resource(mut self) -> Self { + self.on_enter_finalize + .push(init_resource::.into_configs()); + + self + } + fn build(self, app: &mut App) { - for config in self.start_loading { + for config in self.on_enter_loading_assets { app.add_systems( OnEnterInternalLoadingState( self.state.clone(), @@ -708,9 +727,15 @@ impl LoadingStateConfig { config, ); } - for config in self.check_loading { + for config in self.on_update { app.add_systems(LoadingStateSchedule(self.state.clone()), config); } + for config in self.on_enter_finalize { + self.add_systems( + OnEnterInternalLoadingState(self.state.clone(), InternalLoadingState::Finalize), + config, + ); + } } }