mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2025-01-06 02:56:41 +00:00
Add save slots for challenges
This commit is contained in:
parent
41bf965937
commit
5cf63660ef
|
@ -43,6 +43,9 @@ impl SaveSelectMenu {
|
|||
}
|
||||
|
||||
pub fn init(&mut self, state: &mut SharedGameState, ctx: &Context) -> GameResult {
|
||||
self.save_menu = Menu::new(0, 0, 200, 0);
|
||||
self.delete_confirm = Menu::new(0, 0, 75, 0);
|
||||
|
||||
for (iter, save) in self.saves.iter_mut().enumerate() {
|
||||
if let Ok(data) = filesystem::user_open(ctx, state.get_save_filename(iter + 1)) {
|
||||
let loaded_save = GameProfile::load_from_save(data)?;
|
||||
|
@ -94,14 +97,17 @@ impl SaveSelectMenu {
|
|||
CurrentMenu::SaveMenu => match self.save_menu.tick(controller, state) {
|
||||
MenuSelectionResult::Selected(0, _) => {
|
||||
state.save_slot = 1;
|
||||
state.reload_resources(ctx)?;
|
||||
state.load_or_start_game(ctx)?;
|
||||
}
|
||||
MenuSelectionResult::Selected(1, _) => {
|
||||
state.save_slot = 2;
|
||||
state.reload_resources(ctx)?;
|
||||
state.load_or_start_game(ctx)?;
|
||||
}
|
||||
MenuSelectionResult::Selected(2, _) => {
|
||||
state.save_slot = 3;
|
||||
state.reload_resources(ctx)?;
|
||||
state.load_or_start_game(ctx)?;
|
||||
}
|
||||
MenuSelectionResult::Selected(3, _) | MenuSelectionResult::Canceled => exit_action(),
|
||||
|
|
|
@ -163,4 +163,12 @@ impl ModList {
|
|||
|
||||
Ok(ModList { mods })
|
||||
}
|
||||
|
||||
pub fn get_save_from_path(&self, mod_path: String) -> i32 {
|
||||
if let Some(mod_sel) = self.mods.iter().find(|x| x.path == mod_path) {
|
||||
mod_sel.save_slot
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,6 +193,8 @@ impl Scene for TitleScene {
|
|||
match self.current_menu {
|
||||
CurrentMenu::MainMenu => match self.main_menu.tick(&mut self.controller, state) {
|
||||
MenuSelectionResult::Selected(0, _) => {
|
||||
state.mod_path = None;
|
||||
self.save_select_menu.init(state, ctx)?;
|
||||
self.current_menu = CurrentMenu::SaveSelectMenu;
|
||||
}
|
||||
MenuSelectionResult::Selected(1, _) => {
|
||||
|
@ -261,10 +263,14 @@ impl Scene for TitleScene {
|
|||
if last_idx == idx {
|
||||
self.current_menu = CurrentMenu::MainMenu;
|
||||
} else if let Some(mod_info) = state.mod_list.mods.get(idx) {
|
||||
state.save_slot = 4;
|
||||
state.mod_path = Some(mod_info.path.clone());
|
||||
state.reload_resources(ctx)?;
|
||||
state.start_new_game(ctx)?;
|
||||
if mod_info.save_slot >= 0 {
|
||||
self.save_select_menu.init(state, ctx)?;
|
||||
self.current_menu = CurrentMenu::SaveSelectMenu;
|
||||
} else {
|
||||
state.reload_resources(ctx)?;
|
||||
state.start_new_game(ctx)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
MenuSelectionResult::Canceled => {
|
||||
|
|
|
@ -554,13 +554,20 @@ impl SharedGameState {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_save_filename(&self, slot: usize) -> String {
|
||||
pub fn get_save_filename(&mut self, slot: usize) -> String {
|
||||
if let Some(mod_path) = &self.mod_path {
|
||||
format!("/Profile{}.dat", mod_path.replace("/", "")) // Until we have mod names
|
||||
} else if slot == 1 {
|
||||
"/Profile.dat".to_owned()
|
||||
let save_slot = self.mod_list.get_save_from_path(mod_path.to_string());
|
||||
if save_slot < 0 {
|
||||
return "/ModSaveDump.dat".to_owned();
|
||||
} else if save_slot > 0 {
|
||||
return format!("/Mod{}_Profile{}.dat", save_slot, slot);
|
||||
}
|
||||
}
|
||||
|
||||
if slot == 1 {
|
||||
return "/Profile.dat".to_owned();
|
||||
} else {
|
||||
format!("/Profile{}.dat", slot)
|
||||
return format!("/Profile{}.dat", slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue