Changed how game does tabs

This commit is contained in:
p11 2025-05-30 00:13:10 +02:00
parent 84f57449f8
commit 3e6ba8ac02

View File

@ -644,6 +644,21 @@ fn handle_relative_connection(
let _ = writeln!(stream, "<h1>{title}</h1>"); let _ = writeln!(stream, "<h1>{title}</h1>");
} }
enum SectionInfo {
Game(IndexMap<Box<str>, Box<str>>),
Description,
Comment(Vec<Comment>),
}
#[derive(Default)]
struct Section {
title: Box<str>,
lines: Vec<String>,
info: Option<SectionInfo>,
}
let mut sections = Vec::new();
let check_path: &Path = relative_path.as_ref(); let check_path: &Path = relative_path.as_ref();
let config_map = check_path let config_map = check_path
.parent() .parent()
@ -653,27 +668,11 @@ fn handle_relative_connection(
.parent() .parent()
.map(|parent| parent.with_extension("mlc")); .map(|parent| parent.with_extension("mlc"));
enum SectionInfo { if let Some(config_map) = config_map {
Description,
Comment(Vec<Comment>),
}
#[derive(Default)]
struct Section {
title: Box<str>,
lines: Vec<String>,
config_map: Option<IndexMap<Box<str>, Box<str>>>,
info: Option<SectionInfo>,
}
let mut sections = Vec::new();
if config_map.is_some() {
sections.push(Section { sections.push(Section {
title: "Game".into(), title: "Game".into(),
lines: Vec::new(), lines: Vec::new(),
config_map, info: Some(SectionInfo::Game(config_map)),
info: None,
}); });
} else { } else {
let Ok(pk_file) = File::open(file_paths.pk) else { let Ok(pk_file) = File::open(file_paths.pk) else {
@ -693,7 +692,6 @@ fn handle_relative_connection(
current_section = Section { current_section = Section {
title: title.into(), title: title.into(),
lines: vec![line], lines: vec![line],
config_map: None,
info: None, info: None,
}; };
@ -710,7 +708,6 @@ fn handle_relative_connection(
sections.push(Section { sections.push(Section {
title: "Description".into(), title: "Description".into(),
lines: Vec::new(), lines: Vec::new(),
config_map: None,
info: Some(SectionInfo::Description), info: Some(SectionInfo::Description),
}); });
} }
@ -718,7 +715,6 @@ fn handle_relative_connection(
sections.push(Section { sections.push(Section {
title: "Comments".into(), title: "Comments".into(),
lines: Vec::new(), lines: Vec::new(),
config_map: None,
info: Some(SectionInfo::Comment(comments)), info: Some(SectionInfo::Comment(comments)),
}); });
@ -802,16 +798,7 @@ fn handle_relative_connection(
} }
let _ = write!(stream, "</div>"); let _ = write!(stream, "</div>");
for ( for (i, Section { lines, info, .. }) in sections.into_iter().enumerate() {
i,
Section {
lines,
config_map,
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 !lines.is_empty() {
@ -824,7 +811,9 @@ fn handle_relative_connection(
.with_use_textboxes(true), .with_use_textboxes(true),
); );
} }
if let Some(config_map) = config_map { if let Some(info) = info {
match info {
SectionInfo::Game(config_map) => {
if render_novel( if render_novel(
config_map, config_map,
file_paths.pk, file_paths.pk,
@ -841,8 +830,6 @@ fn handle_relative_connection(
return; return;
} }
} }
if let Some(info) = info {
match info {
SectionInfo::Description => { SectionInfo::Description => {
let Ok(pki_file) = File::open(file_paths.pki.unwrap()) else { let Ok(pki_file) = File::open(file_paths.pki.unwrap()) else {
unreachable!(); unreachable!();