using UnityEngine;
using System.Collections.Generic;

public class MakeDoorsAux : MonoBehaviour {

    // Deprecated class. Creates the doors from the CSV.

    private TextAsset graph;
    private string[] text;
    private Dictionary<int, Nexus> dic;

    void Awake() {
        this.dic = new Dictionary<int, Nexus> ();
        this.graph = (TextAsset) Resources.Load ("newMap");
        this.ConstructDict ();
        this.ConstructNexus ();
    }


    void ConstructDict() {
        Debug.Log("Creating map...");
        int sceneInt;
        this.text = this.graph.text.Split('\n');

        foreach (string line in text)
        {
            if (line.Contains("#")) continue;

            sceneInt = int.Parse(line.Split(' ')[0]);

            //Debug.Log("Map scene: " + sceneInt);
            if (sceneInt == Application.loadedLevel)
            {
                this.dic.Add(int.Parse(line.Split(' ')[1]), new Nexus(line));
            }

        }

    }

    void ConstructNexus()
    {
        Debug.Log("Creating doors...");
        //Debug.Log(this.dic.Keys.ToString());
        Nexus tmp;
        GameObject ingameFolder = GameObject.Find("Doors to");

        foreach (int nexus in this.dic.Keys)
        {
            //Debug.Log(nexus);
            GameObject g = new GameObject();
            tmp = this.dic[nexus];
            g.name = "Door in " + tmp.source + " to " + tmp.destiny;
            //Debug.Log(g.name);

            g.AddComponent<BoxCollider>();
            BoxCollider box = g.GetComponent<BoxCollider>();

            box.size = tmp.sizeBox;
            box.center = tmp.centerBox;
            box.isTrigger = true;
            g.AddComponent<Door>();
            //g.GetComponent<Door>().setNexus(tmp);

            g.transform.parent = ingameFolder.transform;
        }

    }
}
