From c397f9d981de4464f4c05c6c19d53093d44bb307 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 22 Aug 2021 17:22:14 +0200 Subject: [PATCH] feat: add TimedFunctions --- .../birb/classes/time/func.lua | 14 +++++++++ .../birb/classes/time/init.lua | 29 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 sonic-radiance.love/birb/classes/time/func.lua diff --git a/sonic-radiance.love/birb/classes/time/func.lua b/sonic-radiance.love/birb/classes/time/func.lua new file mode 100644 index 0000000..3684bf4 --- /dev/null +++ b/sonic-radiance.love/birb/classes/time/func.lua @@ -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 \ No newline at end of file diff --git a/sonic-radiance.love/birb/classes/time/init.lua b/sonic-radiance.love/birb/classes/time/init.lua index 006e83a..ebd4b80 100644 --- a/sonic-radiance.love/birb/classes/time/init.lua +++ b/sonic-radiance.love/birb/classes/time/init.lua @@ -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