pub struct BehaviorConfig {
pub schema: Option<String>,
pub name: String,
pub description: Option<String>,
pub root: CompositionConfig,
pub configs: HashMap<String, Value>,
}Expand description
Root configuration for a behavior composition.
This is the top-level structure for defining behavior trees in JSON.
§Example JSON
{
"$schema": "https://mecha10.dev/schemas/behavior-composition-v1.json",
"name": "patrol_mission",
"description": "Patrol behavior with safety layer",
"root": {
"type": "sequence",
"children": [
{
"type": "node",
"node": "safety_check",
"config_ref": "safety"
},
{
"type": "selector",
"children": [
{
"type": "node",
"node": "detect_obstacles",
"config_ref": "detector"
},
{
"type": "node",
"node": "wander",
"config_ref": "wander"
}
]
}
]
},
"configs": {
"safety": { "max_speed": 1.0 },
"detector": { "confidence": 0.7 },
"wander": { "speed": 0.5 }
}
}Fields§
§schema: Option<String>Schema reference for validation and IntelliSense
name: StringName of this behavior composition
description: Option<String>Optional description
root: CompositionConfigRoot composition node
configs: HashMap<String, Value>Configuration values referenced by nodes
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 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
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl JsonSchema for BehaviorConfig
impl JsonSchema for BehaviorConfig
Source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$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,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for BehaviorConfig
impl RefUnwindSafe for BehaviorConfig
impl Send for BehaviorConfig
impl Sync for BehaviorConfig
impl Unpin 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
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