diff --git a/src/game_over.rs b/src/game_over.rs index cc398bd..0bb0a7b 100644 --- a/src/game_over.rs +++ b/src/game_over.rs @@ -6,7 +6,6 @@ use crate::{ settings::DifficultySetting, stats::Stats, ui::{UiAssets, BUTTON_TEXT, TITLE_TEXT}, - util::cleanup, GameState, }; @@ -14,14 +13,10 @@ pub struct GameOverPlugin; impl Plugin for GameOverPlugin { fn build(&self, app: &mut App) { app.add_systems(OnEnter(GameState::GameOver), init); - app.add_systems(OnExit(GameState::GameOver), cleanup::); app.add_systems(Update, menu_button.run_if(in_state(GameState::GameOver))); } } -#[derive(Component)] -struct GameOverScene; - #[derive(Component)] struct MenuButton; @@ -67,7 +62,7 @@ fn init( ..default() }, NineSliceUiTexture::from_image(ui_assets.nine_panel.clone()), - GameOverScene, + StateScoped(GameState::GameOver), )) .id(); diff --git a/src/loading.rs b/src/loading.rs index b1785d6..fa11845 100644 --- a/src/loading.rs +++ b/src/loading.rs @@ -10,7 +10,6 @@ use crate::{ enemy::EnemyKind, tilemap::{AtlasHandle, TileKind}, ui::UiAssets, - util::cleanup, GameState, }; @@ -34,14 +33,10 @@ impl Plugin for LoadingPlugin { .add_systems( Update, log_pipelines.run_if(resource_changed::), - ) - .add_systems(OnExit(GameState::Loading), cleanup::); + ); } } -#[derive(Component)] -struct LoadingScene; - #[derive(Component)] pub struct LoadingImage { frames: Vec, @@ -105,7 +100,7 @@ fn init_loading_scene( ..default() }, NineSliceUiTexture::from_image(ui_assets.nine_button.clone()), - LoadingScene, + StateScoped(GameState::Loading), )) .with_children(|parent| { parent.spawn(TextBundle { diff --git a/src/main.rs b/src/main.rs index 676bf48..79596c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -154,7 +154,8 @@ fn main() { app.insert_resource(Msaa::Off) .insert_resource(ClearColor(Color::BLACK)) - .init_state::(); + .init_state::() + .enable_state_scoped_entities::(); app.run(); } diff --git a/src/main_menu.rs b/src/main_menu.rs index 8d5002d..4c767c3 100644 --- a/src/main_menu.rs +++ b/src/main_menu.rs @@ -31,16 +31,10 @@ impl Plugin for MainMenuPlugin { ) .run_if(in_state(GameState::MainMenu)), ) - .add_systems( - OnExit(GameState::MainMenu), - (crate::util::cleanup::, cleanup_background), - ); + .add_systems(OnExit(GameState::MainMenu), cleanup_background); } } -#[derive(Component)] -struct MainMenuScene; - #[derive(Resource)] struct MainMenuAssets { background: Handle, @@ -122,7 +116,7 @@ fn setup_menu( ..default() }, NineSliceUiTexture::from_image(ui_assets.nine_panel.clone()), - MainMenuScene, + StateScoped(GameState::MainMenu), )) .id();