-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEvents.lua
70 lines (52 loc) · 1.16 KB
/
Events.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
-- Event
local Event;
do
-- imports
-- private
-- ctor
-- main
end
-- kEvents
do
-- imports
local Frame = kWidgets.Frame;
-- private
local frame = Frame();
local timerPool = { };
-- public
local RegisterEvent = function( event, handler )
assert( type( event ) == "string", "Event must be string" );
assert( type( handler ) == "function", "Handler must be function" );
return frame:RegisterEvent( event, handler );
end
local UnregisterEvent = function( eventObject )
frame:UnregisterEvent( eventObject );
end
local RegisterTimer = function ( time, func )
local count = #timerPool;
local frame;
if (count <= 0) then
frame = CreateFrame("frame");
else
frame = timerPool[count];
timerPool[count] = nil;
end
local total = 0
local function onUpdate(self, elapsed)
total = total + elapsed
if total >= time then
frame:SetScript("OnUpdate", nil);
tinsert(timerPool, frame);
func();
end
end
frame:SetScript("OnUpdate", onUpdate);
end
-- main
kEvents = {
Event = Event,
RegisterEvent = RegisterEvent,
UnregisterEvent = UnregisterEvent,
RegisterTimer = RegisterTimer
};
end