using System.Collections;
using System.Collections.Generic;
using GameFlow;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Spawner : MonoBehaviour
{
    public static Spawner Instance;

    public List<GameObject> SpawnQueue;
    public List<float> InkSupplies;
    public GameObject CurrentSpawn;
    public float Cooldown;
    public Vector2 Offset;

    void Start()
    {
        Instance = this;
        StartCoroutine(SpawnRoutine());
    }

    IEnumerator SpawnRoutine()
    {
        yield return new WaitForSeconds(Cooldown);
        for (int i = 0; i < SpawnQueue.Count; i++)
        {
            var spawned = Instantiate(SpawnQueue[i]);
            spawned.transform.position = transform.position;
            spawned.GetComponent<LinePainter>().MaxInk = InkSupplies[i];
            transform.position = transform.position + (Vector3)Offset;
            yield return new WaitUntil(() => !spawned.activeSelf);
            yield return new WaitForSeconds(Cooldown);
        }
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }
}
