49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
//bevy system signatures often violate these rules
|
|
#![allow(clippy::type_complexity)]
|
|
#![allow(clippy::too_many_arguments)]
|
|
|
|
use bevy::prelude::*;
|
|
use state::AppState;
|
|
|
|
pub struct SetupPlugin;
|
|
|
|
impl Plugin for SetupPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_sub_state::<LoadState>()
|
|
.add_sub_state::<ExampleLoadSubState>()
|
|
.add_systems(OnEnter(LoadState::NotStarted), start_loading)
|
|
.add_systems(
|
|
Update,
|
|
finish_loading.run_if(
|
|
in_state(LoadState::Loading).and(in_state(ExampleLoadSubState::Loaded)),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, Hash, SubStates, Default)]
|
|
#[source(AppState = AppState::Setup)]
|
|
enum LoadState {
|
|
#[default]
|
|
NotStarted,
|
|
Loading,
|
|
}
|
|
|
|
fn start_loading(mut next_state: ResMut<NextState<LoadState>>) {
|
|
info!("started loading...");
|
|
next_state.set(LoadState::Loading);
|
|
}
|
|
|
|
fn finish_loading(mut next_state: ResMut<NextState<AppState>>) {
|
|
info!("finished loading");
|
|
next_state.set(AppState::Game);
|
|
}
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, Hash, SubStates, Default)]
|
|
#[source(LoadState = LoadState::Loading)]
|
|
#[allow(dead_code)]
|
|
enum ExampleLoadSubState {
|
|
Loading,
|
|
#[default]
|
|
Loaded,
|
|
}
|