58 lines
1.2 KiB
GDScript
58 lines
1.2 KiB
GDScript
class_name Task
|
|
extends Node
|
|
|
|
enum {FAILURE = -1, SUCCESS = 1, RUNNING = 0}
|
|
var status: int = FAILURE
|
|
var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
|
|
|
|
|
|
func _ready() -> void:
|
|
for c in get_children():
|
|
if not c is Task:
|
|
push_error("Child is not a task: " + c.name + " in " + name)
|
|
return
|
|
|
|
|
|
func internal_run(p_blackboard: Dictionary) -> void:
|
|
p_blackboard["current_task"] = self
|
|
|
|
if status == RUNNING:
|
|
var running_child: Task = find_running_child()
|
|
if running_child != null:
|
|
running_child.internal_run(p_blackboard)
|
|
status = running_child.status
|
|
return
|
|
else:
|
|
run(p_blackboard)
|
|
else:
|
|
run(p_blackboard)
|
|
|
|
|
|
|
|
func find_running_child() -> Task:
|
|
for c in get_children():
|
|
if c.status == RUNNING:
|
|
return c
|
|
return null
|
|
|
|
|
|
func run_child(p_blackboard: Dictionary, p_child: Task) -> void:
|
|
p_child.internal_run(p_blackboard)
|
|
if p_child.status != RUNNING:
|
|
status = RUNNING
|
|
|
|
|
|
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
|