#include "../helpers/mathfr.lua"

ANIM_UI = {
    isAnimPlay  = false,
    maxBias     = 0.0,
    curAnimTime = 0.0,
    sign        = 1,
    direction   = false,
    DIRECTIONS = {
        ["horizontal"]  = true,
        ["vertical"]    = false,
    },
}
currentBias = 0

function ANIM_UI:InitAnim(maxBias, maxAnimTime, direction)
    if self.DIRECTIONS[direction] == nil then
        error("Wrong direction for ui slide animation", 1)
    end

    self.direction   = self.DIRECTIONS[direction]
    self.maxBias     = math.abs(maxBias)
    self.sign        = maxBias / self.maxBias
    self.isAnimPlay  = true

    currentBias = 0.0
    SetValue("currentBias", self.maxBias, "easeout", maxAnimTime)
    return self.isAnimPlay
end

function ANIM_UI:ClearAnim()
    self.isAnimPlay = false
    currentBias = self.maxBias
end

function ANIM_UI:Draw(dt)
    if not self.isAnimPlay then return self.isAnimPlay, 0.0, 0.0 end

    if currentBias == self.maxBias then
        self.isAnimPlay = false
        currentBias = self.maxBias
    end
    
    return self.isAnimPlay, currentBias * self.sign
end