diff --git a/src/main.rs b/src/main.rs index 45ce815..02801ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -644,6 +644,21 @@ fn handle_relative_connection( let _ = writeln!(stream, "

{title}

"); } + enum SectionInfo { + Game(IndexMap, Box>), + Description, + Comment(Vec), + } + + #[derive(Default)] + struct Section { + title: Box, + lines: Vec, + info: Option, + } + + let mut sections = Vec::new(); + let check_path: &Path = relative_path.as_ref(); let config_map = check_path .parent() @@ -653,27 +668,11 @@ fn handle_relative_connection( .parent() .map(|parent| parent.with_extension("mlc")); - enum SectionInfo { - Description, - Comment(Vec), - } - - #[derive(Default)] - struct Section { - title: Box, - lines: Vec, - config_map: Option, Box>>, - info: Option, - } - - let mut sections = Vec::new(); - - if config_map.is_some() { + if let Some(config_map) = config_map { sections.push(Section { title: "Game".into(), lines: Vec::new(), - config_map, - info: None, + info: Some(SectionInfo::Game(config_map)), }); } else { let Ok(pk_file) = File::open(file_paths.pk) else { @@ -693,7 +692,6 @@ fn handle_relative_connection( current_section = Section { title: title.into(), lines: vec![line], - config_map: None, info: None, }; @@ -710,7 +708,6 @@ fn handle_relative_connection( sections.push(Section { title: "Description".into(), lines: Vec::new(), - config_map: None, info: Some(SectionInfo::Description), }); } @@ -718,7 +715,6 @@ fn handle_relative_connection( sections.push(Section { title: "Comments".into(), lines: Vec::new(), - config_map: None, info: Some(SectionInfo::Comment(comments)), }); @@ -802,16 +798,7 @@ fn handle_relative_connection( } let _ = write!(stream, ""); - for ( - i, - Section { - lines, - config_map, - info, - .. - }, - ) in sections.into_iter().enumerate() - { + for (i, Section { lines, info, .. }) in sections.into_iter().enumerate() { let index = i + 1; let _ = write!(stream, r#"
"#); if !lines.is_empty() { @@ -824,25 +811,25 @@ fn handle_relative_connection( .with_use_textboxes(true), ); } - if let Some(config_map) = config_map { - if render_novel( - config_map, - file_paths.pk, - mlc_path.as_deref(), - file_paths.mld, - relative_path, - &mut stream, - choice, - progress, - ) - .is_err() - { - fail(stream); - return; - } - } if let Some(info) = info { match info { + SectionInfo::Game(config_map) => { + if render_novel( + config_map, + file_paths.pk, + mlc_path.as_deref(), + file_paths.mld, + relative_path, + &mut stream, + choice, + progress, + ) + .is_err() + { + fail(stream); + return; + } + } SectionInfo::Description => { let Ok(pki_file) = File::open(file_paths.pki.unwrap()) else { unreachable!();