Struct bevy_yarnspinner::prelude::DialogueRunner
source · pub struct DialogueRunner { /* private fields */ }
Expand description
The main type to interact with the dialogue system.
Created by calling either YarnProject::create_dialogue_runner
or YarnProject::build_dialogue_runner
.
Implementations§
source§impl DialogueRunner
impl DialogueRunner
sourcepub fn continue_in_next_update(&mut self) -> &mut Self
pub fn continue_in_next_update(&mut self) -> &mut Self
Tells the dialogue runner to try to advance the dialogue in the next update. This method must be called by the dialogue view when the user clicks on a button to show the next line.
Note that the actual advancement of the dialogue will be postponed until the following conditions are met:
- The text provider has finished loading its lines, indicated by
TextProvider::are_lines_available
returningtrue
. - The asset providers have finished loading their assets, indicated by all
AssetProvider::update_asset_availability
calls returningtrue
. - All previously called
YarnCommand
s are finished, indicated by their return type’sTaskFinishedIndicator::is_finished
returningtrue
.
sourcepub fn will_continue_in_next_update(&self) -> bool
pub fn will_continue_in_next_update(&self) -> bool
Returns whether the dialogue runner will try to advance the dialogue in the next update.
This can return true
multiple updates in a row if the conditions mentioned in DialogueRunner::continue_in_next_update
are not yet met.
sourcepub fn select_option(&mut self, option: OptionId) -> Result<&mut Self>
pub fn select_option(&mut self, option: OptionId) -> Result<&mut Self>
If the dialogue is currently waiting for the user to select an option, this method will select the option with the given id.
Implies DialogueRunner::continue_in_next_update
.
sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns whether the dialogue runner is currently running. Returns false
if:
- The dialogue has not yet been started via
DialogueRunner::start_node
- The dialogue has been stopped via
DialogueRunner::stop
- The dialogue has finished running through all nodes
sourcepub fn is_waiting_for_option_selection(&self) -> bool
pub fn is_waiting_for_option_selection(&self) -> bool
Returns whether the dialogue runner is currently waiting for the user to select an option.
If this is true, DialogueRunner::select_option
must be called before the dialogue can continue.
Calling DialogueRunner::continue_in_next_update
will panic in this case.
sourcepub fn run_selected_options_as_lines(
&mut self,
run_selected_options_as_lines: bool
) -> &mut Self
pub fn run_selected_options_as_lines( &mut self, run_selected_options_as_lines: bool ) -> &mut Self
If set, every line the user selects will emit a PresentLineEvent
. Defaults to false
.
sourcepub fn runs_selected_options_as_lines(&self) -> bool
pub fn runs_selected_options_as_lines(&self) -> bool
If set, every line the user selects will emit a PresentLineEvent
. Defaults to false
.
sourcepub fn stop(&mut self) -> &mut Self
pub fn stop(&mut self) -> &mut Self
Stops the execution of the dialogue. Any pending dialogue events will still be sent in the next update, including a DialogueCompleteEvent
.
After this, DialogueRunner::start_node
must be called before the dialogue can be advanced again.
sourcepub fn start_node(&mut self, node_name: impl AsRef<str>) -> &mut Self
pub fn start_node(&mut self, node_name: impl AsRef<str>) -> &mut Self
Starts the dialogue at the given node.
This method must be called after creation or after calling DialogueRunner::stop
before the dialogue can be advanced. Implies DialogueRunner::continue_in_next_update
.
If the dialogue was already running, this method will panic.
See DialogueRunner::try_start_node
for a fallible version of this method.
sourcepub fn try_start_node(
&mut self,
node_name: impl AsRef<str>
) -> Result<&mut Self>
pub fn try_start_node( &mut self, node_name: impl AsRef<str> ) -> Result<&mut Self>
Fallible version of DialogueRunner::start_node
.
Returns the tags for the node node_name
.
The tags for a node are defined by setting the tags
header in
the node’s source code. This header must be a space-separated list
Returns None
if the node is not present in the program.
sourcepub fn node_exists(&self, node_name: &str) -> bool
pub fn node_exists(&self, node_name: &str) -> bool
Gets a value indicating whether a specified node exists in the Yarn files.
sourcepub fn current_node(&self) -> Option<String>
pub fn current_node(&self) -> Option<String>
Gets the name of the node that this Dialogue is currently executing.
This is None
if DialogueRunner::is_running
is false
.
sourcepub fn variable_storage(&self) -> &dyn VariableStorage
pub fn variable_storage(&self) -> &dyn VariableStorage
Returns a shallow clone of the registered VariableStorage
. The storage used can be overridden by calling DialogueRunnerBuilder::with_variable_storage
.
sourcepub fn variable_storage_mut(&mut self) -> &mut dyn VariableStorage
pub fn variable_storage_mut(&mut self) -> &mut dyn VariableStorage
Returns a shallow mutable clone of the registered VariableStorage
. The storage used can be overridden by calling DialogueRunnerBuilder::with_variable_storage
.
sourcepub fn update_line_availability(
&mut self,
loaded_untyped_assets: &Assets<LoadedUntypedAsset>
) -> bool
pub fn update_line_availability( &mut self, loaded_untyped_assets: &Assets<LoadedUntypedAsset> ) -> bool
Returns whether both the text and asset providers have loaded all their lines.
sourcepub fn set_language(&mut self, language: impl Into<Language>) -> &mut Self
pub fn set_language(&mut self, language: impl Into<Language>) -> &mut Self
Sets the language of both the text and asset providers. Same as calling DialogueRunner::set_text_language
and DialogueRunner::set_asset_language
.
sourcepub fn set_text_language(&mut self, language: impl Into<Language>) -> &mut Self
pub fn set_text_language(&mut self, language: impl Into<Language>) -> &mut Self
Sets the language of the text provider.
sourcepub fn set_asset_language(&mut self, language: impl Into<Language>) -> &mut Self
pub fn set_asset_language(&mut self, language: impl Into<Language>) -> &mut Self
Sets the language of all asset providers. If no asset providers where added via DialogueRunnerBuilder::add_asset_provider
, this will do nothing.
sourcepub fn library(&self) -> &Library
pub fn library(&self) -> &Library
Returns the library of functions that can be called from Yarn files.
sourcepub fn library_mut(&mut self) -> &mut Library
pub fn library_mut(&mut self) -> &mut Library
Mutably returns the library of functions that can be called from Yarn files.
sourcepub fn commands(&self) -> &YarnCommands
pub fn commands(&self) -> &YarnCommands
Returns the command registrations that can be called from Yarn files.
sourcepub fn commands_mut(&mut self) -> &mut YarnCommands
pub fn commands_mut(&mut self) -> &mut YarnCommands
Mutably returns the command registrations that can be called from Yarn files.
sourcepub fn text_language(&self) -> Option<Language>
pub fn text_language(&self) -> Option<Language>
Returns the language used by the TextProvider
. If there are no Localizations
available, this will return None
.
sourcepub fn asset_language(&self) -> Option<Language>
pub fn asset_language(&self) -> Option<Language>
Returns the language used by the AssetProvider
s. If there are no Localizations
available, this will return None
.
Panics if the asset providers have different languages.
sourcepub fn inner(&self) -> InnerDialogue<'_>
pub fn inner(&self) -> InnerDialogue<'_>
Returns a struct that can be used to access a portion of the underlying [Dialogue
]. This is advanced functionality.
sourcepub fn inner_mut(&mut self) -> InnerDialogueMut<'_>
pub fn inner_mut(&mut self) -> InnerDialogueMut<'_>
Mutably returns a struct that can be used to access a portion of the underlying [Dialogue
]. This is advanced functionality.
sourcepub fn text_provider(&self) -> &dyn TextProvider
pub fn text_provider(&self) -> &dyn TextProvider
Returns the registered TextProvider
. By default, this is a StringsFileTextProvider
.
sourcepub fn asset_provider<T: 'static>(&self) -> Option<&T>
pub fn asset_provider<T: 'static>(&self) -> Option<&T>
Returns the registered AssetProvider
of the given type if it was previously registered with DialogueRunnerBuilder::add_asset_provider
.
sourcepub fn asset_providers(&self) -> impl Iterator<Item = &dyn AssetProvider>
pub fn asset_providers(&self) -> impl Iterator<Item = &dyn AssetProvider>
Iterates over all registered AssetProvider
s.
Trait Implementations§
source§impl Component for DialogueRunner
impl Component for DialogueRunner
Auto Trait Implementations§
impl !RefUnwindSafe for DialogueRunner
impl Send for DialogueRunner
impl Sync for DialogueRunner
impl Unpin for DialogueRunner
impl !UnwindSafe for DialogueRunner
Blanket Implementations§
§impl<T> AnyExt for T
impl<T> AnyExt for T
§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T
behind reference§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T
behind mutable reference§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T
behind Rc
pointer§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T
behind Arc
pointer§fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
T
behind Box
pointer§fn downcast_move<T>(this: Self) -> Option<T>
fn downcast_move<T>(this: Self) -> Option<T>
Self
to T
,
useful only in generic context as a workaround for specializationsource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId) )
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.