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



public class Console_script : MonoBehaviour 
{
	public TMP_Text console;
	public TMP_InputField command;
	public float startWait, typingRate;
	[TextArea]
	public string initSentence;
	
	// Use this for initialization
	void Start () 
	{
		console.text = "";
		InsertSentence (initSentence);
	}
	

	void Update () 
	{
		
	}

	public void InsertSentence(string sentence)
	{
		StartCoroutine (TypeSentence(sentence));
	}

	public void InsertPlayerSentence()
	{
		

		if (command.text.ToUpper() == "ANALYSIS") 
		{
			if (SharedValues_script.foundScenarioFreq) 
			{
				InsertSentence("TRAMISSION INITIATED!");
			}
		}
		else
			StartCoroutine (TypeSentence(command.text));


		command.text = "";
		command.ActivateInputField ();
	}

	IEnumerator TypeSentence(string sentence)
	{
		console.text += "\n";
		yield return new WaitForSeconds(startWait);
		foreach (char letter in sentence.ToCharArray())
		{
			console.text += letter;

			if(typingRate != 0f)
				yield return new WaitForSeconds(typingRate);
			else
				yield return null;
		}


	}
}
