Documentation
¶
Overview ¶
Package core provides the building blocks for creating domain-specific behavior tree nodes.
Index ¶
Constants ¶
const ( CategoryInvalid = Category("invalid") CategoryComposite = Category("composite") CategoryDecorator = Category("decorator") CategoryLeaf = Category("leaf") )
A list of behavior tree node categories.
Variables ¶
This section is empty.
Functions ¶
func ErrInvalidType ¶
func ErrParamNotFound ¶
Types ¶
type BaseNode ¶
type BaseNode struct {
// contains filtered or unexported fields
}
BaseNode contains properties shared by all categories of node. Do not use this type directly.
func (*BaseNode) GetCategory ¶
GetCategory returns the category of this node.
type Category ¶
type Category string
Category denotes whether a node is a composite, decorator or leaf.
type Composite ¶
type Composite struct { *BaseNode Children []Node CurrentChild int // TODO - move into instance nodes }
Composite is the base type for any specific composite node. Such a node may be domain-specific, but usually one of the common nodes will be used, such as Sequence or Selector.
func NewComposite ¶
NewComposite creates a new composite base node.
func (*Composite) GetChildren ¶
GetChildren returns a list containing the children of the composite node.
type Context ¶
type Context struct { Owner interface{} Data interface{} }
Context is data implicitly shared by all nodes in a behavior tree since a Context instance is propagated through the tree each tick.
func NewContext ¶
func NewContext(owner, data interface{}) *Context
NewContext creates context containing references to an owner and a store.
type Decorator ¶
Decorator is the base type for any specific decorator node. Such a node may be domain-specific, but usually one of the common nodes will be used, such as Inverter or Repeater. Each decorator node has Params: a key-value map used for setting variables for a specific decorator node, for instance Params{"n": 5} for a Repeater node or Params{"ms": 500} for a Delayer node.
func NewDecorator ¶
NewDecorator creates a new decorator base node.
func (*Decorator) GetChildren ¶
GetChildren returns a list containing the only child of the decorator node.
type Leaf ¶
Leaf is the base type for any specific leaf node (domain-specific). Each leaf node has Params: data keys that the implementation imports and Returns: data keys that the implementation exports.
func (*Leaf) GetChildren ¶
GetChildren returns an empty list of Node, since a leaf has no children. This method is required for Leaf in order to implement Node.
type Node ¶
type Node interface { // Automatically implemented by embedding a pointer to a // Composite, Decorator or Leaf node in the custom node. GetStatus() Status SetStatus(Status) GetCategory() Category GetChildren() []Node String() string // Must be implemented by the custom node. Enter(*Context) Tick(*Context) Status Leave(*Context) }
The Node interface must be satisfied by any custom node.