using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using CorgiLabs.Utility;

public class GhostSpawner : MonoBehaviour
{
    [SerializeField] private GhostFeedback m_GhostPrefab;

    private ObjectPool<GhostFeedback> m_GhostPool;

    private void Awake()
    {
        m_GhostPool = new ObjectPool<GhostFeedback>(
                delegate (GhostFeedback ghost)
                {
                    return !ghost.IsVisible;
                },
                delegate ()
                {
                    return Instantiate(m_GhostPrefab, transform);
                }
            );

        ServiceLocator.Provide(this);
    }

    public void SpawnAt(Vector2 pos)
    {
        GhostFeedback ghost = m_GhostPool.Get();

        ghost.TransformComponent.position = pos;

        ghost.Popup();
    }
}
