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,6 +95,29 @@ pub struct GroupPrompt {
pub options: Vec<InstallOption>, pub options: Vec<InstallOption>,
} }
impl GroupPrompt {
fn new(group: &Group, state: &InstallerState, installed_plugins: &[String]) -> Self {
let options = group
.plugins
.plugin
.iter()
.enumerate()
.map(|(idx, option)| InstallOption {
name: option.name.trim().to_owned(),
option_type: resolve_plugin_type(option, state, installed_plugins),
description: option.description.trim().to_owned(),
idx,
})
.collect();
Self {
name: group.name.clone(),
select_type: group.typ,
options,
}
}
}
pub struct InstallOption { pub struct InstallOption {
pub name: String, pub name: String,
pub option_type: PluginTypeEnum, pub option_type: PluginTypeEnum,
@@ -112,31 +131,6 @@ impl Display for InstallOption {
} }
} }
fn create_group_prompt(
group: &Group,
state: &InstallerState,
installed_plugins: &[String],
) -> GroupPrompt {
let options = group
.plugins
.plugin
.iter()
.enumerate()
.map(|(idx, option)| InstallOption {
name: option.name.trim().to_owned(),
option_type: resolve_plugin_type(option, state, installed_plugins),
description: option.description.trim().to_owned(),
idx,
})
.collect();
GroupPrompt {
name: group.name.clone(),
select_type: group.typ,
options,
}
}
/// 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
/// This function eveluates the plugin type /// This function eveluates the plugin type
@@ -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);