namespace BP
{
	//------------------------------------------------------------------------------------------------------------------------
	// Make Serializable - array of tasks, task: delay, type, Data kStr, 
	//
	// Tasks: Play sound with String on an actor
	//        Remove an actor then add that actor to the team again
	// Use only if you don't care that the task will not be serialized. Like maybe playing a sound effect.
	// (*Possibly delete this as it's almost useless*)
	//------------------------------------------------------------------------------------------------------------------------
	namespace Tasks
	{
		funcdef void TaskCallBack();
		array<Task> tasks;
		
		//------------------------------------------------------------------------------------------------------------------------
		void Tick()
		{
			int length = int(tasks.length());
			for (int i = length - 1; i >= 0; i--)
			{
				Task @task = tasks[i];
				task.delay -= GAME_DELTA_TIME;
				if (task.delay <= 0.0f)
				{
					if (task.onCallback !is null)
					{
						task.onCallback();
					}
					tasks.removeAt(i);
				}
			}
		}
		//------------------------------------------------------------------------------------------------------------------------
		void Add(float delay, TaskCallBack@ taskCallback)
		{
			tasks.insertLast(Task(delay, @taskCallback));
		}
		//------------------------------------------------------------------------------------------------------------------------
		void Clear()
		{
			tasks.resize(0);
		}
		//============================================================================================================================
		class Task
		{
			float delay;
			TaskCallBack @onCallback;
			//------------------------------------------------------------------------------------------------------------------------
			Task() {}
			//------------------------------------------------------------------------------------------------------------------------
			Task(float newDelay, TaskCallBack @onCallback)
			{
				DebugAssert(onCallback !is null, "[BP::Task] onCallback arg is null");
				delay = newDelay;
				@this.onCallback = @onCallback;
			}
			//------------------------------------------------------------------------------------------------------------------------
			Task@ opAssign(Task &in other)
			{
				delay = other.delay;
				@onCallback = @other.onCallback;
				
				return this;
			}
			//------------------------------------------------------------------------------------------------------------------------
		};
		//============================================================================================================================
	}
}
