Only require one section list, no additional scene list

This commit is contained in:
p11 2025-04-21 11:14:16 +02:00
parent b519f53607
commit 169baf4c76

View File

@ -26,35 +26,34 @@ fn render_scene(settings: &PlayerSettings, name: &str) -> Markup {
}
}
fn navigation_controls(total_scenes: usize) -> Markup {
fn navigation_controls(total_sections: usize) -> Markup {
html! {
nav .nav-controls {
button .nav-button onclick="prev()" { "" }
span #section-counter { "1/" (total_scenes) }
span #section-counter { "1/" (total_sections) }
button .nav-button onclick="next()" { "" }
}
}
}
fn generate_html(scenes: Vec<Markup>, sections: Vec<Markup>) -> Markup {
let total_scenes = scenes.len();
fn generate_html(sections: Vec<Markup>) -> Markup {
let total_sections = sections.len();
html! {
div #story-container {
div .scene-viewport {
@for (index, (scene, section)) in (scenes.iter().zip(sections)).enumerate() {
@for (index, section) in sections.iter().enumerate() {
section .selection-section
data-section-index=(index)
style=(format!("display: {};", if index == 0 { "block" } else { "none" })) {
(scene)
(section)
}
}
}
(navigation_controls(total_scenes))
(navigation_controls(total_sections))
(global_styles())
(interactive_script(total_scenes))
(interactive_script(total_sections))
}
}
}
@ -248,19 +247,19 @@ fn global_styles() -> Markup {
}
}
fn interactive_script(total_scenes: usize) -> Markup {
fn interactive_script(total_sections: usize) -> Markup {
html! {
script {
(maud::PreEscaped(format!(r"
let currentScene = 0;
const totalScenes = {total_scenes};
const totalSections = {total_sections};
function updateSection() {{
document.querySelectorAll('.selection-section').forEach((el, index) => {{
el.style.display = index === currentScene ? 'block' : 'none';
}});
document.getElementById('section-counter').textContent =
`${{currentScene + 1}}/${{totalScenes}}`;
`${{currentScene + 1}}/${{totalSections}}`;
}}
function prev() {{
@ -269,7 +268,7 @@ fn interactive_script(total_scenes: usize) -> Markup {
}}
function next() {{
if (currentScene < totalScenes - 1) currentScene++;
if (currentScene < totalSections - 1) currentScene++;
updateSection();
}}
@ -333,8 +332,7 @@ pub fn render_novel(
let named_multilinear_info = named_multilinear_info.as_ref();
let dialogs = parse_map(pk_path, &mut settings_context)?;
let (mut scenes, mut sections) =
process_dialog(&dialogs[choice], &mut player_settings, start_level);
let mut sections = process_dialog(&dialogs[choice], &mut player_settings, start_level);
if let Some(_named_multilinear_info) = named_multilinear_info {
let choices_html = html! {
@ -344,11 +342,10 @@ pub fn render_novel(
}
}
};
scenes.push(choices_html);
sections.push(html!());
sections.push(choices_html);
}
let html = generate_html(scenes, sections);
let html = generate_html(sections);
let _ = write!(stream, "{}", html.into_string());
Ok(())
@ -358,8 +355,7 @@ fn process_dialog(
dialog_sequence: &dialogi::DialogSequence<Change, Parameter>,
player_settings: &mut PlayerSettings,
start_level: usize,
) -> (Vec<Markup>, Vec<Markup>) {
let mut scenes = Vec::new();
) -> Vec<Markup> {
let mut sections = Vec::new();
let mut states = initialize_change_states(&dialog_sequence.changes);
@ -372,13 +368,15 @@ fn process_dialog(
player_settings,
);
scenes.push(render_scene(player_settings, &block.name));
sections.push(render_dialog_block(block, start_level));
sections.push(html! {
(render_scene(player_settings, &block.name))
(render_dialog_block(block, start_level))
});
}
player_settings.reset();
(scenes, sections)
sections
}
fn initialize_change_states(