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

public class InputCustomizer : MonoBehaviour {
	public GameObject player;
	public GameObject actualPlayer;
	public Text txt;
	public int actualSurfer = 0;

	private int playerCount = 1;
	private int joystickCount = 0;

	// Use this for initialization
	void Start () {
		actualPlayer = Instantiate (player);
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	public void SetJoystick (){
		joystickCount++;
		Destroy(actualPlayer.GetComponent<KeyboardInputHandler> ());
		actualPlayer.AddComponent<JoystickInputHandler>().joystickNumber = joystickCount;
	}

	public void SetKeys(int a){
		string[] prekeys = new string[4];
		if (a == 0) prekeys = new string[] {"a","d","w","s"};
		if (a == 1) prekeys = new string[] {"left","right","up","down"};
		if (a == 2) prekeys = new string[] {"j","l","i","k"};
		if (a == 3) prekeys = new string[] {"[4]","[6]","[8]","[5]"};
		KeyboardInputHandler inputs = actualPlayer.GetComponent<KeyboardInputHandler> ();
		for (int i = 0; i < 4; i++) {
			inputs.keys [i] = prekeys [i];
		}
	}

	public void SetSurfer(string name){
		GameObject.Find (name).GetComponent<Surfer> ().handler = actualPlayer.GetComponent<InputHandler> ();
	}

	public void NewPlayer(){
		++playerCount;
		txt.text = "Player " + playerCount;
		actualPlayer = Instantiate (player);
	}
}
