feat: Add savegame deletion (#37)
This commit is contained in:
@@ -12,5 +12,6 @@ pub enum ButtonType {
|
||||
NewGame,
|
||||
Settings,
|
||||
PopupSavegameLoad { savegame_path: SavegamePath },
|
||||
PopupSavegameDelete { savegame_path: SavegamePath },
|
||||
PopupClose,
|
||||
}
|
||||
|
||||
@@ -172,14 +172,19 @@ 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![(
|
||||
children![
|
||||
(
|
||||
Node {
|
||||
width: percent(100),
|
||||
height: percent(100),
|
||||
flex_direction: FlexDirection::Column,
|
||||
justify_content: JustifyContent::Center,
|
||||
..default()
|
||||
},
|
||||
children![
|
||||
@@ -201,7 +206,26 @@ fn spawn_load_popup(commands: &mut Commands) {
|
||||
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))
|
||||
)]
|
||||
)
|
||||
],
|
||||
));
|
||||
}
|
||||
});
|
||||
@@ -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(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user