Git Product home page Git Product logo

bevy_talks's Introduction

Hi there ๐Ÿ‘‹

  • I'm Giuseppe, an italian developer and Ph.D. student in Computer Science and Engineering from the University of Bologna.
  • I work mainly on distributed systems and serverless platforms. Currently researching configuration languages for scheduling in serverless.
  • I also am a Software Engineer at Nuvolaris, a startup in serverless computing (mostly using Go there).
  • I'm a passionate coder working on my own projects:

How to reach me:

bevy_talks's People

Contributors

dependabot[bot] avatar giusdp avatar manankarnik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bevy_talks's Issues

Nodes emitting events architecture

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.

Conditional choices

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.

Split talk script files

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.

    • It can be useful to build dialogue graphs procedurally. If we have just the pool of dialogue lines we can pick them and make a graph at runtime.
    • The dialogue lines should have some metadata so they can be grouped together, especially important to indicate which lines are player choices.
    • It is also useful to build graphs with just 1 node that can be added to game items as their description.
  • The graph file that operates just with the ids and puts together actors id, dialogue ids to form a node and connect them together.

    • The non-talk actions (such as Join and Leave) can be used here to indicate when an actor enters/exits the conversation.

Refactor Dialogue Graph

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:

  • Each node as an entity with several components (text, nodekind, next...)
  • the "Next" component contains the Entity of the next node.
  • We can group these components in a 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.

  • It becomes it easy to despawn the entire dialogue graph cause we just need 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.

API to build dialogue graphs programmatically

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.