@@ -33,18 +33,6 @@ pub(crate) struct VirtualMachine {
3333 language_code : Option < Language > ,
3434}
3535
36- /*
37- impl Iterator for VirtualMachine {
38- type Item = Vec<DialogueEvent>;
39-
40- fn next(&mut self) -> Option<Self::Item> {
41- self.assert_can_continue().is_ok().then(||
42- self.continue_()
43- .unwrap_or_else(|e| panic!("Encountered error while running dialogue through its `Iterator` implementation: {e}")))
44- }
45- }
46- */
47-
4836impl VirtualMachine {
4937 pub ( crate ) fn new (
5038 library : Library ,
@@ -112,6 +100,12 @@ impl VirtualMachine {
112100 std:: mem:: take ( & mut self . batched_events )
113101 }
114102
103+ pub fn next ( & mut self , #[ cfg( feature = "bevy" ) ] world : & mut World ) -> Option < Vec < DialogueEvent > > {
104+ self . assert_can_continue ( ) . is_ok ( ) . then ( ||
105+ self . continue_ ( #[ cfg( feature = "bevy" ) ] world)
106+ . unwrap_or_else ( |e| panic ! ( "Encountered error while running dialogue through its `Iterator` implementation: {e}" ) ) )
107+ }
108+
115109 pub ( crate ) fn set_node ( & mut self , node_name : impl Into < String > ) -> Result < ( ) > {
116110 let node_name = node_name. into ( ) ;
117111 debug ! ( "Loading node \" {node_name}\" " ) ;
@@ -654,3 +648,19 @@ fn expand_substitutions(text: &str, substitutions: &[String]) -> String {
654648 text. replace ( & format ! ( "{{{i}}}" , ) , substitution)
655649 } )
656650}
651+
652+ struct RunToCompletionIterator < ' a > {
653+ vm : & ' a mut VirtualMachine ,
654+ #[ cfg( feature = "bevy" ) ]
655+ world : & ' a mut World ,
656+ }
657+
658+ impl < ' a > Iterator for RunToCompletionIterator < ' a > {
659+ type Item = Vec < DialogueEvent > ;
660+
661+ fn next ( & mut self ) -> Option < Self :: Item > {
662+ self . vm . assert_can_continue ( ) . is_ok ( ) . then ( ||
663+ self . vm . continue_ ( #[ cfg( feature = "bevy" ) ] self . world )
664+ . unwrap_or_else ( |e| panic ! ( "Encountered error while running dialogue through its `Iterator` implementation: {e}" ) ) )
665+ }
666+ }
0 commit comments