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

public class MapScript : MonoBehaviour {


    [SerializeField] List<TileScript> mapTiles = new List<TileScript>();
    [SerializeField] List<CharacterScript> charactersOnMap = new List<CharacterScript>();
    [SerializeField] PlayerControllerScript playerOnMap;

    static List<TileScript> Tiles = new List<TileScript>();
    static List<CharacterScript> Characters = new List<CharacterScript>();
    static PlayerControllerScript Player;


    void Awake()
    {
        Tiles = mapTiles;
        Characters = charactersOnMap;
    }

    // Use this for initialization
    void Start () {
        Tiles = mapTiles;
        Characters = charactersOnMap;
    }
	
	// Update is called once per frame
	void Update () {
        //FindAllCharacters();
        FindPlayer();
        Player = playerOnMap;
        Tiles = mapTiles;
        Characters = charactersOnMap;
    }

    public void FindPlayer()
    {
        PlayerControllerScript foundPlayer = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerControllerScript>();
        if (foundPlayer != null)
        {
            playerOnMap = foundPlayer;
        }
    }

    public void FindAllCharacters()
    {
        //GameObject[] foundChars = GameObject.FindGameObjectsWithTag("Character");
        //List<CharacterScript> newChars = new List<CharacterScript>();
        //for(int i = 0; i < foundChars.Length; i++)
        //{
        //    if(foundChars[i].GetComponent<CharacterScript>() != null)
        //    {
        //        newChars.Add(foundChars[i].GetComponent<CharacterScript>());
        //    }
        //}
        //charactersOnMap = newChars;
    }

    public static int GetXTileCount()
    {
        return 5;
    }

    public static int GetYTileCount()
    {
        return 4;
    }

    public List<TileScript> GetMapTiles()
    {
        return mapTiles;
    }

    public List<CharacterScript> GetCharactersOnMap()
    {
        return charactersOnMap;
    }

    public static List<TileScript> GetTiles()
    {
        return Tiles;
    }

    public static List<CharacterScript> GetCharacters()
    {
        return Characters;
    }

    public static PlayerControllerScript GetPlayer()
    {
        return Player;
    }
}
