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,32 +438,46 @@ pub fn render_novel(
} }
let mut simulation = let mut simulation =
BorrowedMultilinearSimulation::from_data(multilinear_info, data).unwrap(); BorrowedMultilinearSimulation::from_data(multilinear_info, data).unwrap();
simulation.try_call(Event(choice));
let progress: String = simulation
.data()
.iter()
.map(|i| format!("{i}"))
.collect::<Vec<_>>()
.join(" ");
let mut choices = Vec::new(); loop {
for (i, dialog_sequence) in dialogs.iter().enumerate() { simulation.try_call(Event(choice));
if let Some(block) = dialog_sequence.blocks.first() { let progress: String = simulation
if simulation.callable(Event(i)) { .data()
choices.push(render_choice(block, i, &progress)) .iter()
} .map(|i| format!("{i}"))
} .collect::<Vec<_>>()
} .join(" ");
if !choices.is_empty() { let mut choices = Vec::new();
let choices_html = html! { for (i, dialog_sequence) in dialogs.iter().enumerate() {
div .choices-section { if let Some(block) = dialog_sequence.blocks.first() {
@for choice in choices { if simulation.callable(Event(i)) {
(choice) 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;
} }
} }