This commit is contained in:
Marvin Dalheimer 2023-04-26 15:20:26 +02:00
commit 7ad208c573
2 changed files with 53 additions and 0 deletions

46
SimpleTimingLib.lua Normal file
View File

@ -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)

7
SimpleTimingLib.toc Normal file
View File

@ -0,0 +1,7 @@
## Interface: 11304
## Title: SimpleTimingLib
## Notes:
## Version: 0.0.1
## Author: Rinma
SimpleTimingLib.lua