Reworked lines tabs

This commit is contained in:
p11 2025-05-30 00:20:50 +02:00
parent 3e6ba8ac02
commit ce23dcf455

View File

@ -645,6 +645,7 @@ fn handle_relative_connection(
} }
enum SectionInfo { enum SectionInfo {
Lines(Vec<String>),
Game(IndexMap<Box<str>, Box<str>>), Game(IndexMap<Box<str>, Box<str>>),
Description, Description,
Comment(Vec<Comment>), Comment(Vec<Comment>),
@ -653,7 +654,6 @@ fn handle_relative_connection(
#[derive(Default)] #[derive(Default)]
struct Section { struct Section {
title: Box<str>, title: Box<str>,
lines: Vec<String>,
info: Option<SectionInfo>, info: Option<SectionInfo>,
} }
@ -671,7 +671,6 @@ fn handle_relative_connection(
if let Some(config_map) = config_map { if let Some(config_map) = config_map {
sections.push(Section { sections.push(Section {
title: "Game".into(), title: "Game".into(),
lines: Vec::new(),
info: Some(SectionInfo::Game(config_map)), info: Some(SectionInfo::Game(config_map)),
}); });
} else { } else {
@ -679,42 +678,44 @@ fn handle_relative_connection(
unreachable!(); unreachable!();
}; };
let mut current_section = Section::default(); let mut current_title: Box<str> = "".into();
let mut current_lines = Vec::new();
for line in BufReader::new(pk_file).lines() { for line in BufReader::new(pk_file).lines() {
let Ok(line) = line else { let Ok(line) = line else {
continue; continue;
}; };
if let Some(title) = line.strip_prefix("# ") { if let Some(title) = line.strip_prefix("# ") {
if !current_section.title.is_empty() { if !current_title.is_empty() {
sections.push(current_section); sections.push(Section {
title: current_title,
info: Some(SectionInfo::Lines(current_lines)),
})
} }
current_section = Section { current_title = title.into();
title: title.into(), current_lines = vec![line];
lines: vec![line],
info: None,
};
continue; continue;
} }
current_section.lines.push(line); current_lines.push(line);
} }
sections.push(current_section); sections.push(Section {
title: current_title,
info: Some(SectionInfo::Lines(current_lines)),
})
} }
if file_paths.pki.is_some() { if file_paths.pki.is_some() {
sections.push(Section { sections.push(Section {
title: "Description".into(), title: "Description".into(),
lines: Vec::new(),
info: Some(SectionInfo::Description), info: Some(SectionInfo::Description),
}); });
} }
sections.push(Section { sections.push(Section {
title: "Comments".into(), title: "Comments".into(),
lines: Vec::new(),
info: Some(SectionInfo::Comment(comments)), info: Some(SectionInfo::Comment(comments)),
}); });
@ -798,10 +799,12 @@ fn handle_relative_connection(
} }
let _ = write!(stream, "</div>"); let _ = write!(stream, "</div>");
for (i, Section { lines, info, .. }) in sections.into_iter().enumerate() { for (i, Section { info, .. }) in sections.into_iter().enumerate() {
let index = i + 1; let index = i + 1;
let _ = write!(stream, r#"<div class="tab-content" id="content-{index}">"#); let _ = write!(stream, r#"<div class="tab-content" id="content-{index}">"#);
if !lines.is_empty() { if let Some(info) = info {
match info {
SectionInfo::Lines(lines) => {
convert_extended( convert_extended(
lines, lines,
&mut stream, &mut stream,
@ -811,8 +814,6 @@ fn handle_relative_connection(
.with_use_textboxes(true), .with_use_textboxes(true),
); );
} }
if let Some(info) = info {
match info {
SectionInfo::Game(config_map) => { SectionInfo::Game(config_map) => {
if render_novel( if render_novel(
config_map, config_map,