feat: add ways to get info from timers

This commit is contained in:
Kazhnuz 2021-04-25 09:22:40 +02:00
parent e4741bdc90
commit 18a86c3a0a
2 changed files with 33 additions and 0 deletions

View file

@ -24,6 +24,7 @@
local Timer = Object:extend()
function Timer:new(actor, name, t)
self.baseTime = t
self.time = t
self.actor = actor
self.name = name
@ -36,6 +37,20 @@ function Timer:update(dt)
end
end
function Timer:delay(time, absolute)
if (absolute == true) then
self.baseTime = self.baseTime + (time - self.time)
self.time = time
else
self.baseTime = self.baseTime + time
self.time = self.time + time
end
end
function Timer:getInfo()
return self.time, self.baseTime, (self.time / self.baseTime)
end
function Timer:finish()
self.actor:timerResponse(self.name)
self.actor.timers[self.name] = nil

View file

@ -23,10 +23,28 @@ function TweenManager:newTween(start, duration, target, easing)
table.insert(self.tweens, newTween)
end
-- TIMER FUNCTIONS
-- Help to get info from timers
function TweenManager:newTimer(start, name)
self.timers[name] = Timer(self, name, start)
end
function TweenManager:delayTimer(time, name, absolute)
if (self.timers[name] ~= nil) then
self.timers[name]:delay(time, absolute)
end
end
function TweenManager:getTimerInfo(name)
if (self.timers[name] ~= nil) then
self.timers[name]:getInfo()
end
end
-- SWITCH FUNCTIONS
-- Help to handle switches
function TweenManager:newSwitch(start, bools)
local newSwitch = {}
-- we add the data into a tween wrapper