mecha10-behavior-runtime 0.6.3

Behavior tree runtime for Mecha10 - unified AI and logic composition system
Documentation
//! Built-in action nodes for behavior trees
//!
//! This module provides common action nodes that can be used in behavior tree compositions.
//! All nodes implement the `BehaviorNode` trait and can be registered in the NodeRegistry.
//!
//! The node implementations are split into cohesive submodules:
//! - [`movement`]: nodes that publish velocity commands (`WanderNode`, `MoveNode`, `StopNode`)
//! - [`sensing`]: nodes that inspect sensor state (`SensorCheckNode`)
//! - [`timing`]: nodes that gate on elapsed time or do nothing (`TimerNode`, `PauseNode`, `IdleNode`)
//! - [`navigation`]: stub path-planning/following/arrival nodes (`PlanPathNode`, `FollowPathNode`,
//!   `CheckArrivalNode`)

mod movement;
mod navigation;
mod sensing;
mod timing;

pub use movement::{MoveNode, StopNode, WanderNode};
pub use navigation::{CheckArrivalNode, FollowPathNode, PlanPathNode};
pub use sensing::SensorCheckNode;
pub use timing::{IdleNode, PauseNode, TimerNode};

use crate::{BoxedBehavior, NodeRegistry};
use serde_json::Value;

/// Registers a single builtin action under `$name`, wiring its `from_json`
/// constructor into the registry. Avoids repeating the same closure shape
/// for every node type.
macro_rules! register_action {
    ($registry:expr, $name:literal, $node_type:ty) => {
        $registry.register($name, |config: Value| -> anyhow::Result<BoxedBehavior> {
            Ok(Box::new(<$node_type>::from_json(config)?))
        });
    };
}

/// Register all built-in action nodes with a registry
///
/// This function registers the following nodes:
/// - `wander`: WanderNode
/// - `move`: MoveNode
/// - `sensor_check`: SensorCheckNode
/// - `timer`: TimerNode
/// - `idle`: IdleNode
/// - `pause`: PauseNode
/// - `stop`: StopNode
/// - `plan_path`: PlanPathNode
/// - `follow_path`: FollowPathNode
/// - `check_arrival`: CheckArrivalNode
///
/// # Example
///
/// ```rust
/// use mecha10_behavior_runtime::{NodeRegistry, actions};
///
/// let mut registry = NodeRegistry::new();
/// actions::register_builtin_actions(&mut registry);
/// ```
pub fn register_builtin_actions(registry: &mut NodeRegistry) {
    register_action!(registry, "wander", WanderNode);
    register_action!(registry, "move", MoveNode);
    register_action!(registry, "sensor_check", SensorCheckNode);
    register_action!(registry, "timer", TimerNode);
    register_action!(registry, "idle", IdleNode);
    register_action!(registry, "pause", PauseNode);
    register_action!(registry, "stop", StopNode);
    register_action!(registry, "plan_path", PlanPathNode);
    register_action!(registry, "follow_path", FollowPathNode);
    register_action!(registry, "check_arrival", CheckArrivalNode);
}