From 14e93a2880f9d552a8e613bc709c1877ac3535ee Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 18 Jul 2021 09:33:26 +0200 Subject: [PATCH] improvement(time): add support for named tweens --- .../birb/classes/time/init.lua | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/birb/classes/time/init.lua b/sonic-radiance.love/birb/classes/time/init.lua index c5e29df..773c71e 100644 --- a/sonic-radiance.love/birb/classes/time/init.lua +++ b/sonic-radiance.love/birb/classes/time/init.lua @@ -39,13 +39,26 @@ function TweenManager:new(subject) end function TweenManager:newTween(start, duration, target, easing) + table.insert(self.tweens, self:createTween(start, duration, target, easing)) +end + +function TweenManager:setNamedTween(name, start, duration, target, easing) + self.tweens[name] = nil + self.tweens[name] = self:createTween(start, duration, target, easing) +end + +function TweenManager:createTween(start, duration, target, easing) local newTween = {} -- we add the data into a tween wrapper newTween.tween = tween.new(duration, self.subject, target, easing) newTween.start = self.time + start -- /!\ START IS RELATIVE TO CURRENT TIME newTween.clear = newTween.start + duration - table.insert(self.tweens, newTween) + return newTween +end + +function TweenManager:removeNamedTween(name) + self.tweens[name] = nil end -- TIMER FUNCTIONS @@ -67,6 +80,10 @@ function TweenManager:getTimerInfo(name) end end +function TweenManager:removeTimer(name) + self.timers[name] = nil +end + -- SWITCH FUNCTIONS -- Help to handle switches @@ -82,14 +99,19 @@ end function TweenManager:update(dt) self.time = self.time + dt + print("tweens") - for i, tweenWrapper in ipairs(self.tweens) do + for key, tweenWrapper in pairs(self.tweens) do if (self.time > tweenWrapper.start) then + print(key) tweenWrapper.tween:update(dt) + if (self.time > tweenWrapper.clear) then + self.tweens[key] = nil + end end end - for i, switch in ipairs(self.switches) do + for i, switch in pairs(self.switches) do if (self.time > switch.start) then -- We test each boolean in the switch for i, bool in ipairs(switch.bools) do