Skip to content

Commit

Permalink
feat(subcomponent): Add support for subcomponents
Browse files Browse the repository at this point in the history
Signed-off-by: dark0dave <dark0dave@mykolab.com>
  • Loading branch information
dark0dave committed Nov 11, 2023
1 parent fd0225b commit 29acdda
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions fixtures/test.log
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
// ~TP2_File~ #language_number #component_number // [Subcomponent Name -> ] Component Name [ : Version]
~TEST_MOD_NAME_1/TEST.TP2~ #0 #0 // test mod one
~TEST_MOD_NAME_2/TEST.TP2~ #0 #0 // test mod two
~TEST_MOD_NAME_3/TEST.TP2~ #0 #0
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ fn main() {
let number_of_mods_found = mods.len();
let mods_to_be_installed = if args.skip_installed {
let installed_mods = parse_weidu_log(installed_log_path);
mods.iter()
mods.into_iter()
.filter_map(|weidu_mod| {
if !installed_mods.contains(weidu_mod) {
Some(weidu_mod.clone())
if !installed_mods.contains(&weidu_mod) {
Some(weidu_mod)
} else {
None
}
Expand Down
26 changes: 23 additions & 3 deletions src/mod_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct ModComponent {
pub name: String,
pub lang: String,
pub component: String,
pub subcomponent: Option<String>,
}

impl From<String> for ModComponent {
Expand Down Expand Up @@ -48,11 +49,18 @@ impl From<String> for ModComponent {
.expect("Could not find component")
.replace('#', "");

lang_and_component.next();
let subcomponent = lang_and_component
.fuse()
.map(|char| char.to_string())
.reduce(|acc, e| format!("{} {}", acc, e));

ModComponent {
tp_file,
name,
lang,
component,
subcomponent,
}
}
}
Expand Down Expand Up @@ -93,16 +101,28 @@ mod tests {
tp_file: "TEST.TP2".to_string(),
name: "test_mod_name_1".to_string(),
lang: "0".to_string(),
component: "0".to_string()
component: "0".to_string(),
subcomponent: Some("test mod one".to_string())
})
);
assert_eq!(
logs.last(),
logs.get(1),
Some(&ModComponent {
tp_file: "TEST.TP2".to_string(),
name: "test_mod_name_2".to_string(),
lang: "0".to_string(),
component: "0".to_string()
component: "0".to_string(),
subcomponent: Some("test mod two".to_string())
})
);
assert_eq!(
logs.last(),
Some(&ModComponent {
tp_file: "TEST.TP2".to_string(),
name: "test_mod_name_3".to_string(),
lang: "0".to_string(),
component: "0".to_string(),
subcomponent: None
})
);
}
Expand Down
1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ mod tests {
name: "test_mod_name_1".to_string(),
lang: "0".to_string(),
component: "0".to_string(),
subcomponent: None,
};
let mod_folder = find_mod_folder(&mod_component, Path::new("fixtures/mods"), 3);

Expand Down

0 comments on commit 29acdda

Please sign in to comment.