If there's only one choice, it will be automatically chosen

This commit is contained in:
p11 2025-04-21 22:07:20 +02:00
parent cd61068f06
commit fd3a923668

View File

@ -354,8 +354,8 @@ fn interactive_script(total_sections: usize) -> Markup {
fn process_dialog( fn process_dialog(
dialog_sequence: &DialogSequence<Change, Parameter>, dialog_sequence: &DialogSequence<Change, Parameter>,
player_settings: &mut PlayerSettings, player_settings: &mut PlayerSettings,
) -> Vec<Markup> { sections: &mut Vec<Markup>,
let mut sections = Vec::new(); ) {
let mut states = initialize_change_states(&dialog_sequence.changes); let mut states = initialize_change_states(&dialog_sequence.changes);
for block in &dialog_sequence.blocks { for block in &dialog_sequence.blocks {
@ -373,7 +373,6 @@ fn process_dialog(
} }
player_settings.reset(); player_settings.reset();
sections
} }
fn initialize_change_states( fn initialize_change_states(
@ -412,7 +411,7 @@ pub fn render_novel(
pk_path: &Path, pk_path: &Path,
mld_path: &Path, mld_path: &Path,
stream: &mut TcpStream, stream: &mut TcpStream,
choice: usize, mut choice: usize,
progress: &str, progress: &str,
) -> Result<(), ParsingError> { ) -> Result<(), ParsingError> {
let mut settings_context = SettingsContext::new(); let mut settings_context = SettingsContext::new();
@ -422,7 +421,8 @@ pub fn render_novel(
player_settings.extract_settings(&mut settings_context, &mut config_map); player_settings.extract_settings(&mut settings_context, &mut config_map);
let dialogs = parse_map(pk_path, &mut settings_context)?; 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) { if let Some(named_multilinear_info) = load_multilinear(mld_path) {
let multilinear_info = &named_multilinear_info.info; let multilinear_info = &named_multilinear_info.info;
@ -438,6 +438,8 @@ pub fn render_novel(
} }
let mut simulation = let mut simulation =
BorrowedMultilinearSimulation::from_data(multilinear_info, data).unwrap(); BorrowedMultilinearSimulation::from_data(multilinear_info, data).unwrap();
loop {
simulation.try_call(Event(choice)); simulation.try_call(Event(choice));
let progress: String = simulation let progress: String = simulation
.data() .data()
@ -450,21 +452,33 @@ pub fn render_novel(
for (i, dialog_sequence) in dialogs.iter().enumerate() { for (i, dialog_sequence) in dialogs.iter().enumerate() {
if let Some(block) = dialog_sequence.blocks.first() { if let Some(block) = dialog_sequence.blocks.first() {
if simulation.callable(Event(i)) { if simulation.callable(Event(i)) {
choices.push(render_choice(block, i, &progress)) choices.push((i, block))
} }
} }
} }
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() { if !choices.is_empty() {
let choices_html = html! { let choices_html = html! {
div .choices-section { div .choices-section {
@for choice in choices { @for choice in choices {
(choice) (render_choice(choice.1, choice.0, &progress))
} }
} }
}; };
sections.push(choices_html); sections.push(choices_html);
} }
break;
}
} }
let html = generate_html(sections); let html = generate_html(sections);