diff --git a/src/vn.rs b/src/vn.rs index 6e7fa09..db5de5b 100644 --- a/src/vn.rs +++ b/src/vn.rs @@ -354,8 +354,8 @@ fn interactive_script(total_sections: usize) -> Markup { fn process_dialog( dialog_sequence: &DialogSequence, player_settings: &mut PlayerSettings, -) -> Vec { - let mut sections = Vec::new(); + sections: &mut Vec, +) { let mut states = initialize_change_states(&dialog_sequence.changes); for block in &dialog_sequence.blocks { @@ -373,7 +373,6 @@ fn process_dialog( } player_settings.reset(); - sections } fn initialize_change_states( @@ -412,7 +411,7 @@ pub fn render_novel( pk_path: &Path, mld_path: &Path, stream: &mut TcpStream, - choice: usize, + mut choice: usize, progress: &str, ) -> Result<(), ParsingError> { let mut settings_context = SettingsContext::new(); @@ -422,7 +421,8 @@ pub fn render_novel( player_settings.extract_settings(&mut settings_context, &mut config_map); let dialogs = parse_map(pk_path, &mut settings_context)?; - let mut sections = process_dialog(&dialogs[choice], &mut player_settings); + let mut sections = Vec::new(); + process_dialog(&dialogs[choice], &mut player_settings, &mut sections); if let Some(named_multilinear_info) = load_multilinear(mld_path) { let multilinear_info = &named_multilinear_info.info; @@ -438,32 +438,46 @@ pub fn render_novel( } let mut simulation = BorrowedMultilinearSimulation::from_data(multilinear_info, data).unwrap(); - simulation.try_call(Event(choice)); - let progress: String = simulation - .data() - .iter() - .map(|i| format!("{i}")) - .collect::>() - .join(" "); - let mut choices = Vec::new(); - for (i, dialog_sequence) in dialogs.iter().enumerate() { - if let Some(block) = dialog_sequence.blocks.first() { - if simulation.callable(Event(i)) { - choices.push(render_choice(block, i, &progress)) - } - } - } + loop { + simulation.try_call(Event(choice)); + let progress: String = simulation + .data() + .iter() + .map(|i| format!("{i}")) + .collect::>() + .join(" "); - if !choices.is_empty() { - let choices_html = html! { - div .choices-section { - @for choice in choices { - (choice) + let mut choices = Vec::new(); + for (i, dialog_sequence) in dialogs.iter().enumerate() { + if let Some(block) = dialog_sequence.blocks.first() { + if simulation.callable(Event(i)) { + choices.push((i, block)) } } - }; - sections.push(choices_html); + } + + if choices.len() == 1 { + let next_choice = choices[0].0; + if next_choice != choice { + choice = next_choice; + process_dialog(&dialogs[choice], &mut player_settings, &mut sections); + continue; + } + } + + if !choices.is_empty() { + let choices_html = html! { + div .choices-section { + @for choice in choices { + (render_choice(choice.1, choice.0, &progress)) + } + } + }; + sections.push(choices_html); + } + + break; } }