pub struct BehaviorLoader { /* private fields */ }Implementations§
Source§impl BehaviorLoader
impl BehaviorLoader
Sourcepub fn new(registry: NodeRegistry) -> Self
pub fn new(registry: NodeRegistry) -> Self
Sourcepub fn load(&self, config: &BehaviorConfig) -> Result<BoxedBehavior>
pub fn load(&self, config: &BehaviorConfig) -> Result<BoxedBehavior>
Load a behavior tree from a configuration.
This is the main entry point for loading behavior trees. It takes a
BehaviorConfig (typically loaded from JSON) and recursively instantiates
all nodes in the tree.
§Arguments
config- The behavior configuration to load
§Returns
A boxed behavior node representing the root of the tree, or an error if:
- A referenced node type is not registered
- A config reference is invalid
- A factory function fails
§Example
use mecha10_behavior_runtime::{BehaviorConfig, NodeRegistry, BehaviorLoader};
let loader = BehaviorLoader::new(registry);
let json = r#"{
"name": "test",
"root": {
"type": "node",
"node": "test"
}
}"#;
let config = BehaviorConfig::from_json(json).unwrap();
let behavior = loader.load(&config).unwrap();Sourcepub fn load_from_json(&self, json: &str) -> Result<BoxedBehavior>
pub fn load_from_json(&self, json: &str) -> Result<BoxedBehavior>
Load a behavior tree from a JSON string.
This is a convenience method that combines parsing and loading.
§Arguments
json- JSON string containing a BehaviorConfig
§Example
use mecha10_behavior_runtime::{NodeRegistry, BehaviorLoader};
let loader = BehaviorLoader::new(registry);
let json = r#"{
"name": "test",
"root": {
"type": "node",
"node": "test"
}
}"#;
let behavior = loader.load_from_json(json).unwrap();Sourcepub fn load_from_file(&self, path: impl AsRef<Path>) -> Result<BoxedBehavior>
pub fn load_from_file(&self, path: impl AsRef<Path>) -> Result<BoxedBehavior>
Load a behavior tree from a JSON file.
This is a convenience method that reads a file and loads the behavior tree.
§Arguments
path- Path to the JSON file
§Example
use mecha10_behavior_runtime::{NodeRegistry, BehaviorLoader};
let loader = BehaviorLoader::new(registry);
let behavior = loader.load_from_file("configs/behaviors/@mecha10/patrol/config.json").unwrap();Sourcepub fn registry(&self) -> &NodeRegistry
pub fn registry(&self) -> &NodeRegistry
Get a reference to the underlying node registry.
This can be useful for inspecting registered types or adding new types after the loader has been created.
Trait Implementations§
Source§impl Clone for BehaviorLoader
impl Clone for BehaviorLoader
Auto Trait Implementations§
impl Freeze for BehaviorLoader
impl RefUnwindSafe for BehaviorLoader
impl Send for BehaviorLoader
impl Sync for BehaviorLoader
impl Unpin for BehaviorLoader
impl UnsafeUnpin for BehaviorLoader
impl UnwindSafe for BehaviorLoader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more