using UnityEngine;
using Vector2 = UnityEngine.Vector2;

public class JoyStickInputController : MonoBehaviour
{
    public Controller controller;
	
    public Action GetInputAction()
    {
        string suffix;
        switch (controller)
        {
            case Controller.One:
                suffix = "_First";
                break;
            case Controller.Two:
                suffix = "_Second";
                break;
            default:
                suffix = string.Empty;
                break;
        }

        float inputLsh = Input.GetAxisRaw("DPAD_H_Controller" + suffix);
        float inputLsv = Input.GetAxisRaw("DPAD_V_Controller" + suffix);

        Vector2 input = new Vector2(inputLsh, inputLsv).normalized;


        if (Vector2.zero != input)
        {
            print(input);
        }

        bool inputInt = Input.GetButton("A_BTN_Controller" + suffix);

        if (inputLsh != 0)
            print(inputLsh);
        if (inputLsv != 0)
            print(inputLsv);

        if (controller == Controller.One)
        {
            if (Input.GetKeyDown(KeyCode.W))
                return Action.Up;
            if (Input.GetKeyDown(KeyCode.A))
                return Action.Left;
            if (Input.GetKeyDown(KeyCode.S))
                return Action.Down;
            if (Input.GetKeyDown(KeyCode.D))
                return Action.Right;
        }

		if (controller == Controller.Two)
        {
            if (Input.GetKeyDown(KeyCode.UpArrow))
                return Action.Up;
            if (Input.GetKeyDown(KeyCode.LeftArrow))
                return Action.Left;
            if (Input.GetKeyDown(KeyCode.DownArrow))
                return Action.Down;
            if (Input.GetKeyDown(KeyCode.RightArrow))
                return Action.Right;
        }


        if (input.x < 0)
            return Action.Left;
        if (input.x > 0)
            return Action.Right;
        if (input.y > 0)
            return Action.Up;
        if (input.y < 0)
            return Action.Down;
        if (inputInt)
            return Action.Interact;

        return Action.None;
    }
}

public enum Controller
{
    One,
    Two
}

public enum Action
{
    None,
    Up,
    Down,
    Left,
    Right,
    Interact
}