giusdp / bevy_talks Goto Github PK
View Code? Open in Web Editor NEWA Bevy plugin to write dialogues for your characters, together with player choices.
Home Page: https://giusdp.github.io/bevy_talks/
License: Apache License 2.0
A Bevy plugin to write dialogues for your characters, together with player choices.
Home Page: https://giusdp.github.io/bevy_talks/
License: Apache License 2.0
While waiting for the official Bevy editor, let's start with egui and have a way to write characters and dialogue graphs.
We can take inspiration
Currently the graph that models a conversation is implemented with petgraph and stored into a component Talk
.
This also keeps track of the start_node
and current_node
(these are NodeIndex).
There are also some helper components (CurrentText, CurrentActor, CurrentNodeKind...) that can be queried, but they are kinda useless since you just need to query for Talk
and you can access all the info you need.
It would be interesting to try to model the graph as a bunch of entities:
Bundle
to quickly create nodes.We could have a root Entity that represents the entire dialogue graph (with some marker component). Then each children entity has the bundle of components to make it a "TalkNode". They each have the "Next" component so we know where it points to.
despawn_recursively()
the root entity.Perhaps we could use aery to add relationships between entities.
Instead of using "Next" component to have a pointer to the next dialogue, we can put the 2 TalkNode entities in a relationship? We should investigate this.
The relationship can also be useful to tie together a TalkNode with the Actors.
We ca have all the actors of a dialogue graph as their own entities (with the appropiate components) connected to each TalkNode in a relationship.
After the dialogues as entity-graph refactor it would be nice to move away from the single point of access approach (the parent entity with the Talk
component). Instead an user should be able to interact with the nodes directly (by making CurrentNode component public so it can be queried).
The Talk
parent is still needed to be able to differentiate between multiple dialogue graphs and identify which dialogue graph to advance with the NextActionRequest and ChooseActionRequest events.
We can add events from the dialogue graph to the outside (the other direction) so that it is possible to react to the changes in the dialogue graph (just moving from one node to another). Having direct access to the nodes and having the nodes send events would make the dialogue graphs way more flexible and customizable.
I have a working demo using bevy-trait-query and this trait:
#[bevy_trait_query::queryable]
pub trait NodeEventEmitter {
/// Creates an event to be emitted when a node is reached.
fn make(&self, actors: &[Entity]) -> Box<dyn Reflect>;
}
Moving to a node with text will result in an event being sent that I defined as:
/// Emitted when a text node is reached.
#[derive(Event, Reflect, Default, Clone)]
#[reflect(Event)]
pub struct TextNodeEvent {
/// The text from the node.
pub text: String,
/// The actors from the node.
pub actors: Vec<Entity>,
}
Now a "Text Node" in a dialogue graph is a component:
/// Component to mark a dialogue node as a text node containing some text.
#[derive(Component, Default, Debug)]
pub struct TextNode(pub String);
impl NodeEventEmitter for TextNode {
fn make(&self, actors: &[Entity]) -> Box<dyn Reflect> {
Box::from(TextNodeEvent {
text: self.0.clone(),
actors: actors.to_vec(),
})
}
}
Note that the "actors" are automatically injected by the plugin.
This is a complete implementation of a component for a dialogue node that will enable the node to send an event when reached.
Also the Join, Leave and Choice nodes are defined as components with the relative events attached.
For the users it will unlock the possibility to add any custom component to nodes that can optionally emit events (the TalkBuilder will need to be updated for that).
Reactive to events instead of checking the Talk entity fields also simplify the API. Now you can have multiple smaller systems that just listen to the events (join, leave, text, choice + custom ones)
This needs some cleaning and testing + all the boilerplate to enable events attached to components can be stuffed inside a macro.
Bevy has moved its plugin guidelines to the Bevy Book on the website. As a result, the bevy tracking link is broken. Willing to create a PR for the same if required.
See bevyengine/bevy#11272
Right now there is one asset file used to create a dialogue graph. It contains both the actors vector and the script actions vector.
The actions also contain the data needed to create the actual graph (ids and next ids), together with other data (the kind of action, actor, text...).
We could instead take a different approach and split this asset file into 3 assets.
Actors asset file that acts as a DB of the characters in a game
A file with just the dialogue lines without graph metadata.
The graph file that operates just with the ids and puts together actors id, dialogue ids to form a node and connect them together.
Library looks snazzy, was wanting to give it a shot but had a feature request. It'd be nice to be able to conditionally include choices. A use case being new dialogue option existing if the player is currently on a quest.
Potentially related to #41, though it'd be nice if it could also be done within the asset files.
Besides the asset files that describe dialogue graphs, it can be useful to have some builder pattern API to create dialogue graphs and add nodes via code so they can be build at runtime.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.