Skip to main content

Crate bonsai_mdsl

Crate bonsai_mdsl 

Source
Expand description

§Bonsai MDSL

A Rust library for parsing and executing behavior trees defined in MDSL (Mistreevous Domain Specific Language).

This library provides a high-performance, type-safe implementation of behavior trees using the MDSL format originally created by the mistreevous TypeScript library.

§Basic Usage

use bonsai_mdsl::{BehaviorTree, TreeContext, NodeResult};

let mdsl = r#"
root {
    sequence {
        action [greet]
        action [wave]
    }
}
"#;

let mut context = TreeContext::new();
context.register_simple_action("greet", || {
    println!("Hello!");
    NodeResult::Success
});
context.register_simple_action("wave", || {
    println!("*waves*");
    NodeResult::Success
});

let mut tree = BehaviorTree::from_mdsl(mdsl).unwrap();
let result = tree.tick(&context).unwrap();
assert_eq!(result, NodeResult::Success);

Re-exports§

pub use context::TreeContext;
pub use error::BonsaiError;
pub use error::Result;
pub use nodes::Node;
pub use nodes::NodeResult;
pub use nodes::NodeState;
pub use nodes::NodeType;
pub use tree::BehaviorTree;
pub use async_context::AsyncTreeContext;
pub use parser::parse_mdsl;
pub use parser::MdslValue;

Modules§

async_context
Async Context for Behavior Trees
context
error
nodes
parser
tree

Constants§

VERSION
Current version of the library