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

public class InputManager : MonoBehaviour {
    public float simultaneousInputTimeThreshold = .1f; // If pause between top and bottom is to large, don't consider simultaneous input to be active.

    [HideInInspector]
    public bool topInputActive; // For speed and convenience.
    [HideInInspector]
    public bool bottomInputActive; // For speed and convenience.
    [HideInInspector]
    public bool simultaneousInputActive; // For speed and convenience.

    private float topInputStartTime; // When the last top input started.
    private float bottomInputStartTime; // When the last top input started.

    public void Initialize () {
        topInputStartTime = bottomInputStartTime - simultaneousInputTimeThreshold * 2f;
    }

    private void CacheInput () {
        if (Input.GetButton ("topInput")) {
            if (!topInputActive)
                topInputStartTime = Time.time;
            topInputActive = true;
        } else
            topInputActive = false;

        if (Input.GetButton ("bottomInput")) {
            if (!bottomInputActive)
                bottomInputStartTime = Time.time;
            bottomInputActive = true;
        } else
            bottomInputActive = false;

        simultaneousInputActive = (topInputActive && bottomInputActive && Mathf.Abs (topInputStartTime - bottomInputStartTime) < simultaneousInputTimeThreshold ? true : false);
    }

    public void Update () {
        CacheInput ();
        if (Input.GetButtonDown ("Cancel"))
            Application.Quit ();
    }
}
