1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//! # Bevy Yarn Spinner
//!
//! This is the Bevy integration for Yarn Spinner, the friendly dialogue creation tool for Rust.
//! It allows you to easily create dialogue systems in your game.
//!
//! ## Usage
//!
//! The three main types you will interact with are:
//! - [`YarnSpinnerPlugin`]: The plugin registering all systems and types.
//! - [`YarnProject`]: A [`Resource`](bevy::prelude::Resource) for the compiled Yarn project, which is created for you when [`YarnSpinnerPlugin`] is added.
//! - [`DialogueRunner`]: The [`Component`](bevy::prelude::Component) running through the Yarn files and sending events for things you should draw on the screen.
//! Can be created from a [`YarnProject`].
//!
//! ## Dialogue Views
//!
//! The dialogue runner itself does not draw anything to the screen, it only tells you what content to present.
//! Any plugin that handles the actual drawing is called a *dialogue view*. We provide an [example dialogue view](https://crates.io/crates/bevy_yarnspinner_example_dialogue_view)
//! that you can use to explore the features of Yarn Spinner and get started quickly.
//!
//! Specifically, a dialogue view is required to do the following things
//! - Handle the [`PresentLine`](crate::events::PresentLine) event and draw the line to the screen.
//! - Handle the [`PresentOptions`](crate::events::PresentOptions) event and draw the options to the screen.
//! - Call [`DialogueRunner::continue_in_next_update`](crate::prelude::DialogueRunner::continue_in_next_update) when the user wishes to continue the dialogue.
//! - Pass a user's option selection to the right dialogue runner via [`DialogueRunner::select_option`](crate::prelude::DialogueRunner::select_option).
//!
//! See the documentation for the [`events`] module for additional optional events that may be handled
//!
//! Note that while [`DialogueRunner`]s are setup in such a way that you can have multiple instances running in parallel (such as for split-screen co-op),
//! a general-purpose dialogue view is not required to support this use-case, as every game that does this will have it's own way of wanting to deal with this.
//! In particular, the [example dialogue view](https://crates.io/crates/bevy_yarnspinner_example_dialogue_view) only supports a single [`DialogueRunner`].
//!
//! ## Demo
//!
//! You can play a the [Yarn Spinner for Rust Demo](https://janhohenheim.itch.io/yarnspinner-rust-demo) in your browser to see the aforementioned example dialogue view in action.
//! Additionally, there are [many examples](https://github.com/YarnSpinnerTool/YarnSpinner-Rust/tree/main/examples/bevy_yarnspinner/src/bin) that you can check out.
//!
//! ## Example
//!
//! The main workflow is as follows:
//! - Register the [`YarnSpinnerPlugin`]
//! - When the [`YarnProject`] [`Resource`](bevy::prelude::Resource) is added, spawn a [`DialogueRunner`] from it.
//! The latter can nicely be done with `my_system.run_if(resource_added::<YarnProject>)`.
//!
//! The following example is adapted from the [hello world example](https://github.com/YarnSpinnerTool/YarnSpinner-Rust/blob/main/examples/bevy_yarnspinner/src/bin/hello_world.rs).
//!
//! ```text
//! # assets/dialogue/hello_world.yarn
//! title: Start
//! ---
//! Hello world!
//! ===
//! ```
//!
//! ```no_run
//! // src/main.rs
//! use bevy::prelude::*;
//! use bevy_yarnspinner::prelude::*;
//! // Use the example dialogue view to see the dialogue in action. Requires the `bevy_yarnspinner_example_dialogue_view` crate.
//! // use bevy_yarnspinner_example_dialogue_view::prelude::*;
//!
//! fn main() {
//! let mut app = App::new();
//! app.add_plugins((
//! // Add the Yarn Spinner plugin.
//! // As soon as this plugin is built, a Yarn project will be compiled
//! // from all Yarn files found under assets/dialog/*.yarn
//! YarnSpinnerPlugin::new(),
//! // Initialize the bundled example UI. Requires the `bevy_yarnspinner_example_dialogue_view` crate.
//! // ExampleYarnSpinnerDialogueViewPlugin::new(),
//! ))
//! // Setup a 2D camera so we can see the text
//! .add_systems(Startup, setup_camera)
//! // Spawn the dialog as soon as the Yarn project finished compiling
//! .add_systems(
//! Update,
//! spawn_dialogue_runner.run_if(resource_added::<YarnProject>),
//! )
//! .run();
//! }
//!
//! fn setup_camera(mut commands: Commands) {
//! commands.spawn(Camera2d::default());
//! }
//!
//! fn spawn_dialogue_runner(mut commands: Commands, project: Res<YarnProject>) {
//! let mut dialogue_runner = project.create_dialogue_runner(&mut commands);
//! // Start the dialog at the node with the title "Start"
//! dialogue_runner.start_node("Start");
//! commands.spawn(dialogue_runner);
//! }
//! ```
//!
//! [`DialogueRunner`]: crate::prelude::DialogueRunner
//! [`YarnProject`]: crate::prelude::YarnProject
//! [`YarnSpinnerPlugin`]: crate::prelude::YarnSpinnerPlugin
pub use ;
pub use crate;
pub use crate;
pub use ;
pub use ;