refactor: Move load savegame popup to savegame feature

This commit is contained in:
demenik
2025-11-28 12:37:57 +01:00
parent cdcb8c08d4
commit a2566f3643
6 changed files with 57 additions and 38 deletions

View File

@@ -1,9 +1,8 @@
use crate::{features::savegame::messages::SavegameLoadMessage, prelude::*};
use crate::features::savegame::ui::spawn_load_popup;
use crate::prelude::*;
use components::*;
use ui::*;
pub mod components;
pub mod ui;
pub struct StartScreenPlugin;
@@ -80,8 +79,6 @@ fn menu(
mut commands: Commands,
mut next_state: ResMut<NextState<AppState>>,
mut interaction_query: Query<(&Interaction, &ButtonType), (Changed<Interaction>, With<Button>)>,
root_query: Query<(Entity, &RootMarker)>,
mut savegame_messages: MessageWriter<SavegameLoadMessage>,
) {
for (interaction, button_type) in &mut interaction_query {
match *interaction {
@@ -94,31 +91,6 @@ fn menu(
commands.insert_resource(SavegamePath::next());
next_state.set(AppState::GameScreen);
}
ButtonType::PopupClose => {
for (entity, root) in root_query.iter() {
match *root {
RootMarker::PopupSavegameLoad => commands.entity(entity).despawn(),
_ => {}
}
}
}
ButtonType::PopupSavegameLoad { savegame_path } => {
commands.insert_resource(savegame_path.clone());
next_state.set(AppState::GameScreen);
savegame_messages.write(SavegameLoadMessage);
}
ButtonType::PopupSavegameDelete { savegame_path } => {
if let Err(e) = std::fs::remove_file(savegame_path.clone().0) {
println!("Error while deleting savegame: {:?}", e);
}
for (entity, root) in root_query.iter() {
match *root {
RootMarker::PopupSavegameLoad => commands.entity(entity).despawn(),
_ => {}
}
}
}
ButtonType::Settings => todo!(),
};
}