pub struct BehaviorConfig {
pub schema: Option<String>,
pub name: String,
pub description: Option<String>,
pub root: CompositionConfig,
pub configs: HashMap<String, Value>,
}Expand description
A behavior tree definition loaded from a JSON configuration file.
Fields§
§schema: Option<String>URL of the JSON schema this configuration conforms to.
name: StringName of this behavior.
description: Option<String>Human-readable description of what this behavior does.
root: CompositionConfigThe root node of the behavior tree.
configs: HashMap<String, Value>Named configuration values referenced by nodes in the behavior tree via config_ref.
Implementations§
Source§impl BehaviorConfig
impl BehaviorConfig
Sourcepub fn from_json(json: &str) -> Result<BehaviorConfig, Error>
pub fn from_json(json: &str) -> Result<BehaviorConfig, Error>
Load a behavior configuration from a JSON string.
§Example
use mecha10_behavior_runtime::BehaviorConfig;
let json = r#"{
"name": "test_behavior",
"root": {
"type": "sequence",
"children": []
}
}"#;
let config = BehaviorConfig::from_json(json).unwrap();
assert_eq!(config.name, "test_behavior");Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<BehaviorConfig, Error>
pub fn from_file(path: impl AsRef<Path>) -> Result<BehaviorConfig, Error>
Load a behavior configuration from a JSON file.
Sourcepub fn generate_schema() -> Result<String, Error>
pub fn generate_schema() -> Result<String, Error>
Generate a JSON schema for this configuration type.
This can be used for editor IntelliSense and validation.
Sourcepub fn schema_value() -> Value
pub fn schema_value() -> Value
The schemars-derived JSON Schema for this configuration type, as a
serde_json::Value – the same schema generate_schema
serializes to a pretty-printed string, super::validator’s runtime validator
is built from, and cargo run --example export_schemas
(packages/cli/examples/export_schemas.rs) renders to schemas/behavior.schema.json,
the single standard-named schemas/ source of truth for this type (LAB-4245 folded
the old separate cargo run --example generate_schema →
schemas/behavior_composition_v1.json path into this one).
Sourcepub fn get_config(&self, key: &str) -> Option<&Value>
pub fn get_config(&self, key: &str) -> Option<&Value>
Get a configuration value by reference key.
Trait Implementations§
Source§impl Clone for BehaviorConfig
impl Clone for BehaviorConfig
Source§fn clone(&self) -> BehaviorConfig
fn clone(&self) -> BehaviorConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BehaviorConfig
impl Debug for BehaviorConfig
Source§impl<'de> Deserialize<'de> for BehaviorConfig
impl<'de> Deserialize<'de> for BehaviorConfig
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<BehaviorConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<BehaviorConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for BehaviorConfig
impl JsonSchema for BehaviorConfig
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Serialize for BehaviorConfig
impl Serialize for BehaviorConfig
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for BehaviorConfig
impl RefUnwindSafe for BehaviorConfig
impl Send for BehaviorConfig
impl Sync for BehaviorConfig
impl Unpin for BehaviorConfig
impl UnsafeUnpin for BehaviorConfig
impl UnwindSafe for BehaviorConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> ⓘ
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> ⓘ
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