using UnityEngine;
using System.Collections;

public class InputController : MonoBehaviour {

	private PlayerMovementController moveCtrl;
	private SwingArmControl armCtrl;

	private Camera mainCamera;

	void Start () {
		moveCtrl = gameObject.GetComponent<PlayerMovementController>();
		armCtrl = gameObject.GetComponent<SwingArmControl>();

		GameObject camGO = GameObject.Find ("Main Camera");
		if(camGO == null)
			Debug.LogError("Input Contoller could not find 'Main Camera' game object.  Required for getting mouse input.  Fix it.");
		mainCamera = camGO.GetComponent<Camera>();
	}

	void Update () {
		Vector2 mousePos = (Vector2)mainCamera.ScreenToWorldPoint(Input.mousePosition);

		//moveCtrl.AimPoint = mousePos;
		//armCtrl.AimPoint = mousePos;

		moveCtrl.UpKeyDown = Input.GetKeyDown(KeyCode.W);
		moveCtrl.DownKeyDown = Input.GetKeyDown(KeyCode.S);
		moveCtrl.LeftKeyDown = Input.GetKeyDown(KeyCode.A);
		moveCtrl.RightKeyDown = Input.GetKeyDown(KeyCode.D);

		/*if(Input.GetKey(KeyCode.A))
		{
			moveCtrl.JukeInput = -1;
		}
		else if(Input.GetKey(KeyCode.D))
		{
			moveCtrl.JukeInput = 1;
		}
		else
		{
			moveCtrl.JukeInput = 0;
		}
		*/

		//moveCtrl.MoveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
		float x =0, y =0;
		if(Input.GetKey(KeyCode.W))
		{
			y = 1;
		}
		else if(Input.GetKey(KeyCode.S))
		{
			y = -1;
		}

		if(Input.GetKey(KeyCode.D))
		{
			x = 1;
		}
		else if(Input.GetKey(KeyCode.A))
		{
			x = -1;
		}

		float rx =0, ry =0;
		if(Input.GetKey(KeyCode.UpArrow))
		{
			ry = 1;
		}
		else if(Input.GetKey(KeyCode.DownArrow))
		{
			ry = -1;
		}
		
		if(Input.GetKey(KeyCode.RightArrow))
		{
			rx = 1;
		}
		else if(Input.GetKey(KeyCode.LeftArrow))
		{
			rx = -1;
		}


		moveCtrl.MoveInput = new Vector2(x,y);
		armCtrl.PlayerInput = new Vector2(rx, ry);
		/*if(Input.GetMouseButtonDown(0))
			moveCtrl.PullTrigger();
		else if(Input.GetMouseButtonDown(1))
			moveCtrl.PullSecondaryTrigger();
		*/

	}
}
