moved group prompt constructor

This commit is contained in:
2026-03-01 18:32:03 +01:00
parent 2a97995469
commit 8d8270ebb0

View File

@@ -7,11 +7,7 @@ use crate::fomod::{
#[derive(Debug)] #[derive(Debug)]
pub struct InstallerState { pub struct InstallerState {
/// Flags set by plugin selections throughout the install
flags: HashMap<String, String>, flags: HashMap<String, String>,
/// Files to install, keyed by destination path.
/// Higher priority value wins when destinations conflict.
selected_files: Vec<FileTypeEnum>, selected_files: Vec<FileTypeEnum>,
} }
@@ -99,24 +95,8 @@ pub struct GroupPrompt {
pub options: Vec<InstallOption>, pub options: Vec<InstallOption>,
} }
pub struct InstallOption { impl GroupPrompt {
pub name: String, fn new(group: &Group, state: &InstallerState, installed_plugins: &[String]) -> Self {
pub option_type: PluginTypeEnum,
pub idx: usize,
pub description: String,
}
impl Display for InstallOption {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} ({:?})", self.name, self.option_type)
}
}
fn create_group_prompt(
group: &Group,
state: &InstallerState,
installed_plugins: &[String],
) -> GroupPrompt {
let options = group let options = group
.plugins .plugins
.plugin .plugin
@@ -130,12 +110,26 @@ fn create_group_prompt(
}) })
.collect(); .collect();
GroupPrompt { Self {
name: group.name.clone(), name: group.name.clone(),
select_type: group.typ, select_type: group.typ,
options, options,
} }
} }
}
pub struct InstallOption {
pub name: String,
pub option_type: PluginTypeEnum,
pub idx: usize,
pub description: String,
}
impl Display for InstallOption {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} ({:?})", self.name, self.option_type)
}
}
/// Each plugin in the install steps have a type. e.g.: Optional, Required, Recommended /// Each plugin in the install steps have a type. e.g.: Optional, Required, Recommended
/// But the type depends on dependencies /// But the type depends on dependencies
@@ -207,7 +201,7 @@ impl FomodInstaller {
for group in &step.optional_file_groups.group { for group in &step.optional_file_groups.group {
// TODO: Skip groups where all plugins are NotUsable // TODO: Skip groups where all plugins are NotUsable
let prompt = create_group_prompt(group, &state, &self.installed_plugins); let prompt = GroupPrompt::new(group, &state, &self.installed_plugins);
let selected_plugins = (self.group_prompt)(prompt); let selected_plugins = (self.group_prompt)(prompt);