using System.Collections.Generic;
using UnityEngine;

public class Game_Manager : MonoBehaviour
{
    public bool enablePlayerSpawn = false;
    public bool playerSpawned = false;
    public GameObject gameOverUI;
    private EnumGameState gameState = EnumGameState.PLAYING;
    private List<GameObject> subscribers = new List<GameObject>();

    public void subscribe(GameObject sub)
    {
        subscribers.Add(sub);
    }
    public void unsubscribe(GameObject sub)
    {
        subscribers.Remove(sub);
    }

    private void notifySubs()
    {
        foreach (GameObject sub in subscribers)
        {
            sub.GetComponent<GameStateController>().notifyInput(gameState);
        }
    }

    public bool readPlayerSpawnEnabled()
    {
        return enablePlayerSpawn;
    }

    public void notifyPlayerSpawn()
    {
        playerSpawned = true;
        enablePlayerSpawn = false;
    }
    public void notifyPlayerDespawn()
    {
        playerSpawned = false;
        enablePlayerSpawn = true;
    }

    public void pauseGame()
    {
        gameState = EnumGameState.PAUSED;
        notifySubs();
    }
    public void unpauseGame()
    {
        gameState = EnumGameState.PLAYING;
        notifySubs();
    }

    public void triggerGameOver()
    {
        gameState = EnumGameState.GAMEOVER;
        notifySubs();
        gameOverUI.SetActive(true);
    }
}
