forked from oUF-wow/oUF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
private.lua
80 lines (65 loc) · 1.89 KB
/
private.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
72
73
74
75
76
77
78
79
80
local parent, ns = ...
local Private = ns.oUF.Private
function Private.argcheck(value, num, ...)
assert(type(num) == 'number', "Bad argument #2 to 'argcheck' (number expected, got " .. type(num) .. ')')
for i = 1, select('#', ...) do
if(type(value) == select(i, ...)) then return end
end
local types = strjoin(', ', ...)
local name = debugstack(2,2,0):match(": in function [`<](.-)['>]")
error(string.format("Bad argument #%d to '%s' (%s expected, got %s)", num, name, types, type(value)), 3)
end
function Private.print(...)
print('|cff33ff99oUF:|r', ...)
end
function Private.error(...)
Private.print('|cffff0000Error:|r ' .. string.format(...))
end
function Private.unitExists(unit)
return unit and (UnitExists(unit) or ShowBossFrameWhenUninteractable(unit))
end
local validator = CreateFrame('Frame')
function Private.validateUnit(unit)
local isOK, _ = pcall(validator.RegisterUnitEvent, validator, 'UNIT_HEALTH', unit)
if(isOK) then
_, unit = validator:IsEventRegistered('UNIT_HEALTH')
validator:UnregisterEvent('UNIT_HEALTH')
return not not unit
end
end
local selectionTypes = {
[ 0] = 0,
[ 1] = 1,
[ 2] = 2,
[ 3] = 3,
[ 4] = 4,
[ 5] = 5,
[ 6] = 6,
[ 7] = 7,
[ 8] = 8,
[ 9] = 9,
-- [10] = 10, -- unavailable to players
-- [11] = 11, -- unavailable to players
-- [12] = 12, -- inconsistent due to bugs and its reliance on cvars
[13] = 13,
}
function Private.unitSelectionType(unit, considerHostile)
if(considerHostile and UnitThreatSituation('player', unit)) then
return 0
else
return selectionTypes[UnitSelectionType(unit, true)]
end
end
local function errorHandler(...)
return geterrorhandler()(...)
end
function Private.xpcall(func, ...)
return xpcall(func, errorHandler, ...)
end
function Private.validateEvent(event)
local isOK = xpcall(validator.RegisterEvent, errorHandler, validator, event)
if(isOK) then
validator:UnregisterEvent(event)
end
return isOK
end