diff --git a/src/menu/save_select_menu.rs b/src/menu/save_select_menu.rs index a1e4fd4..9d11056 100644 --- a/src/menu/save_select_menu.rs +++ b/src/menu/save_select_menu.rs @@ -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(), diff --git a/src/mod_list.rs b/src/mod_list.rs index 019e736..50e0be3 100644 --- a/src/mod_list.rs +++ b/src/mod_list.rs @@ -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 + } + } } diff --git a/src/scene/title_scene.rs b/src/scene/title_scene.rs index 7d7f7ac..10e747f 100644 --- a/src/scene/title_scene.rs +++ b/src/scene/title_scene.rs @@ -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 => { diff --git a/src/shared_game_state.rs b/src/shared_game_state.rs index 12b3f57..cf6193d 100644 --- a/src/shared_game_state.rs +++ b/src/shared_game_state.rs @@ -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); } } }