Also use tabs for the game

This commit is contained in:
p11 2025-05-29 23:55:03 +02:00
parent 27fa8be23e
commit 3bb1ceaf49

View File

@ -20,6 +20,7 @@ use data_stream::{
from_stream, to_stream,
};
use header_config::parse_config;
use indexmap::IndexMap;
use maud::html;
use percent_encoding::percent_decode_str;
use pukram2html::{Settings, convert, convert_extended, convert_subheader};
@ -652,35 +653,26 @@ fn handle_relative_connection(
.parent()
.map(|parent| parent.with_extension("mlc"));
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;
}
} else {
let Ok(pk_file) = File::open(file_paths.pk) else {
unreachable!();
};
#[derive(Default)]
struct Section {
title: Box<str>,
lines: Vec<String>,
config_map: Option<IndexMap<Box<str>, Box<str>>>,
}
let mut sections = Vec::new();
if config_map.is_some() {
sections.push(Section {
title: "Game".into(),
lines: Vec::new(),
config_map,
});
} else {
let Ok(pk_file) = File::open(file_paths.pk) else {
unreachable!();
};
let mut current_section = Section::default();
for line in BufReader::new(pk_file).lines() {
@ -694,6 +686,7 @@ fn handle_relative_connection(
current_section = Section {
title: title.into(),
lines: vec![line],
config_map: None,
};
continue;
@ -703,6 +696,7 @@ fn handle_relative_connection(
}
sections.push(current_section);
}
let count = sections.len();
@ -784,9 +778,16 @@ fn handle_relative_connection(
}
let _ = write!(stream, "</div>");
for (i, Section { lines, .. }) in sections.iter().enumerate() {
for (
i,
Section {
lines, config_map, ..
},
) in sections.into_iter().enumerate()
{
let index = i + 1;
let _ = write!(stream, r#"<div class="tab-content" id="content-{index}">"#);
if !lines.is_empty() {
convert_extended(
lines,
&mut stream,
@ -795,11 +796,28 @@ fn handle_relative_connection(
.with_start_level(start_level)
.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;
}
}
let _ = write!(stream, "</div>");
}
let _ = write!(stream, "</div>");
}
section(&mut stream);