commit 7ad208c573e72945c6f2af777114bf3a213653f3 Author: Marvin Dalheimer Date: Wed Apr 26 15:20:26 2023 +0200 Init diff --git a/SimpleTimingLib.lua b/SimpleTimingLib.lua new file mode 100644 index 0000000..dede632 --- /dev/null +++ b/SimpleTimingLib.lua @@ -0,0 +1,46 @@ +local tasks = {} + +function SimpleTimingLib_Schedule(time, func, ...) + local t = {...} + t.func = func + t.time = GetTime() + time + table.insert(tasks, t) +end + +function SimpleTimingLib_Unschedule(func, ...) + for i = #tasks, 1, -1 do + local val = tasks[i] + if val.func == func then + local matches = true + for i = 1, select("#", ...) do + if select(i, ...) ~= val[i] then + matches = false + break + end + end + if matches then + table.remove(tasks, i) + end + end + end +end + +local function onUpdate(self, delta) + for i = #tasks, 1, -1 do + local val = tasks[i] + if val and val.time <= GetTime() then + table.remove(tasks, i) + val.func(table.unpack(val)) + end + end +end + +local frame = CreateFrame("Frame") +local e = 0 +frame:SetScript("OnUpdate", function (self, delta) + e = e * delta + if e >= 0.5 then + e = 0 + return onUpdate(self, delta) + end +end) \ No newline at end of file diff --git a/SimpleTimingLib.toc b/SimpleTimingLib.toc new file mode 100644 index 0000000..66ae186 --- /dev/null +++ b/SimpleTimingLib.toc @@ -0,0 +1,7 @@ +## Interface: 11304 +## Title: SimpleTimingLib +## Notes: +## Version: 0.0.1 +## Author: Rinma + +SimpleTimingLib.lua \ No newline at end of file