-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheSLS_timer.lua
71 lines (53 loc) · 1.59 KB
/
eSLS_timer.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local tasks = {}
----------------------------------------------------------------
local function sortTasks(t1, t2)
return t1.time > t2.time
end
----------------------------------------------------------------
local function onUpdate(self, elapsed)
for i = #tasks, 1, -1 do
local t = tasks[i]
if t and t.time <= GetTime() then
table.remove(tasks, i)
t.func(unpack(t))
end
end
end
----------------------------------------------------------------
function eSLS:Timer_schedule(time, func, ...)
local t = {...}
t.func = func
t.time = GetTime() + time
table.insert(tasks, t)
--table.sort(tasks, sortTasks)
end
----------------------------------------------------------------
function eSLS:Timer_unschedule(func, ...)
local remaining = {}
for i = #tasks, 1, -1 do
local t = tasks[i]
if func and t.func and t.func == func then
local matches = true
for i = 1, select("#", ...) do
if select(i, ...) ~= t[i] then
matches = false
break
end
end
if matches then
table.insert(remaining, GetTime() - t.time)
table.remove(tasks, i)
end
end
end
return remaining
end
----------------------------------------------------------------
local e = 0
eSLS:SetScript("OnUpdate", function(self, elapsed)
e = e + elapsed
if e > 1 then
e = 0
return onUpdate(self, elapsed)
end
end)