mirror of
https://github.com/132nd-vWing/tacview-splitter.git
synced 2026-08-26 06:38:36 +02:00
fix coalition assigning
This commit is contained in:
@@ -24,6 +24,10 @@ fn main_inner() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
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)?;
|
||||
|
||||
+6
-4
@@ -78,7 +78,9 @@ impl Line {
|
||||
) -> Result<Self, ProcessingError> {
|
||||
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<Coalition> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-1
@@ -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<Coalition> {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,6 +12,7 @@ pub fn create_writer(
|
||||
coalition: &Coalition,
|
||||
) -> Result<Box<dyn Write>, Box<dyn ErrTrait>> {
|
||||
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<File, Error> {
|
||||
}
|
||||
|
||||
fn create_zipwriter(outer_name: &str, inner_name: &str) -> Result<ZipWriter<File>, Error> {
|
||||
println!("{outer_name} {inner_name}");
|
||||
let mut writer = ZipWriter::new(create_textwriter(outer_name)?);
|
||||
writer.start_file(
|
||||
inner_name,
|
||||
|
||||
Reference in New Issue
Block a user