Class: BehaviorTree::Tree
- Inherits:
-
SingleChildNodeBase
- Object
- NodeBase
- SingleChildNodeBase
- BehaviorTree::Tree
- Defined in:
- lib/behavior_tree/tree.rb
Overview
Root node of the tree. This is the class that must be instantiated by the user.
Constant Summary collapse
- CHILD_VALID_CLASSES =
[ Decorators::DecoratorBase, ControlNodeBase, TaskBase ].freeze
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #chainable_node ⇒ Object
- #ensure_after_tick ⇒ Object
-
#initialize(child) ⇒ Tree
constructor
A new instance of Tree.
Methods included from BehaviorTree::TreeStructure::Printer
Methods included from BehaviorTree::TreeStructure::Algorithms
#cycle?, #each_node, #repeated_nodes, #uniq_nodes?
Constructor Details
#initialize(child) ⇒ Tree
Returns a new instance of Tree.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/behavior_tree/tree.rb', line 15 def initialize(child) super(child) if child.nil? # Cannot be leaf, raise error. if CHILD_VALID_CLASSES.any? { |node_class| child.is_a?(NodeBase) && child.chainable_node.is_a?(node_class) } super(child) return end raise InvalidTreeMainNodeError, child.class end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/behavior_tree/tree.rb', line 9 def context @context end |
Instance Method Details
#chainable_node ⇒ Object
26 27 28 |
# File 'lib/behavior_tree/tree.rb', line 26 def chainable_node @child end |
#ensure_after_tick ⇒ Object
30 31 32 33 |
# File 'lib/behavior_tree/tree.rb', line 30 def ensure_after_tick # Copy the main node status to self. self.status = child.status end |