MCPcopy Index your code
hub / github.com/YarnSpinnerTool/YarnSpinner-Rust

github.com/YarnSpinnerTool/YarnSpinner-Rust @v0.8.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.8.0 ↗ · + Follow
2,013 symbols 5,783 edges 196 files 536 documented · 27%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Yarn Spinner for Rust

Crates.io Docs Discord

Note: Yarn Spinner for Rust is a work-in-progress project. We don't currently offer any official support for it. We encourage you to file issues if you have them, and to join the official Yarn Spinner Discord to discuss the project!

The Rust port of Yarn Spinner, the friendly tool for writing game dialogue. Read more on docs.yarnspinner.dev or check out the live demo, which was written using the Bevy engine. This project offers first class support for Bevy and assumes you are using it. If you are not, check out the relevant section of the book

Yarn Spinner for Rust Demo

Quickstart

Taken straight from our examples:

First, let's add our dependencies:

cargo add bevy bevy_yarnspinner bevy_yarnspinner_example_dialogue_view

Now, the main.rs:

```rust,no_run use bevy::prelude::; use bevy_yarnspinner::prelude::; use bevy_yarnspinner_example_dialogue_view::prelude::*;

fn main() { let mut app = App::new(); app.add_plugins(( DefaultPlugins, // Register the Yarn Spinner plugin using its default settings, which will look for Yarn files in the "dialogue" folder. // If this app should support Wasm or Android, we cannot load files without specifying them, so use the following instead. // YarnSpinnerPlugin::with_yarn_source(YarnFileSource::file("dialogue/hello_world.yarn")), YarnSpinnerPlugin::new(), // Initialize the bundled example UI ExampleYarnSpinnerDialogueViewPlugin::new(), )) .add_systems(Startup, setup_camera) .add_systems( Update, // Spawn the dialogue runner once the Yarn project has finished compiling spawn_dialogue_runner.run_if(resource_added::), ) .run(); }

fn setup_camera(mut commands: Commands) { commands.spawn(Camera2d::default()); }

fn spawn_dialogue_runner(mut commands: Commands, project: Res) { // Create a dialogue runner from the project. let mut dialogue_runner = project.create_dialogue_runner(&mut commands); // Immediately start showing the dialogue to the player dialogue_runner.start_node("HelloWorld"); commands.spawn(dialogue_runner); }


And finally, the `assets/dialogue/hello_world.yarn`:

```text
title: HelloWorld
---
Hello World! To continue the dialogue, click with your mouse, press the space bar or the enter key.
These are options. You can select one by clicking on it or pressing the corresponding number on your keyboard.
-> Some cool option
-> Some other cool option
Now we'll jump to another node!
<<jump AnotherNode>>

===

title: AnotherNode
---
Now, a character will talk. Notice how the upper left corner of the dialogue will show their name.
Hohenheim: Hi, I'm Jan Hohenheim, creator of Yarn Spinner for Rust. I hope you enjoy using it!
Let's set a condition. Do you prefer dogs or cats?
-> Dogs
    <<set $animal = "dog">>
-> Cats
    <<set $animal = "cats">>
-> Turtles
    I, uuuh... okay, why not.
    <<set $animal = "turtles">>
Now let's print the result of the condition. Your preference is...
(Drum roll)
<<if $animal == "dog">>
Dogs! Arf Arf!
<<elseif $animal == "cats">>
Cats! (Can't say I agree, but you do you)
<<else>>
Turtles! Solid choice.
<<endif>>
Et voilà! That was all. Thanks for checking out Yarn Spinner for Rust! Continuing from the last node will exit the dialogue.
===

Examples

To run the examples, switch to the correct dir:

# For Bevy examples:
cd examples/bevy_yarnspinner
# Or, for non-Bevy examples:
cd examples/yarnspinner_without_bevy

then list the available examples with

cargo run --bin

finally, pick something from the list, e.g.

cargo run --bin hello_world

The Bevy demo game is in demo and can be run by using

cd demo
cargo run

Version Table

Bevy Yarn Spinner for Rust Yarn Spinner
0.18 0.8 2.5.0
0.18 0.7 2.3.0
0.17 0.6 2.3.0
0.16 0.5 2.3.0
0.15 0.4 2.3.0
0.14 0.3 2.3.0
0.13 0.2 2.3.0
0.12 0.1 2.3.0

Extension points exported contracts — how you extend this code

Sealed (Interface)
Used to seal [`AllowedOptionalityChain`] so the type can be exported, but not implemented. [6 implementers]
crates/core/src/yarn_fn/optionality.rs
TaskFinishedIndicator (Interface)
Trait implemented by the return types of methods registered in the [`YarnCommands`]. [6 implementers]
crates/bevy_plugin/src/commands/command_wrapping.rs
UnwrapExt (Interface)
Contains unwrapping methods that include a link to open a github issue in the panic message [2 implementers]
crates/internal_shared/src/bug.rs
CompiledProgramAnalyser (Interface)
A trait for analysing a compiled Yarn program. Can be used by adding them to a [`Context`] with [`Context::add_analyser` [2 …
crates/runtime/src/analyser.rs
DiagnosticVec (Interface)
Trait implemented for `Vec ` to provide utility methods. [1 implementers]
crates/compiler/src/listeners/error_listener/diagnostic.rs
TestCompiler (Interface)
(no doc) [1 implementers]
crates/yarnspinner/tests/test_base/extensions.rs
SubTypeOf (Interface)
A trait for checking if a (maybe [`Option`] of) [`Type`] is a subtype of a (maybe [`Option`] of) [`Type`]. [4 implementers]
crates/core/src/types/type_util.rs
YarnCommand (Interface)
A method that can be registered as a command for Yarn files via [`YarnCommands::add_command`]. The signature of the met [2 …
crates/bevy_plugin/src/commands/command_wrapping.rs

Core symbols most depended-on inside this repo

clone
called by 280
crates/core/src/yarn_fn/function_wrapping.rs
as_ref
called by 193
crates/core/src/line_id.rs
iter
called by 103
crates/core/src/library.rs
clone
called by 93
crates/runtime/src/text_provider.rs
compile
called by 91
crates/compiler/src/compiler.rs
get_text
called by 83
crates/runtime/src/text_provider.rs
push
called by 77
crates/compiler/src/collections.rs
clone
called by 74
crates/bevy_plugin/src/commands/command_wrapping.rs

Shape

Method 1,238
Function 445
Class 213
Interface 88
Enum 29

Languages

Rust100%

Modules by API surface

crates/compiler/src/parser/generated/yarnspinnerparser.rs315 symbols
crates/compiler/src/parser/generated/yarnspinnerparservisitor.rs125 symbols
crates/compiler/src/parser/generated/yarnspinnerparserlistener.rs83 symbols
crates/runtime/src/dialogue.rs42 symbols
crates/core/src/yarn_fn/function_wrapping.rs39 symbols
crates/compiler/src/visitors/type_check_visitor.rs39 symbols
crates/bevy_plugin/src/dialogue_runner.rs39 symbols
crates/compiler/src/visitors/code_generation_visitor.rs35 symbols
crates/bevy_plugin/src/localization/strings_file/asset.rs30 symbols
crates/runtime/src/virtual_machine.rs29 symbols
crates/bevy_plugin/src/commands/command_wrapping.rs26 symbols
crates/bevy_plugin/src/commands/command_registry.rs26 symbols

For agents

$ claude mcp add YarnSpinner-Rust \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact