-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from 17cupsofcoffee/tui-example
- Loading branch information
Showing
16 changed files
with
810 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[package] | ||
name = "yarnspinner_without_bevy_examples" | ||
version = "0.1.0" | ||
edition = "2021" | ||
repository = "https://github.com/YarnSpinnerTool/YarnSpinner-Rust" | ||
homepage = "https://docs.yarnspinner.dev/" | ||
keywords = ["gamedev", "dialog", "yarn", "bevy"] | ||
categories = ["game-development", "compilers"] | ||
authors = ["Joe Clay <[email protected]>"] | ||
publish = false | ||
|
||
[dependencies] | ||
crossterm = "0.27" | ||
ratatui = "0.26" | ||
anyhow = "1.0" | ||
yarnspinner = { path = "../../crates/yarnspinner", version = "0.2" } | ||
|
||
[[bin]] | ||
name = "access_variables" | ||
doc = false | ||
|
||
[[bin]] | ||
name = "custom_command" | ||
doc = false | ||
|
||
[[bin]] | ||
name = "custom_function" | ||
doc = false | ||
|
||
[[bin]] | ||
name = "hello_world" | ||
doc = false |
6 changes: 6 additions & 0 deletions
6
examples/yarnspinner_without_bevy/assets/dialogue/access_variables.yarn
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
title: AccessVariables | ||
--- | ||
Setting $foo to 1 after you continue this line | ||
<<set $foo to 1>> | ||
$foo is now {$foo}. This information should also be printed in your console once the UI exits. | ||
=== |
8 changes: 8 additions & 0 deletions
8
examples/yarnspinner_without_bevy/assets/dialogue/custom_command.yarn
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
title: CustomCommand | ||
--- | ||
When a command is encountered, a 'Command' DialogueEvent will be triggered. | ||
You can handle this in your game code to do anything you'd like. | ||
For example, here's a command that changes the background of the terminal! | ||
<<set_background "cyan">> | ||
Ooh, pretty. | ||
=== |
6 changes: 6 additions & 0 deletions
6
examples/yarnspinner_without_bevy/assets/dialogue/custom_function.yarn
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
title: CustomFunction | ||
--- | ||
Rust functions can be registered into your dialogue's library to make them runnable via Yarn. | ||
Let's take a look at a custom function now! | ||
pow(2,3) = {pow(2,3)} | ||
=== |
34 changes: 34 additions & 0 deletions
34
examples/yarnspinner_without_bevy/assets/dialogue/hello_world.yarn
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
title: HelloWorld | ||
--- | ||
Hello World! To continue the dialogue, press the enter key. You can also press Q to quit. | ||
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. | ||
=== |
24 changes: 24 additions & 0 deletions
24
examples/yarnspinner_without_bevy/src/bin/access_variables.rs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use yarnspinner::core::YarnValue; | ||
use yarnspinner_without_bevy_examples::TuiDialogueRunner; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
// See lib.rs for more details on how this works! | ||
let mut runner = | ||
TuiDialogueRunner::new("./assets/dialogue/access_variables.yarn", "AccessVariables")?; | ||
|
||
runner.set_variable("$foo", YarnValue::Number(0.0))?; | ||
|
||
println!( | ||
"Value of $foo before dialogue: {:?}", | ||
runner.get_variable("$foo")? | ||
); | ||
|
||
runner.run()?; | ||
|
||
println!( | ||
"Value of $foo after dialogue: {:?}", | ||
runner.get_variable("$foo")? | ||
); | ||
|
||
Ok(()) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use yarnspinner_without_bevy_examples::TuiDialogueRunner; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
// See lib.rs for more details on how this works! | ||
TuiDialogueRunner::new("./assets/dialogue/custom_command.yarn", "CustomCommand")?.run() | ||
} |
16 changes: 16 additions & 0 deletions
16
examples/yarnspinner_without_bevy/src/bin/custom_function.rs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use yarnspinner_without_bevy_examples::TuiDialogueRunner; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
// See lib.rs for more details on how this works! | ||
let mut runner = | ||
TuiDialogueRunner::new("./assets/dialogue/custom_function.yarn", "CustomFunction")?; | ||
|
||
runner.add_function("pow", pow); | ||
runner.run()?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn pow(base: f32, exponent: f32) -> f32 { | ||
base.powf(exponent) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use yarnspinner_without_bevy_examples::TuiDialogueRunner; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
// See lib.rs for more details on how this works! | ||
TuiDialogueRunner::new("./assets/dialogue/hello_world.yarn", "HelloWorld")?.run() | ||
} |
Oops, something went wrong.