improvement(time): add support for named tweens

This commit is contained in:
Kazhnuz 2021-07-18 09:33:26 +02:00
parent eedf981c54
commit 14e93a2880

View file

@ -39,13 +39,26 @@ function TweenManager:new(subject)
end end
function TweenManager:newTween(start, duration, target, easing) 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 = {} local newTween = {}
-- we add the data into a tween wrapper -- we add the data into a tween wrapper
newTween.tween = tween.new(duration, self.subject, target, easing) newTween.tween = tween.new(duration, self.subject, target, easing)
newTween.start = self.time + start -- /!\ START IS RELATIVE TO CURRENT TIME newTween.start = self.time + start -- /!\ START IS RELATIVE TO CURRENT TIME
newTween.clear = newTween.start + duration newTween.clear = newTween.start + duration
table.insert(self.tweens, newTween) return newTween
end
function TweenManager:removeNamedTween(name)
self.tweens[name] = nil
end end
-- TIMER FUNCTIONS -- TIMER FUNCTIONS
@ -67,6 +80,10 @@ function TweenManager:getTimerInfo(name)
end end
end end
function TweenManager:removeTimer(name)
self.timers[name] = nil
end
-- SWITCH FUNCTIONS -- SWITCH FUNCTIONS
-- Help to handle switches -- Help to handle switches
@ -82,14 +99,19 @@ end
function TweenManager:update(dt) function TweenManager:update(dt)
self.time = self.time + 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 if (self.time > tweenWrapper.start) then
print(key)
tweenWrapper.tween:update(dt) tweenWrapper.tween:update(dt)
if (self.time > tweenWrapper.clear) then
self.tweens[key] = nil
end
end 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 if (self.time > switch.start) then
-- We test each boolean in the switch -- We test each boolean in the switch
for i, bool in ipairs(switch.bools) do for i, bool in ipairs(switch.bools) do