From cda33692cf5549d5d64dd0e68aaab66e0734f5d0 Mon Sep 17 00:00:00 2001 From: 132nd-Professor <132nd-Professor> Date: Fri, 12 Aug 2022 17:47:48 +0200 Subject: [PATCH] fix coalition assigning --- src/main.rs | 4 ++++ src/processor.rs | 10 ++++++---- src/tacview.rs | 15 ++++++++++++++- src/writer.rs | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index caf39b9..8b5fdf7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,10 @@ fn main_inner() -> Result<(), Box> { let coalition_per_line = processor::divide_body_by_coalition(body)?; + // for c in &coalition_per_line { + // println!("{c}"); + // } + let mut blue_writer = writer::create_writer(is_zip, &input_filename, &Coalition::Blue)?; blue_writer.write_strings(header)?; blue_writer.write_for_coalition(body, &coalition_per_line, Coalition::Blue)?; diff --git a/src/processor.rs b/src/processor.rs index 4b94c66..d3d457e 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -78,7 +78,9 @@ impl Line { ) -> Result { let id = Self::get_id_from_line(current_line, &line_type)?; let continued = Self::will_line_continue(current_line); - let coalition = Self::assign_id_to_coalitions(coalition_ids, current_line, id); + let coalition = Self::assign_id_to_coalitions(coalition_ids, current_line, id) + .unwrap_or(Coalition::Unknown); // happens for the authentication line at the end of + // a file that has verification enabled Ok(Line::new(line_type, continued, coalition)) } @@ -86,13 +88,13 @@ impl Line { coalition_ids: &mut CoalitionIDs<'a>, line: &S, id: &'a str, - ) -> Coalition { + ) -> Option { if Coalition::line_contains_coalition(line) { let coalition = Coalition::from_line(line); coalition_ids.insert(id, &coalition); - coalition + Some(coalition) } else { - Coalition::Unknown + coalition_ids.get(id) } } diff --git a/src/tacview.rs b/src/tacview.rs index 838e213..2441d3d 100644 --- a/src/tacview.rs +++ b/src/tacview.rs @@ -38,7 +38,8 @@ impl Display for Coalition { Self::Blue => "blue".to_string(), Self::Red => "red".to_string(), Self::Purple => "purple".to_string(), - _ => unreachable!("We never need these variants"), + Self::All => "all".to_string(), + Self::Unknown => "unknown".to_string(), } ) } @@ -64,4 +65,16 @@ impl<'a> CoalitionIDs<'a> { Coalition::All | Coalition::Unknown => false, }; } + + pub fn get(&self, id: &'a str) -> Option { + if self.blue.contains(id) { + Some(Coalition::Blue) + } else if self.red.contains(id) { + Some(Coalition::Red) + } else if self.purple.contains(id) { + Some(Coalition::Purple) + } else { + None + } + } } diff --git a/src/writer.rs b/src/writer.rs index 354503b..f531170 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -12,6 +12,7 @@ pub fn create_writer( coalition: &Coalition, ) -> Result, Box> { let base_name = remove_extension(filename, is_zip); + println!("writing {coalition}"); if is_zip { Ok(Box::new(create_zipwriter( &format!("{base_name}_{coalition}{EXTENSION_ZIP}"), @@ -35,7 +36,6 @@ fn create_textwriter(filename: &str) -> Result { } fn create_zipwriter(outer_name: &str, inner_name: &str) -> Result, Error> { - println!("{outer_name} {inner_name}"); let mut writer = ZipWriter::new(create_textwriter(outer_name)?); writer.start_file( inner_name,