package me.hammerle.supersnuvi.javafx;

public class KeyBinding implements IKeyBinding
{
    private boolean isDown;
    private boolean justReleased;
    private int downTime;
    
    public KeyBinding()
    {
        downTime = 0;
        justReleased = false;
    }
    
    public void press()
    {
        isDown = true;
    }
    
    public void release()
    {
        isDown = false;
    }
    
    public void tick()
    {   
        if(isDown)
        {
            downTime++;
        }
        else if(justReleased)
        {
            downTime = 0;
            justReleased = false;
        }
        else if(downTime > 0)
        {
            justReleased = true;
        }
    }
    
    @Override
    public boolean isDown()
    {
        return downTime > 0;
    }

    @Override
    public int getDownTime() 
    {
        return downTime;
    }

    @Override
    public boolean wasJustReleased() 
    {
        return justReleased;
    }
    
    @Override
    public void resetTime() 
    {
        downTime = 0;
    }
}
