feat(content): add datapack discovery and world installs
This commit is contained in:
1 parent
a98426e22a
commit
7986bab3a7
27 files changed
+1138
-119
No files matched your search
@@ -65,7 +65,12 @@ impl UiHarness {
|
||||
shaders_discovery_state: widgets::content::DiscoveryState::new(
|
||||
crate::instance::ContentKind::Shader,
|
||||
),
|
||||
datapacks_discovery_state: widgets::content::DiscoveryState::new(
|
||||
crate::instance::ContentKind::DataPack,
|
||||
),
|
||||
worlds_state: widgets::content::ContentListState::default(),
|
||||
world_datapacks_state: widgets::content::ContentListState::default(),
|
||||
open_world_datapacks: None,
|
||||
world_quick_play_support: None,
|
||||
screenshots_state: {
|
||||
let mut state = widgets::screenshots_grid::ScreenshotsState::default();
|
||||
|
||||
@@ -192,11 +192,79 @@ fn version_popup_switches_to_the_other_provider() {
|
||||
.push(project_entry(project("sodium"), None));
|
||||
state.list.list_state.selected = Some(0);
|
||||
let first = state.begin_versions().unwrap();
|
||||
assert_eq!(first.provider, "modrinth");
|
||||
state.version_popup.as_mut().unwrap().loading = false;
|
||||
let second = state.switch_version_source().unwrap();
|
||||
assert_eq!(second.provider, "curseforge");
|
||||
assert_eq!(state.version_popup.as_ref().unwrap().provider, "curseforge");
|
||||
assert_ne!(second.provider, first.provider);
|
||||
assert_eq!(
|
||||
state.version_popup.as_ref().unwrap().provider,
|
||||
second.provider
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn datapack_versions_select_a_world_before_dependency_resolution() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let minecraft = temp.path().join("minecraft");
|
||||
let world_path = minecraft.join("saves/world-folder");
|
||||
std::fs::create_dir_all(world_path.join("datapacks")).unwrap();
|
||||
let installed = world_path.join("datapacks/project.zip");
|
||||
std::fs::write(&installed, b"zip").unwrap();
|
||||
|
||||
let mut state = DiscoveryState::new(ContentKind::DataPack);
|
||||
state
|
||||
.list
|
||||
.entries
|
||||
.push(project_entry(project("project"), Some(installed.clone())));
|
||||
state.list.list_state.selected = Some(0);
|
||||
let request = state.begin_versions().unwrap();
|
||||
let mut datapack_version = version("1.0.0");
|
||||
datapack_version.loaders = vec!["datapack".to_owned()];
|
||||
DiscoveryState::push_action_result(
|
||||
&request.pending,
|
||||
DiscoveryActionResult::Versions {
|
||||
request_id: request.request_id,
|
||||
project_id: request.project_id,
|
||||
result: Ok(vec![datapack_version]),
|
||||
},
|
||||
);
|
||||
state.drain_pending();
|
||||
|
||||
let world = crate::instance::scan_one_world(&world_path, "world-folder", true);
|
||||
assert!(state.begin_world_selection(vec![world]));
|
||||
let mut manifest = crate::instance::ContentManifest::default();
|
||||
manifest.upsert(crate::instance::ContentFileRecord {
|
||||
relative_path: PathBuf::from("saves/world-folder/datapacks/project.zip"),
|
||||
kind: ContentKind::DataPack,
|
||||
enabled: true,
|
||||
fingerprint: crate::instance::FileFingerprint {
|
||||
size: 3,
|
||||
modified_ns: 1,
|
||||
hashes: Default::default(),
|
||||
},
|
||||
resolution: crate::instance::Resolution::Resolved {
|
||||
project: crate::instance::ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
project_id: "project".to_owned(),
|
||||
version_id: "old".to_owned(),
|
||||
},
|
||||
},
|
||||
provider_aliases: Vec::new(),
|
||||
required_dependencies: Vec::new(),
|
||||
automatic_dependency: false,
|
||||
cleanup_eligible: false,
|
||||
});
|
||||
|
||||
assert!(state.select_world(Some(&manifest), &minecraft));
|
||||
let dependency = state.begin_dependency_resolution().unwrap();
|
||||
assert_eq!(dependency.root.kind, ContentKind::DataPack);
|
||||
assert_eq!(
|
||||
dependency.root.target_world.as_deref(),
|
||||
Some(world_path.as_path())
|
||||
);
|
||||
assert_eq!(
|
||||
dependency.root.installed_path.as_deref(),
|
||||
Some(installed.as_path())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -354,6 +422,8 @@ fn project_page_loads_for_the_selected_discovery_entry() {
|
||||
icon_url: None,
|
||||
categories: Vec::new(),
|
||||
additional_categories: Vec::new(),
|
||||
project_type: "mod".to_owned(),
|
||||
loaders: Vec::new(),
|
||||
}),
|
||||
},
|
||||
);
|
||||
@@ -521,6 +591,8 @@ fn dependency_resolution_opens_the_existing_confirmation() {
|
||||
title: "Project".to_owned(),
|
||||
version: root_version,
|
||||
installed_path: None,
|
||||
kind: crate::instance::ContentKind::Mod,
|
||||
destination: std::path::PathBuf::from("mods"),
|
||||
provider_aliases: Vec::new(),
|
||||
required_dependencies: Vec::new(),
|
||||
automatic_dependency: false,
|
||||
|
||||
@@ -17,7 +17,7 @@ use super::{
|
||||
ContentListState, WatcherEventHandling, available_description_width, description_text_width,
|
||||
diff_directory, diff_event_paths, ellipsize, load_provider_metadata, read_dir_stems,
|
||||
right_aligned_footer_spans, square_icon_columns, title_suffix_spans, watcher_event_handling,
|
||||
world_game_mode_color,
|
||||
world_descriptions, world_game_mode_color,
|
||||
};
|
||||
|
||||
fn entry(name: &str) -> ContentEntry {
|
||||
@@ -40,6 +40,22 @@ fn entry(name: &str) -> ContentEntry {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn world_cards_preview_up_to_three_datapacks() {
|
||||
let lines = world_descriptions(&WorldDetails {
|
||||
game_mode: None,
|
||||
last_played: None,
|
||||
minecraft_version: Some("1.21.1".to_owned()),
|
||||
size: Some("4.0 MB".to_owned()),
|
||||
datapacks: ["A", "B", "C", "D"]
|
||||
.into_iter()
|
||||
.map(str::to_owned)
|
||||
.collect(),
|
||||
});
|
||||
|
||||
assert_eq!(lines, ["1.21.1 • 4.0 MB", "• A", "• B", "• C", "+1 more"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toggling_a_selected_entry_renames_and_updates_it() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
@@ -363,9 +379,10 @@ fn provider_icons_are_requested_only_for_visible_missing_icons() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn embedded_icons_do_not_request_provider_fallbacks() {
|
||||
fn complete_local_pack_metadata_does_not_request_provider_fallbacks() {
|
||||
let mut state = ContentListState::default();
|
||||
let mut visible = entry("Visible");
|
||||
visible.description = "Local description".to_owned();
|
||||
visible.icon_bytes = Some(vec![1, 2, 3]);
|
||||
visible.icon_lines = Some(crate::instance::content::fallback_icon());
|
||||
visible.provider_project = Some(crate::instance::ProviderProject {
|
||||
@@ -457,6 +474,7 @@ fn multiline_rendering_uses_the_space_beside_large_icons() {
|
||||
last_played: None,
|
||||
minecraft_version: Some("1.21.1".to_owned()),
|
||||
size: Some("2.0 MB".to_owned()),
|
||||
datapacks: Vec::new(),
|
||||
});
|
||||
world.icon_lines = Some(crate::instance::content::fallback_icon_large());
|
||||
let mut state = ContentListState::default();
|
||||
@@ -647,6 +665,8 @@ async fn provider_metadata_loads_from_cache_without_network() {
|
||||
icon_url: None,
|
||||
categories: Vec::new(),
|
||||
additional_categories: Vec::new(),
|
||||
project_type: "mod".to_owned(),
|
||||
loaders: Vec::new(),
|
||||
})
|
||||
.unwrap(),
|
||||
)
|
||||
|
||||
@@ -9,14 +9,18 @@ fn mode_labels_have_the_same_rendered_width() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_navigation_only_cycles_downloadable_tabs() {
|
||||
fn discovery_navigation_includes_datapacks() {
|
||||
assert_eq!(
|
||||
ContentTab::Shaders.next_for_mode(ContentMode::Discover),
|
||||
ContentTab::DataPacks
|
||||
);
|
||||
assert_eq!(
|
||||
ContentTab::DataPacks.next_for_mode(ContentMode::Discover),
|
||||
ContentTab::Mods
|
||||
);
|
||||
assert_eq!(
|
||||
ContentTab::Mods.previous_for_mode(ContentMode::Discover),
|
||||
ContentTab::Shaders
|
||||
ContentTab::DataPacks
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,8 +52,11 @@ fn discovery_version_rows_only_show_the_version_number() {
|
||||
|
||||
#[test]
|
||||
fn discovery_confirmation_popup_fits_its_summary() {
|
||||
assert_eq!(version_popup_height(false, None), VERSION_POPUP_HEIGHT);
|
||||
assert_eq!(version_popup_height(true, None), 6);
|
||||
assert_eq!(
|
||||
version_popup_height(false, None, false),
|
||||
VERSION_POPUP_HEIGHT
|
||||
);
|
||||
assert_eq!(version_popup_height(true, None, false), 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user