Skip to content

Commit

Permalink
Replace add_system_to_schedule to update to latest bevy commit
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Feb 24, 2023
1 parent a411640 commit a7ae554
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 53 deletions.
2 changes: 1 addition & 1 deletion bevy_asset_loader/examples/atlas_from_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {
.add_collection_to_loading_state::<_, MyAssets>(MyStates::AssetLoading)
.insert_resource(Msaa::Off)
.add_plugins(DefaultPlugins)
.add_system_to_schedule(OnEnter(MyStates::Next), draw_atlas)
.add_system(draw_atlas.in_schedule(OnEnter(MyStates::Next)))
.add_system(animate_sprite_system.run_if(in_state(MyStates::Next)))
.run();
}
Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/examples/custom_dynamic_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
"custom.my-assets.ron",
)
.add_collection_to_loading_state::<_, MyAssets>(MyStates::AssetLoading)
.add_system_to_schedule(OnEnter(MyStates::Next), render_stuff)
.add_system(render_stuff.in_schedule(OnEnter(MyStates::Next)))
.run();
}

Expand Down
4 changes: 2 additions & 2 deletions bevy_asset_loader/examples/failure_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fn main() {
)
.add_collection_to_loading_state::<_, MyAssets>(MyStates::AssetLoading)
.add_system(timeout.run_if(in_state(MyStates::AssetLoading)))
.add_system_to_schedule(OnEnter(MyStates::Next), fail)
.add_system_to_schedule(OnEnter(MyStates::ErrorScreen), ok)
.add_system(fail.in_schedule(OnEnter(MyStates::Next)))
.add_system(ok.in_schedule(OnEnter(MyStates::ErrorScreen)))
.run();
}

Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/examples/full_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
LoadingState::new(MyStates::AssetLoading).continue_to_state(MyStates::Next),
)
.add_collection_to_loading_state::<_, MyAssets>(MyStates::AssetLoading)
.add_system_to_schedule(OnEnter(MyStates::Next), expectations)
.add_system(expectations.in_schedule(OnEnter(MyStates::Next)))
.run();
}

Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/examples/init_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
.init_resource_after_loading_state::<_, CombinedImage>(MyStates::AssetLoading)
.insert_resource(Msaa::Off)
.add_plugins(DefaultPlugins)
.add_system_to_schedule(OnEnter(MyStates::Next), draw)
.add_system(draw.in_schedule(OnEnter(MyStates::Next)))
.run();
}

Expand Down
6 changes: 3 additions & 3 deletions bevy_asset_loader/examples/manual_dynamic_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ fn main() {
OnEnter(MyStates::Next),
(spawn_player_and_tree, play_background_audio),
)
.add_system_to_schedule(OnEnter(MyStates::Menu), menu)
.add_system(menu.in_schedule(OnEnter(MyStates::Menu)))
.add_system(character_setup.run_if(in_state(MyStates::Menu)))
.add_system(update_menu.run_if(in_state(MyStates::Menu)))
.add_system_to_schedule(OnExit(MyStates::Menu), exit_menu)
.add_system_to_schedule(OnEnter(MyStates::Next), render_optional_background)
.add_system(exit_menu.in_schedule(OnExit(MyStates::Menu)))
.add_system(render_optional_background.in_schedule(OnEnter(MyStates::Next)))
.add_system(move_player.run_if(in_state(MyStates::Next)))
.run();
}
Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/examples/no_loading_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
.init_collection::<ImageAssets>()
// This system listens for mouse clicks and then loads + inserts the AudioAssets collection
.add_system(load_and_play_audio)
.add_startup_system(draw)
.add_system(draw.on_startup())
.run();
}

Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/examples/progress_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
// track progress during `MyStates::AssetLoading` and continue to `MyStates::Next` when progress is completed
.add_plugin(ProgressPlugin::new(MyStates::AssetLoading).continue_to(MyStates::Next))
// gracefully quit the app when `MyStates::Next` is reached
.add_system_to_schedule(OnEnter(MyStates::Next), expect)
.add_system(expect.in_schedule(OnEnter(MyStates::Next)))
.add_system(
track_fake_long_task
.before(print_progress)
Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/examples/standard_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() {
brightness: 0.2,
})
.add_plugins(DefaultPlugins)
.add_system_to_schedule(OnEnter(MyStates::Next), spawn_player)
.add_system(spawn_player.in_schedule(OnEnter(MyStates::Next)))
.run();
}

Expand Down
63 changes: 31 additions & 32 deletions bevy_asset_loader/src/loading_state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod dynamic_asset_systems;
mod systems;

use bevy::app::{App, CoreSet};
use bevy::app::{App, CoreSet, IntoSystemAppConfig};
use bevy::asset::{Asset, HandleUntyped};
use bevy::ecs::schedule::{
common_conditions::in_state, IntoSystemConfig, IntoSystemSetConfig, NextState, OnEnter, States,
Expand Down Expand Up @@ -375,24 +375,21 @@ where
));

if configure_loading_state {
app.add_system_to_schedule(
loading_state_schedule.clone(),
app.add_systems((
resume_to_loading_asset_collections::<S>
.in_schedule(loading_state_schedule.clone())
.in_set(InternalLoadingStateSet::ResumeDynamicAssetCollections),
)
.add_system_to_schedule(
loading_state_schedule.clone(),
initialize_loading_state.in_set(InternalLoadingStateSet::Initialize),
)
.add_system_to_schedule(
loading_state_schedule.clone(),
resume_to_finalize::<S>.in_set(InternalLoadingStateSet::CheckAssets),
)
.add_system_to_schedule(
loading_state_schedule.clone(),
finish_loading_state::<S>.in_set(InternalLoadingStateSet::Finalize),
)
.add_system_to_schedule(OnEnter(self.loading_state.clone()), reset_loading_state)
initialize_loading_state
.in_schedule(loading_state_schedule.clone())
.in_set(InternalLoadingStateSet::Initialize),
resume_to_finalize::<S>
.in_schedule(loading_state_schedule.clone())
.in_set(InternalLoadingStateSet::CheckAssets),
finish_loading_state::<S>
.in_schedule(loading_state_schedule.clone())
.in_set(InternalLoadingStateSet::Finalize),
))
.add_system(reset_loading_state.in_schedule(OnEnter(self.loading_state.clone())))
.configure_set(
LoadingStateSet(self.loading_state.clone())
.after(CoreSet::StateTransitions)
Expand Down Expand Up @@ -674,13 +671,16 @@ impl LoadingStateAppExt for App {
&mut self,
loading_state: S,
) -> &mut Self {
self.add_system_to_schedule(
OnEnterInternalLoadingState(loading_state.clone(), InternalLoadingState::LoadingAssets),
start_loading_collection::<S, A>,
self.add_system(
start_loading_collection::<S, A>.in_schedule(OnEnterInternalLoadingState(
loading_state.clone(),
InternalLoadingState::LoadingAssets,
)),
)
.add_system_to_schedule(
LoadingStateSchedule(loading_state),
check_loading_collection::<S, A>.in_set(InternalLoadingStateSet::CheckAssets),
.add_system(
check_loading_collection::<S, A>
.in_schedule(LoadingStateSchedule(loading_state))
.in_set(InternalLoadingStateSet::CheckAssets),
)
}

Expand Down Expand Up @@ -708,16 +708,15 @@ impl LoadingStateAppExt for App {
.insert(loading_state.clone(), dynamic_collections_for_state);

self.init_resource::<LoadingAssetHandles<C>>()
.add_system_to_schedule(
.add_system(load_dynamic_asset_collections::<S, C>.in_schedule(
OnEnterInternalLoadingState(
loading_state.clone(),
InternalLoadingState::LoadingDynamicAssetCollections,
),
load_dynamic_asset_collections::<S, C>,
)
.add_system_to_schedule(
LoadingStateSchedule(loading_state),
))
.add_system(
check_dynamic_asset_collections::<S, C>
.in_schedule(LoadingStateSchedule(loading_state))
.in_set(InternalLoadingStateSet::CheckDynamicAssetCollections),
)
}
Expand All @@ -726,9 +725,9 @@ impl LoadingStateAppExt for App {
&mut self,
loading_state: S,
) -> &mut Self {
self.add_system_to_schedule(
OnEnterInternalLoadingState(loading_state, InternalLoadingState::Finalize),
init_resource::<A>,
)
self.add_system(init_resource::<A>.in_schedule(OnEnterInternalLoadingState(
loading_state,
InternalLoadingState::Finalize,
)))
}
}
4 changes: 2 additions & 2 deletions bevy_asset_loader/tests/continues_to_failure_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ fn continues_to_failure_state() {
)
.add_collection_to_loading_state::<_, Audio>(MyStates::Load)
.add_system(timeout.run_if(in_state(MyStates::Load)))
.add_system_to_schedule(OnEnter(MyStates::Next), fail)
.add_system_to_schedule(OnEnter(MyStates::Error), exit)
.add_system(fail.in_schedule(OnEnter(MyStates::Next)))
.add_system(exit.in_schedule(OnEnter(MyStates::Error)))
.run();
}

Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/tests/continues_without_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn continues_without_collection() {
.add_loading_state(LoadingState::new(MyStates::Load).continue_to_state(MyStates::Next))
.init_resource::<TestState>()
.add_system(expect.run_if(in_state(MyStates::Load)))
.add_system_to_schedule(OnEnter(MyStates::Next), exit)
.add_system(exit.in_schedule(OnEnter(MyStates::Next)))
.run();
}

Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/tests/init_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn init_resource() {
.add_collection_to_loading_state::<_, MyAssets>(MyStates::Load)
.init_resource_after_loading_state::<_, PostProcessed>(MyStates::Load)
.add_system(timeout.run_if(in_state(MyStates::Load)))
.add_system_to_schedule(OnEnter(MyStates::Next), expect)
.add_system(expect.in_schedule(OnEnter(MyStates::Next)))
.run();
}

Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/tests/multiple_asset_collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn multiple_asset_collections() {
.add_collection_to_loading_state::<_, PlopAudio>(MyStates::Load)
.add_collection_to_loading_state::<_, BackgroundAudio>(MyStates::Load)
.add_system(timeout.run_if(in_state(MyStates::Load)))
.add_system_to_schedule(OnEnter(MyStates::Next), expect)
.add_system(expect.in_schedule(OnEnter(MyStates::Next)))
.run();
}

Expand Down
17 changes: 13 additions & 4 deletions bevy_asset_loader/tests/multiple_loading_states.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#![allow(dead_code, unused_imports)]

use bevy::app::AppExit;
use bevy::audio::AudioPlugin;
use bevy::prelude::*;
use bevy_asset_loader::asset_collection::AssetCollection;
use bevy_asset_loader::loading_state::{LoadingState, LoadingStateAppExt};

#[cfg(all(
not(feature = "2d"),
not(feature = "3d"),
not(feature = "progress_tracking")
))]
#[test]
fn multiple_loading_states() {
App::new()
Expand All @@ -13,16 +20,18 @@ fn multiple_loading_states() {
.add_plugin(AudioPlugin::default())
.add_loading_state(LoadingState::new(MyStates::Splash).continue_to_state(MyStates::Load))
.add_collection_to_loading_state::<_, SplashAssets>(MyStates::Splash)
.add_loading_state(LoadingState::new(MyStates::Load).continue_to_state(MyStates::Play))
.add_collection_to_loading_state::<_, MyAssets>(MyStates::Load)
.add_collection_to_loading_state::<_, MyOtherAssets>(MyStates::Load)
.add_system(timeout)
.add_system_to_schedule(OnEnter(MyStates::Load), use_splash_assets)
.add_system_to_schedule(OnEnter(MyStates::Play), use_loading_assets)
.add_system(use_splash_assets.in_schedule(OnEnter(MyStates::Load)))
.add_system(use_loading_assets.in_schedule(OnEnter(MyStates::Play)))
.add_system(quit.run_if(in_state(MyStates::Play)))
.run();
}

fn timeout(time: Res<Time>) {
println!("Frame");
if time.elapsed_seconds_f64() > 5. {
if time.elapsed_seconds_f64() > 30. {
panic!("The app did not finish in 30 seconds");
}
}
Expand Down

0 comments on commit a7ae554

Please sign in to comment.