forked from 2121578/gai-ca2
36 lines
774 B
GDScript
36 lines
774 B
GDScript
class_name Task
|
|
extends Node
|
|
|
|
enum {FAILURE = -1, SUCCESS = 1, RUNNING = 0}
|
|
var status: int = FAILURE
|
|
|
|
|
|
func internal_run(p_blackboard: Dictionary) -> void:
|
|
p_blackboard["current_task"] = self
|
|
|
|
if status == RUNNING:
|
|
for c in self.get_children():
|
|
if not c.status == RUNNING:
|
|
continue
|
|
c.internal_run(p_blackboard)
|
|
if c.status != SUCCESS:
|
|
status = c.status
|
|
return
|
|
|
|
run(p_blackboard)
|
|
|
|
|
|
func run(p_blackboard: Dictionary) -> void:
|
|
pass
|
|
|
|
|
|
func cancel(p_blackboard: Dictionary):
|
|
pass
|
|
|
|
|
|
func get_first_child() -> Task:
|
|
if get_child_count() == 0:
|
|
push_error("Task does not have any children: " + name)
|
|
return null
|
|
return get_children()[0] as Task
|