Add addons
This commit is contained in:
parent
2c862b2235
commit
3367bad24f
527 changed files with 36197 additions and 0 deletions
22
Sprout/addons/beehave/nodes/decorators/decorator.gd
Normal file
22
Sprout/addons/beehave/nodes/decorators/decorator.gd
Normal 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
|
||||
12
Sprout/addons/beehave/nodes/decorators/failer.gd
Normal file
12
Sprout/addons/beehave/nodes/decorators/failer.gd
Normal 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
|
||||
21
Sprout/addons/beehave/nodes/decorators/inverter.gd
Normal file
21
Sprout/addons/beehave/nodes/decorators/inverter.gd
Normal 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
|
||||
21
Sprout/addons/beehave/nodes/decorators/limiter.gd
Normal file
21
Sprout/addons/beehave/nodes/decorators/limiter.gd
Normal 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
|
||||
12
Sprout/addons/beehave/nodes/decorators/succeeder.gd
Normal file
12
Sprout/addons/beehave/nodes/decorators/succeeder.gd
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue