Skip to content

Commit

Permalink
feat(components): Add component_name, sub components, and version (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
dark0dave authored Mar 10, 2024
2 parents 4da2da0 + d858426 commit 0c90aa9
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 21 deletions.
5 changes: 4 additions & 1 deletion fixtures/test.log
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
// The top of the file is the 'oldest' mod
// ~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_1/TEST.TP2~ #0 #1 // test mod two
~TEST_MOD_NAME_2/END.TP2~ #0 #0 // test mod with subcomponent information -> Standard installation
~TEST_MOD_NAME_3/END.TP2~ #0 #0 // test mod with version: 1.02
~TEST_MOD_NAME_4/TWEAKS.TP2~ #0 #3346 // test mod with both subcomponent information and version -> Casting speed only: v16
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn main() {
mods.iter()
.filter_map(|weidu_mod| {
if !installed_mods.contains(weidu_mod) {
log::debug!("Mod to be installed {:?}", weidu_mod);
Some(weidu_mod.clone())
} else {
None
Expand All @@ -51,7 +52,7 @@ fn main() {
mods
};

log::debug!(
log::info!(
"Number of mods found: {}, Number of mods to be installed: {}",
number_of_mods_found,
mods_to_be_installed.len()
Expand Down
104 changes: 85 additions & 19 deletions src/mod_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ use std::{
path::{PathBuf, MAIN_SEPARATOR},
};

#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, PartialOrd, Clone)]
pub struct ModComponent {
pub tp_file: String,
pub name: String,
pub lang: String,
pub component: String,
pub component_name: String,
pub sub_component: String,
pub version: String,
}

impl From<String> for ModComponent {
Expand All @@ -33,10 +36,12 @@ impl From<String> for ModComponent {
.unwrap_or_else(|| panic!("Could not split {} into mod into name and component", line))
.to_ascii_lowercase();

let mut lang_and_component = parts
let mut tail = parts
.next()
.unwrap_or_else(|| panic!("Could not find lang and component, from {}", line))
.split(' ');
.split("//");

let mut lang_and_component = tail.next().unwrap_or_default().split(' ');

let lang = lang_and_component
.nth(1)
Expand All @@ -48,11 +53,39 @@ impl From<String> for ModComponent {
.unwrap_or_else(|| panic!("Could not find component, from {}", line))
.replace('#', "");

let mut component_name_sub_component_version = tail.next().unwrap_or_default().split(':');

let mut component_name_sub_component = component_name_sub_component_version
.next()
.unwrap_or_default()
.split("->");

let component_name = component_name_sub_component
.next()
.unwrap_or_default()
.trim()
.to_string();

let sub_component = component_name_sub_component
.next()
.unwrap_or_default()
.trim()
.to_string();

let version = component_name_sub_component_version
.next()
.unwrap_or_default()
.trim()
.to_string();

ModComponent {
tp_file,
name,
lang,
component,
component_name,
sub_component,
version,
}
}
}
Expand Down Expand Up @@ -88,22 +121,55 @@ mod tests {
let test_log = Path::new("fixtures/test.log");
let logs = parse_weidu_log(test_log.to_path_buf());
assert_eq!(
logs.first(),
Some(&ModComponent {
tp_file: "TEST.TP2".to_string(),
name: "test_mod_name_1".to_string(),
lang: "0".to_string(),
component: "0".to_string()
})
);
assert_eq!(
logs.last(),
Some(&ModComponent {
tp_file: "TEST.TP2".to_string(),
name: "test_mod_name_2".to_string(),
lang: "0".to_string(),
component: "0".to_string()
})
logs,
vec![
ModComponent {
tp_file: "TEST.TP2".to_string(),
name: "test_mod_name_1".to_string(),
lang: "0".to_string(),
component: "0".to_string(),
component_name: "test mod one".to_string(),
sub_component: "".to_string(),
version: "".to_string()
},
ModComponent {
tp_file: "TEST.TP2".to_string(),
name: "test_mod_name_1".to_string(),
lang: "0".to_string(),
component: "1".to_string(),
component_name: "test mod two".to_string(),
sub_component: "".to_string(),
version: "".to_string()
},
ModComponent {
tp_file: "END.TP2".to_string(),
name: "test_mod_name_2".to_string(),
lang: "0".to_string(),
component: "0".to_string(),
component_name: "test mod with subcomponent information".to_string(),
sub_component: "Standard installation".to_string(),
version: "".to_string()
},
ModComponent {
tp_file: "END.TP2".to_string(),
name: "test_mod_name_3".to_string(),
lang: "0".to_string(),
component: "0".to_string(),
component_name: "test mod with version".to_string(),
sub_component: "".to_string(),
version: "1.02".to_string()
},
ModComponent {
tp_file: "TWEAKS.TP2".to_string(),
name: "test_mod_name_4".to_string(),
lang: "0".to_string(),
component: "3346".to_string(),
component_name: "test mod with both subcomponent information and version"
.to_string(),
sub_component: "Casting speed only".to_string(),
version: "v16".to_string()
}
]
);
}
}
3 changes: 3 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ mod tests {
name: "test_mod_name_1".to_string(),
lang: "0".to_string(),
component: "0".to_string(),
component_name: "".to_string(),
sub_component: "".to_string(),
version: "".to_string(),
};
let mod_folder = find_mod_folder(&mod_component, Path::new("fixtures/mods"), 3);

Expand Down

0 comments on commit 0c90aa9

Please sign in to comment.