model: add file_count_preference for multi-file selection support
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ia27c829dbcc21a7fcfc8e6f67f9e33276a6a6964
This commit is contained in:
parent
e47690a858
commit
0288be07f9
4 changed files with 19 additions and 5 deletions
|
|
@ -171,6 +171,7 @@ mod tests {
|
|||
projects: None,
|
||||
export_profiles: None,
|
||||
export_server_side_projects_to_client: None,
|
||||
file_count_preference: None,
|
||||
};
|
||||
assert!(config.export_server_side_projects_to_client.is_none());
|
||||
}
|
||||
|
|
@ -220,6 +221,7 @@ mod tests {
|
|||
projects: None,
|
||||
export_profiles: None,
|
||||
export_server_side_projects_to_client: None,
|
||||
file_count_preference: None,
|
||||
};
|
||||
|
||||
let json = serde_json::to_string_pretty(&config).unwrap();
|
||||
|
|
|
|||
|
|
@ -1232,6 +1232,7 @@ mod tests {
|
|||
projects: None,
|
||||
export_profiles: None,
|
||||
export_server_side_projects_to_client: None,
|
||||
file_count_preference: None,
|
||||
},
|
||||
profile_config,
|
||||
export_path: PathBuf::from("/tmp/export"),
|
||||
|
|
@ -1362,6 +1363,7 @@ mod tests {
|
|||
projects: None,
|
||||
export_profiles: None,
|
||||
export_server_side_projects_to_client: None,
|
||||
file_count_preference: None,
|
||||
};
|
||||
|
||||
assert_eq!(get_project_type_dir(&ProjectType::Mod, &config), "mods");
|
||||
|
|
@ -1398,6 +1400,7 @@ mod tests {
|
|||
projects: None,
|
||||
export_profiles: None,
|
||||
export_server_side_projects_to_client: None,
|
||||
file_count_preference: None,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
|
|
@ -1462,6 +1465,7 @@ mod tests {
|
|||
projects: None,
|
||||
export_profiles: None,
|
||||
export_server_side_projects_to_client: None,
|
||||
file_count_preference: None,
|
||||
};
|
||||
|
||||
let mut context = create_test_context(None);
|
||||
|
|
@ -1492,6 +1496,7 @@ mod tests {
|
|||
projects: None,
|
||||
export_profiles: None,
|
||||
export_server_side_projects_to_client: None,
|
||||
file_count_preference: None,
|
||||
};
|
||||
|
||||
let mut context = create_test_context(None);
|
||||
|
|
|
|||
|
|
@ -64,6 +64,9 @@ pub struct Config {
|
|||
rename = "exportServerSideProjectsToClient"
|
||||
)]
|
||||
pub export_server_side_projects_to_client: Option<bool>,
|
||||
/// Number of files to select per project (defaults to 1)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_count_preference: Option<usize>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
|
@ -80,6 +83,7 @@ impl Default for Config {
|
|||
projects: Some(HashMap::new()),
|
||||
export_profiles: None,
|
||||
export_server_side_projects_to_client: None,
|
||||
file_count_preference: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -145,6 +149,7 @@ impl Config {
|
|||
projects: Some(pakku.projects),
|
||||
export_profiles: None,
|
||||
export_server_side_projects_to_client: None,
|
||||
file_count_preference: None,
|
||||
})
|
||||
},
|
||||
Err(e) => Err(PakkerError::InvalidConfigFile(e.to_string())),
|
||||
|
|
@ -203,6 +208,7 @@ mod tests {
|
|||
projects: None,
|
||||
export_profiles: None,
|
||||
export_server_side_projects_to_client: None,
|
||||
file_count_preference: None,
|
||||
};
|
||||
assert_eq!(config.name, "test-pack");
|
||||
assert_eq!(config.version, "1.0.0");
|
||||
|
|
@ -224,6 +230,7 @@ mod tests {
|
|||
projects: None,
|
||||
export_profiles: None,
|
||||
export_server_side_projects_to_client: None,
|
||||
file_count_preference: None,
|
||||
};
|
||||
config.description = Some("A test modpack".to_string());
|
||||
config.author = Some("Test Author".to_string());
|
||||
|
|
|
|||
|
|
@ -246,6 +246,7 @@ impl Project {
|
|||
&mut self,
|
||||
mc_versions: &[String],
|
||||
loaders: &[String],
|
||||
file_count: Option<usize>,
|
||||
) -> crate::error::Result<()> {
|
||||
// Filter compatible files
|
||||
let compatible_files: Vec<_> = self
|
||||
|
|
@ -269,10 +270,9 @@ impl Project {
|
|||
.then_with(|| b.date_published.cmp(&a.date_published))
|
||||
});
|
||||
|
||||
// Keep only the best file
|
||||
if let Some(best_file) = sorted_files.first() {
|
||||
self.files = vec![(*best_file).clone()];
|
||||
}
|
||||
// Keep the specified number of files (default to 1 if not specified)
|
||||
let count = file_count.unwrap_or(1);
|
||||
self.files = sorted_files.into_iter().take(count).cloned().collect();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -531,7 +531,7 @@ mod tests {
|
|||
let lockfile_mc = vec!["1.20.1".to_string()];
|
||||
let lockfile_loaders = vec!["fabric".to_string()];
|
||||
|
||||
let result = project.select_file(&lockfile_mc, &lockfile_loaders);
|
||||
let result = project.select_file(&lockfile_mc, &lockfile_loaders, None);
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue