From 631812abdf9ff04fc2730ecfb51733c226a7eb7b Mon Sep 17 00:00:00 2001 From: p11 Date: Mon, 21 Apr 2025 10:53:07 +0200 Subject: [PATCH] Moved choice rendering to separate function --- src/vn.rs | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/vn.rs b/src/vn.rs index fa1cad1..a2cafae 100644 --- a/src/vn.rs +++ b/src/vn.rs @@ -298,6 +298,30 @@ fn load_multilinear(mld_path: &Path) -> Option { parse_multilinear(file).ok() } +fn render_choice( + dialog_sequence: &dialogi::DialogSequence, + index: usize, + progress: &str, +) -> Markup { + html! { + @if let Some(block) = dialog_sequence.blocks.first() { + form method="POST" { + input type="hidden" name="progress" value=(progress); + input type="hidden" name="choice" value=(index); + + button type="submit" .choice-button { + fieldset .choice-box { + @if !block.name.is_empty() { + legend .choice-name { (block.name) } + } + (block.lines[0].text) + } + } + } + } + } +} + pub fn render_novel( mut config_map: IndexMap, Box>, pk_path: &Path, @@ -324,24 +348,10 @@ pub fn render_novel( let choices_html = html! { div .choices-section { @for (i, dialog_sequence) in dialogs.iter().enumerate() { - @if let Some(block) = dialog_sequence.blocks.first() { - form method="POST" { - input type="hidden" name="progress" value=(progress); - input type="hidden" name="choice" value=(i); - button type="submit" .choice-button { - fieldset .choice-box { - @if !block.name.is_empty() { - legend .choice-name { (block.name) } - } - (block.lines[0].text) - } - } - } - } + (render_choice(dialog_sequence, i, progress)) } } }; - scenes.push(choices_html); sections.push(html!()); }