feat: Add savegame deletion (#37)

This commit is contained in:
demenik
2025-11-27 13:56:30 +01:00
parent 13fd30b21c
commit 62bb029084
2 changed files with 62 additions and 25 deletions

View File

@@ -12,5 +12,6 @@ pub enum ButtonType {
NewGame,
Settings,
PopupSavegameLoad { savegame_path: SavegamePath },
PopupSavegameDelete { savegame_path: SavegamePath },
PopupClose,
}

View File

@@ -172,36 +172,60 @@ fn spawn_load_popup(commands: &mut Commands) {
height: px(80),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Row,
column_gap: px(10.0),
padding: UiRect::horizontal(px(10.0)),
..default()
},
BackgroundColor(NORMAL_BUTTON),
children![(
Node {
width: percent(100),
height: percent(100),
flex_direction: FlexDirection::Column,
..default()
},
children![
(
Text::new(format!(
"Spielstand {}",
savegame.index + 1
)),
children![
(
Node {
width: percent(100),
height: percent(100),
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::Center,
..default()
},
children![
(
Text::new(format!(
"Spielstand {}",
savegame.index + 1
)),
TextFont::from_font_size(24.0),
TextColor(Color::srgb(0.9, 0.9, 0.9))
),
(
Text::new(format!(
"Beeren: {}, Fokusphasen abgeschlossen: {}",
savegame.total_berries,
savegame.completed_focus
)),
TextFont::from_font_size(18.0),
TextColor(Color::srgb(0.9, 0.9, 0.9))
)
]
),
(
Button,
ButtonType::PopupSavegameDelete {
savegame_path: savegame.path.clone()
},
Node {
width: px(40.0),
height: px(40.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
children![(
Text::new("X"),
TextFont::from_font_size(24.0),
TextColor(Color::srgb(0.9, 0.9, 0.9))
),
(
Text::new(format!(
"Beeren: {}, Fokusphasen abgeschlossen: {}",
savegame.total_berries,
savegame.completed_focus
)),
TextFont::from_font_size(18.0),
TextColor(Color::srgb(0.9, 0.9, 0.9))
)
]
)],
)]
)
],
));
}
});
@@ -245,6 +269,18 @@ fn menu(
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(),
_ => {}
}
}
}
_ => (),
};
}