feat: add TimedFunctions

This commit is contained in:
Kazhnuz 2021-08-22 17:22:14 +02:00
parent 39d11596f0
commit c397f9d981
2 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,14 @@
local Timer = require "birb.classes.time.timer"
local TimedFunction = Timer:extend()
function TimedFunction:new(actor, name, func, t)
TimedFunction.super.new(self, actor, name, t)
self.func = func
end
function TimedFunction:finish()
self.actor.funcs[self.name] = nil
self.func()
end
return TimedFunction

View file

@ -27,6 +27,7 @@ local TweenManager = Object:extend()
local tween = require "birb.libs.tween"
local Timer = require "birb.classes.time.timer"
local TimedFunction = require "birb.classes.time.func"
function TweenManager:new(subject)
self.subject = subject
@ -36,6 +37,7 @@ function TweenManager:new(subject)
self.switches = {}
self.timers = {}
self.funcs = {}
end
function TweenManager:newTween(start, duration, target, easing)
@ -84,6 +86,29 @@ function TweenManager:removeTimer(name)
self.timers[name] = nil
end
-- FUNCTION FUNCTIONS
-- Help to get functions
function TweenManager:newFunc(start, name, func)
self.funcs[name] = TimedFunction(self, name, func, start)
end
function TweenManager:delayFunc(time, name, absolute)
if (self.funcs[name] ~= nil) then
self.funcs[name]:delay(time, absolute)
end
end
function TweenManager:getFuncInfo(name)
if (self.funcs[name] ~= nil) then
return self.funcs[name]:getInfo()
end
end
function TweenManager:removeFunc(name)
self.funcs[name] = nil
end
-- SWITCH FUNCTIONS
-- Help to handle switches
@ -129,6 +154,10 @@ function TweenManager:update(dt)
timer:update(dt)
end
for k, func in pairs(self.funcs) do
func:update(dt)
end
self:clearEndedTweens()
end