Add addons

This commit is contained in:
Joey Yakimowich-Payne 2023-01-03 16:53:53 -07:00
commit 3367bad24f
No known key found for this signature in database
GPG key ID: 6BFE655FA5ABD1E1
527 changed files with 36197 additions and 0 deletions

View file

@ -0,0 +1,22 @@
## Decorator nodes are used to transform the result received by its child.
## Must only have one child.
@tool
class_name Decorator extends BeehaveNode
@icon("../../icons/category_decorator.svg")
func _ready():
if Engine.is_editor_hint():
return
if self.get_child_count() != 1:
push_error("Beehave Error: Decorator %s should have only one child (NodePath: %s)" % [self.name, self.get_path()])
func _get_configuration_warnings() -> PackedStringArray:
var warnings: PackedStringArray = super._get_configuration_warnings()
if get_child_count() != 1:
warnings.append("Decorator should have exactly one child node.")
return warnings

View file

@ -0,0 +1,12 @@
## A Failer node will always return a `FAILURE` status code.
@tool
class_name AlwaysFailDecorator extends Decorator
@icon("../../icons/failer.svg")
func tick(actor: Node, blackboard: Blackboard) -> int:
for c in get_children():
var response = c.tick(actor, blackboard)
if response == RUNNING:
return RUNNING
return FAILURE

View file

@ -0,0 +1,21 @@
## An inverter will return `FAILURE` in case it's child returns a `SUCCESS` status
## code or `SUCCESS` in case its child returns a `FAILURE` status code.
@tool
class_name InverterDecorator extends Decorator
@icon("../../icons/inverter.svg")
func tick(actor: Node, blackboard: Blackboard) -> int:
for c in get_children():
var response = c.tick(actor, blackboard)
if response == SUCCESS:
return FAILURE
if response == FAILURE:
return SUCCESS
if c is Leaf and response == RUNNING:
blackboard.set_value("running_action", c)
return RUNNING
# Decorators must have a child. This should be unreachable code.
return FAILURE

View file

@ -0,0 +1,21 @@
## The limiter will execute its child `x` amount of times. When the number of
## maximum ticks is reached, it will return a `FAILURE` status code.
@tool
class_name LimiterDecorator extends Decorator
@icon("../../icons/limiter.svg")
@onready var cache_key = 'limiter_%s' % self.get_instance_id()
@export var max_count : float = 0
func tick(actor: Node, blackboard: Blackboard) -> int:
var current_count = blackboard.get_value(cache_key)
if current_count == null:
current_count = 0
if current_count <= max_count:
blackboard.set_value(cache_key, current_count + 1)
return self.get_child(0).tick(actor, blackboard)
else:
return FAILURE

View file

@ -0,0 +1,12 @@
## A succeeder node will always return a `SUCCESS` status code.
@tool
class_name AlwaysSucceedDecorator extends Decorator
@icon("../../icons/succeeder.svg")
func tick(actor: Node, blackboard: Blackboard) -> int:
for c in get_children():
var response = c.tick(actor, blackboard)
if response == RUNNING:
return RUNNING
return SUCCESS