diff --git a/crates/horizon-client/src/title.rs b/crates/horizon-client/src/title.rs index b2fcfe8f4..3d7d12288 100644 --- a/crates/horizon-client/src/title.rs +++ b/crates/horizon-client/src/title.rs @@ -298,15 +298,23 @@ impl Title { options: WorldOptions::default(), } } + /// WorldSelectionList.handleNewLevels: a singleplayer list that comes + /// back empty (the last world deleted, say) opens a fresh Create New + /// World, whose Cancel goes to the title screen. fn return_to_list(&mut self, folder: Option<&str>) { let worlds = list_worlds(&self.saves); + *self.recent.borrow_mut() = None; + if worlds.is_empty() { + self.create_return_to_main = true; + self.mode = Self::new_world(); + return; + } let selected = folder.and_then(|folder| { worlds .iter() .position(|w| w.folder == folder && self.matches_search(w)) }); self.mode = Mode::Select { worlds, selected }; - *self.recent.borrow_mut() = None; } /// Deletes the world `Mode::Delete` asks about and goes back to the /// refreshed list; a failure (the world is open elsewhere, say) shows the diff --git a/crates/horizon-client/src/title/tests.rs b/crates/horizon-client/src/title/tests.rs index 04fefe366..55fac200a 100644 --- a/crates/horizon-client/src/title/tests.rs +++ b/crates/horizon-client/src/title/tests.rs @@ -288,12 +288,37 @@ fn delete_requires_confirmation_and_both_cancel_paths_preserve_world() { assert_eq!((delete.x, delete.y, delete.w), (88.0, 146.0, 150.0)); f.click("Delete"); assert!(!f.title.saves.join("World").exists()); - assert!(matches!(&f.title.mode, Mode::Select { worlds, selected: None } if worlds.is_empty())); - f.click("Back"); + // The last world gone, vanilla opens a fresh Create New World, not an empty list. + assert!(matches!(&f.title.mode, Mode::Create { name, .. } if name == "New World")); + f.click("Cancel"); + assert!(matches!(f.title.mode, Mode::Main)); f.click("Singleplayer"); assert!(matches!(f.title.mode, Mode::Create { .. })); } +#[test] +fn deleting_one_of_two_worlds_keeps_the_list() { + let mut f = Fixture::new(); + f.world("One", "One"); + f.world("Two", "Two"); + f.select(); + f.click("Delete"); + f.click("Delete"); + assert!(matches!(&f.title.mode, Mode::Select { worlds, .. } if worlds.len() == 1)); +} + +#[test] +fn a_list_emptied_elsewhere_opens_create_world() { + let mut f = Fixture::new(); + f.world("World", "World"); + f.title.enter_singleplayer(); + world_management::delete(&f.title.saves, "World").unwrap(); + f.title.worlds_changed(); + assert!(matches!(f.title.mode, Mode::Create { .. })); + f.title.escape(); + assert!(matches!(f.title.mode, Mode::Main)); +} + #[test] fn backup_zip_preserves_nested_files_excludes_lock_and_keeps_duplicate_backups() { let f = Fixture::new(); @@ -600,7 +625,7 @@ fn world_management_buttons_sound_when_enabled() { assert_eq!(f.click_with_sound("Cancel"), (Action::None, true)); assert_eq!(f.click_with_sound("Delete"), (Action::None, true)); assert_eq!(f.click_with_sound("Delete"), (Action::None, true)); - assert!(matches!(f.title.mode, Mode::Select { .. })); + assert!(matches!(f.title.mode, Mode::Create { .. })); } #[test]