using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WinCondition : MonoBehaviour
{
    public static Action OnWin;

    private static int s_dwarves;

    public static void DwarfClimbedLadder()
    {
        s_dwarves -= 1;
        if(s_dwarves == 0)
        {
            Debug.Log("All dwarves have escaped");
            OnWin?.Invoke();
        }
    }

    [SerializeField] private TMPro.TMP_Text m_text;

    private void Start()
    {
        var dwarves = GameObject.FindGameObjectsWithTag("Player");
        s_dwarves = dwarves.Length;
        m_text.enabled = false;
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
#if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
#else
            Application.Quit();
#endif
        }
        if (s_dwarves == 0)
        {
            m_text.enabled = true;
        }
    }
}
