Created
April 27, 2024 17:15
-
-
Save stargazing-dino/e46e09ef721547668f5782c2e294cb8d to your computer and use it in GitHub Desktop.
Gets all paths of a dialogue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Untested code! | |
fn generate_all_paths( | |
dialogue: &mut Dialogue, | |
progress: &mut Progress, | |
) -> Vec<GraphWalk> { | |
let mut all_paths = Vec::new(); | |
let dialogue_events = match dialogue.continue_() { | |
Ok(events) => events, | |
Err(_) => { | |
all_paths.push(progress.clone()); | |
return all_paths; | |
} | |
}; | |
for dialogue_event in dialogue_events { | |
match dialogue_event { | |
DialogueEvent::Line(line) => { | |
progress.push_line( | |
&line, | |
dialogue.text_provider(), | |
dialogue.current_node().unwrap().as_str(), | |
); | |
} | |
DialogueEvent::DialogueComplete => { | |
all_paths.push(progress.clone()); | |
} | |
DialogueEvent::Options(options) => { | |
for (index, option) in options.iter().enumerate() { | |
let mut dialogue_clone = dialogue.clone(); // <- Does not implement Clone | |
let mut progress_clone = progress.clone(); | |
progress_clone.push_option( | |
index, | |
option, | |
dialogue_clone.text_provider(), | |
dialogue_clone.current_node().unwrap().as_str(), | |
); | |
dialogue_clone.set_selected_option(option.id).unwrap(); | |
let sub_paths = generate_all_paths( | |
&mut dialogue_clone, | |
progress_clone, | |
); | |
all_paths.extend(sub_paths); | |
} | |
} | |
_ => {} | |
} | |
} | |
all_paths | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment