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