Bevy Talks
[!WARNING]
Be aware thatbevy_talks
's API is still undergoing revisions (with possibly big architectural changes). Feedback on its ergonomics and developer experience (DX) is highly appreciated.
This Bevy plugin provides a way to create dialogues and conversations in your game as graphs.
You can imagine a Talk between the player and NPCs as a directed graph where each node is an action that can be performed such as saying a line, joining/leaving the conversation, or a choice the player can make.
The most common action is text being displayed on the screen, and a simple Talk is just a sequence of texts forming a conversation between actors.
You can have multiple entities each with their own Talk graph. Or you can make a VN-like game with one single big dialogue graph in the game.
[!NOTE] A more in-depth documentation is being slowly written as an mdbook here! Help is appreciated :)
Actions and Actors
Talks are made up of actions that are translated into graph nodes.
Actions can be defined either via the TalkBuilder
(where you have more control over the dialogue graph with custom components and events) or with "talk.ron" asset files. With the latter, you are building dialogue nodes by passing Action
data:
It contains several fields that define the kind of action it can be, the relevant actors, text or choices and the next action to perform (where to go in the graph after).
The actors are quite simple right now. It is just the name and an identifier (the slug):
Having a well defined Talk with actions and actors will result in spawning a graph where all the nodes are entities. Each action will be an entity "node", and each actor is also an entity.
All the action nodes will be connected with each other with an aery relationship (called FollowedBy), following the graph structure given by the actions next and id fields, and each action with actors will result in the corresponding entity being connected with the actors entities with another aery relationship (called PerformedBy).
The Parent Talk
All the node entities in the graph will be a child of a main entity that represents the Talk itself, with the Talk component attached to it.
You can think of this parent Talk entity as it "encapsulates" the graph and you can use it to identify a dialogue graph. You will use it to send events to advance the dialogue.
Build Talks from talk.ron files
The above-mentioned ron assets files are used to create TalkData
assets. They can be used to build dialogue graphs via bevy Commands
.
The files must have the extension: talk.ron
. Here's an example:
The plugin adds an AssetLoader
for these ron files, so it's as easy as:
let handle: = asset_server.load;
Then you can use Talk::builder()
to create a TalkBuilder
, which has the fill_with_talk_data
method.
You can retrieve the TalkData
from the assets collection talks: Res<Assets<TalkData>>
.
With the builder ready, you can use the Commands extension to spawn the dialogue graph in the world:
use *;
use *;
// We stored the previously loaded handle of a TalkData asset in this resource
Spawning that talk graph will result in this:
graph LR;
A[Narrator Talks] --> B[Alice,Bob Join];
B --> C[Bob Talks];
C --> D[Choice];
D --> E[Narrator Talks];
D --> F[Narrator Talks];
F --> G[Narrator Talks];
E --> G;
Usage
Besides building dialogue graphs, at some point you have to interact with them.
After all the nodes are entities with components, so you could just do queries using the special CurrentNode
component that keeps track of the current node. Then each node could have a TextNode
, JoinNode
, LeaveNode
, ChoiceNode
or your own custom components (added via the builder).
Another way is to use a dialogue graph in an event-driven way. The plugin sends events every time you move to a new node based on the components it has. A node with a TextNode
will send a TextNodeEvent
event, a node with a ChoiceNode
will send a ChoiceEvent
event, and so on. You can also add your own node emitting components to customize the behaviour.
For example, to display the text of a TextNode
you can simply listen to the TextNodeEvent
event:
Note that the actors connected to the node are injected in the event, so you don't need to query them.
Request Events
That's the events from a dialogue graph to you. There is also the other direction so you can send requests to the dialogue graph (to advance the dialogue).
To move forward to the next action:
/// Event to request the next node in a `Talk`.
/// It requires an entity with the `Talk` component you want to update.
To jump to a specific action (used with choices):
/// An event to jump to some specific node in a graph.
/// It requires an entity with the `Talk` component you want to update.
There is also an useful event to re-send all the events associated to a node:
/// Event to request the current node to re-send all its events.
You pass the entity with the Talk
component in these events, plus the next node entity in case of the choose event.
Check out the examples
folder to see how to use the plugin.
- simple.rs shows how to use the plugin to create a simple, linear conversation.
- choices.rs shows how to use the plugin to create a conversation with choices (jumps in the graph).
- full.rs shows a Talk where all the action kinds are used.
- ingame.rs shows how to use the plugin with more than one talk you can interact with.
- custom_node_event.rs shows how to add your own event emitting component to create a custom node.
Roadmap
Some nice-to-haves from the top of my head:
- More node kinds (got rid of node kinds, now nodes are entities with components)
- Extensive documentation/manual wiki (added an mdbook, but always in progress...)
- Extensible Interaction/Trigger system (I mean I'm using events, more decoupled than this is impossible)
- Use the built-in bevy_ecs relations (when one day when we will have them)
- Dialogue UIs
- Graphical editor to create the asset files
- Voice lines/sound support
- Support other asset formats (yarn?)
- More examples
- Localization with Fluent
Bevy Version Support
Compatibility of bevy_talks
versions:
bevy_talks |
bevy |
---|---|
main |
0.12 |
0.5.0 |
0.12 |
0.4.0 |
0.12 |
0.3.1 |
0.12 |
0.3.0 |
0.11 |
0.2.0 |
0.11 |
0.1.1 |
0.11 |
bevy_main |
main |
License
Dual-licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.