|
|
|
@ -9,8 +9,10 @@ impl Plugin for LoadingPlugin {
|
|
|
|
app.init_resource::<TrackLoadingProgress>()
|
|
|
|
app.init_resource::<TrackLoadingProgress>()
|
|
|
|
.init_state::<LoadingState>()
|
|
|
|
.init_state::<LoadingState>()
|
|
|
|
.add_systems(PreUpdate, reset_progress)
|
|
|
|
.add_systems(PreUpdate, reset_progress)
|
|
|
|
|
|
|
|
.add_systems(Startup, spawn_loading_screen)
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
Update,
|
|
|
|
Update,
|
|
|
|
|
|
|
|
(
|
|
|
|
(
|
|
|
|
(
|
|
|
|
track_loading::<AnimationClip>,
|
|
|
|
track_loading::<AnimationClip>,
|
|
|
|
track_loading::<AudioSource>,
|
|
|
|
track_loading::<AudioSource>,
|
|
|
|
@ -20,12 +22,14 @@ impl Plugin for LoadingPlugin {
|
|
|
|
track_loading::<Shader>,
|
|
|
|
track_loading::<Shader>,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.run_if(in_state(LoadingState::Active)),
|
|
|
|
.run_if(in_state(LoadingState::Active)),
|
|
|
|
|
|
|
|
toggle_state_visibility::<LoadingState>.run_if(state_changed::<LoadingState>),
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(PostUpdate, check_progress);
|
|
|
|
.add_systems(PostUpdate, check_progress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(States, Clone, PartialEq, Eq, Hash, Debug, Default)]
|
|
|
|
#[derive(States, Clone, PartialEq, Eq, Hash, Debug, Default, Component)]
|
|
|
|
pub enum LoadingState {
|
|
|
|
pub enum LoadingState {
|
|
|
|
#[default]
|
|
|
|
#[default]
|
|
|
|
Active,
|
|
|
|
Active,
|
|
|
|
@ -36,6 +40,23 @@ pub enum LoadingState {
|
|
|
|
#[derive(Resource, Default)]
|
|
|
|
#[derive(Resource, Default)]
|
|
|
|
struct TrackLoadingProgress(Vec<bool>);
|
|
|
|
struct TrackLoadingProgress(Vec<bool>);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn spawn_loading_screen(mut commands: Commands) {
|
|
|
|
|
|
|
|
commands.spawn((
|
|
|
|
|
|
|
|
Node {
|
|
|
|
|
|
|
|
align_self: AlignSelf::Center,
|
|
|
|
|
|
|
|
justify_self: JustifySelf::Center,
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
LoadingState::Active,
|
|
|
|
|
|
|
|
children![
|
|
|
|
|
|
|
|
(
|
|
|
|
|
|
|
|
TextColor(WHITE.into()),
|
|
|
|
|
|
|
|
Text::new("Credits"),
|
|
|
|
|
|
|
|
BackgroundColor(BLACK.into())
|
|
|
|
|
|
|
|
)],
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// At the start of the update clear progress
|
|
|
|
/// At the start of the update clear progress
|
|
|
|
fn reset_progress(mut progress: ResMut<TrackLoadingProgress>) {
|
|
|
|
fn reset_progress(mut progress: ResMut<TrackLoadingProgress>) {
|
|
|
|
progress.0.clear()
|
|
|
|
progress.0.clear()
|
|
|
|
|