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

public class ErrorDisplay : MonoBehaviour
{

	//Text textField;
	List<string> errorCodes = new List<string>();
	TextMesh textField;
    string last_text;

	void setText(string t)
		{
		    last_text = t;
		    textField.text = t;
		}

	string getText()
		{
		    return last_text;
		}

    public void removeCode(string code)
    {
        //remove matching code, if it exists
        errorCodes.RemoveAll(item => item == code);
    }

    public void addCode(string code)
    {
        //remove matching code, if it exists
        errorCodes.Add(code);
    }

	public void clearCodes()
	{
		setText("");
        errorCodes.Clear();
	}

	// Use this for initialization
	void Start () 
	{
		textField = GetComponent<TextMesh>();
		clearCodes();
	}

	// Update is called once per frame
	void Update () 
	{
        string displayCodes = "";

        foreach (string code in errorCodes)
        {
            displayCodes += "ERROR> " + code + "\n";
        }

        setText(displayCodes);

		// DEBUG
		//textField.text = "Bonjour le monde\ncomment ca va?\nchalala\nazea";
	}
}
