extends Node

class_name TaskList

var unassigned_tasks: Array[Dictionary] = []

var assigned_task_dict: Dictionary = {}

func record_task(task):
#Records a provided task in the list
	
	if task.assignment:
		var assignment: Actor = task["assignment"]
		#var assignment_task_list: Array = []
		assign_task(task, assignment)
		if not assigned_task_dict.has(assignment):
			assigned_task_dict[assignment] = []
		assigned_task_dict[assignment].append(task)

func finish_task(source, task):
#Removes a completed task from the list
	
	var source_task_array = assigned_task_dict[source]
	var finished_task_index = source_task_array.find(task)
	source_task_array.pop_at(finished_task_index)
	
	if not assigned_task_dict[source]:
		assigned_task_dict.erase(source)

func assign_task(task, assignment: Actor):
#Alerts an actor that it has a new task.
	
	assignment.lookup_actor_to_task.append(task)
