-
Notifications
You must be signed in to change notification settings - Fork 58
/
factory.lua
71 lines (56 loc) · 1.57 KB
/
factory.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 _, ns = ...
local oUF = ns.oUF
local Private = oUF.Private
local argcheck = Private.argcheck
local queue = {}
local factory = CreateFrame('Frame')
factory:SetScript('OnEvent', function(self, event, ...)
return self[event](self, event, ...)
end)
factory:RegisterEvent('PLAYER_LOGIN')
factory.active = true
function factory:PLAYER_LOGIN()
if(not self.active) then return end
for _, func in next, queue do
func(oUF)
end
-- Avoid creating dupes.
table.wipe(queue)
end
--[[ Factory: oUF:Factory(func)
Used to call a function directly if the current character is logged in and the factory is active. Else the function is
queued up to be executed at a later time (upon PLAYER_LOGIN by default).
* self - the global oUF object
* func - function to be executed or delayed (function)
--]]
function oUF:Factory(func)
argcheck(func, 2, 'function')
-- Call the function directly if we're active and logged in.
if(IsLoggedIn() and factory.active) then
return func(self)
else
table.insert(queue, func)
end
end
--[[ Factory: oUF:EnableFactory()
Used to enable the factory.
* self - the global oUF object
--]]
function oUF:EnableFactory()
factory.active = true
end
--[[ Factory: oUF:DisableFactory()
Used to disable the factory.
* self - the global oUF object
--]]
function oUF:DisableFactory()
factory.active = nil
end
--[[ Factory: oUF:RunFactoryQueue()
Used to try to execute queued up functions. The current player must be logged in and the factory must be active for
this to succeed.
* self - the global oUF object
--]]
function oUF:RunFactoryQueue()
factory:PLAYER_LOGIN()
end