Files
DevKage 955411d34a feat: Add Blackboard support for behavior trees (#3756)
This PR adds blackboard support to the behavior tree packages, enabling
shared memory/data storage between nodes in a behavior tree.

## What's New

### Core Features
- **`Blackboard` class** (`behavior_tree` package): A type-safe
key-value store for sharing data between behavior tree nodes
  - `set<T>(key, value)` - Store values with type safety
- `get<T>(key, {defaultValue})` - Retrieve values (throws `StateError`
if key not found without default)
  - `has(key)` - Check key existence
  - `remove(key)` - Remove entries
  - `clear()` - Clear all entries
  - `copy()` - Create independent copies

- **`BlackboardProvider` interface**: Enables components to provide
blackboards to behavior trees

- **Parent-query architecture**: Nodes access the blackboard through
their parent chain, eliminating the need for explicit parameter passing
  - Root node receives `BlackboardProvider` reference
  - Child nodes query parents via `_parent` chain
- Blackboard getter: `return _blackboardProvider?.blackboard ??
_parent?.blackboard`

### Integration with Flame
- **`HasBehaviorTree` mixin** now implements `BlackboardProvider`
  - New `blackboard` property for setting/getting the shared blackboard
- Automatically sets blackboard provider on root node when `treeRoot` is
assigned
  - Fully backward compatible - blackboard is optional

### Implementation Details
- Parent relationships established in node constructors via
`setParent()` calls
- All composite nodes (`Sequence`, `Selector`) and decorator nodes
(`Inverter`, `Limiter`) updated to set parent references
- Blackboard stored only in component, not duplicated in nodes
- Zero performance overhead when blackboard not used

## Motivation

Behavior trees often need to share state between nodes (e.g., enemy
health, player distance, patrol points). Previously, this required
either:
1. Passing data through constructor parameters (verbose, inflexible)
2. Using global state (poor encapsulation)
3. Custom node implementations with component references (tight
coupling)

The blackboard pattern provides a clean, flexible solution that's common
in AI systems and game engines.

---------

Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
2025-11-22 18:04:37 +01:00
..