feat: Add savegame deletion (#37)
This commit is contained in:
@@ -12,5 +12,6 @@ pub enum ButtonType {
|
|||||||
NewGame,
|
NewGame,
|
||||||
Settings,
|
Settings,
|
||||||
PopupSavegameLoad { savegame_path: SavegamePath },
|
PopupSavegameLoad { savegame_path: SavegamePath },
|
||||||
|
PopupSavegameDelete { savegame_path: SavegamePath },
|
||||||
PopupClose,
|
PopupClose,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,36 +172,60 @@ fn spawn_load_popup(commands: &mut Commands) {
|
|||||||
height: px(80),
|
height: px(80),
|
||||||
justify_content: JustifyContent::Center,
|
justify_content: JustifyContent::Center,
|
||||||
align_items: AlignItems::Center,
|
align_items: AlignItems::Center,
|
||||||
|
flex_direction: FlexDirection::Row,
|
||||||
|
column_gap: px(10.0),
|
||||||
|
padding: UiRect::horizontal(px(10.0)),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
BackgroundColor(NORMAL_BUTTON),
|
BackgroundColor(NORMAL_BUTTON),
|
||||||
children![(
|
children![
|
||||||
Node {
|
(
|
||||||
width: percent(100),
|
Node {
|
||||||
height: percent(100),
|
width: percent(100),
|
||||||
flex_direction: FlexDirection::Column,
|
height: percent(100),
|
||||||
..default()
|
flex_direction: FlexDirection::Column,
|
||||||
},
|
justify_content: JustifyContent::Center,
|
||||||
children![
|
..default()
|
||||||
(
|
},
|
||||||
Text::new(format!(
|
children![
|
||||||
"Spielstand {}",
|
(
|
||||||
savegame.index + 1
|
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),
|
TextFont::from_font_size(24.0),
|
||||||
TextColor(Color::srgb(0.9, 0.9, 0.9))
|
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);
|
next_state.set(AppState::GameScreen);
|
||||||
savegame_messages.write(SavegameLoadMessage);
|
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