--- Умеет асинхронно ждать какое-то время (для анимаций)
--- @class ResidentSleeperBehavior : Behavior
--- @field animationNode? AnimationNode
--- @field endsAt? number
local behavior = {}
behavior.__index = behavior
behavior.id = "residentsleeper"

function behavior.new() return setmetatable({}, behavior) end

function behavior:update(dt)
    if not self.animationNode then return end
    if love.timer.getTime() >= self.endsAt then
        self.animationNode:finish()
        self.animationNode = nil
        self.endsAt = nil
    end
end

--- @param ms number time to wait in milliseconds
--- @param node AnimationNode
function behavior:sleep(ms, node)
    if self.animationNode then node:finish() end
    self.animationNode = node
    self.endsAt = love.timer.getTime() + ms / 1000
end

return behavior
