mirror of
https://github.com/horizon-rust/horizon.git
synced 2026-11-07 11:06:11 -10:00
Select World: deleting the last world opens Create New World
WorldSelectionList.handleNewLevels opens a fresh CreateWorldScreen when the singleplayer list comes back empty, with Cancel going to the title screen. Horizon went back to an empty list instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
97437beaff
commit
f105583803
2 files changed
+37
-4
No files matched your search
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user