-
Notifications
You must be signed in to change notification settings - Fork 4
/
Util.lua
51 lines (45 loc) · 1.22 KB
/
Util.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
---@class AddonNamespace
local addon = select(2, ...)
local Util = {}
addon.Util = Util
local raidUnits = {
"raid1", "raid2", "raid3", "raid4", "raid5", "raid6", "raid7", "raid8", "raid9", "raid10",
"raid11", "raid12", "raid13", "raid14", "raid15", "raid16", "raid17", "raid18", "raid19", "raid20",
"raid21", "raid22", "raid23", "raid24", "raid25", "raid26", "raid27", "raid28", "raid29", "raid30",
"raid31", "raid32", "raid33", "raid34", "raid35", "raid36", "raid37", "raid38", "raid39", "raid40"
}
local partyUnits = { "player", "party1", "party2", "party3", "party4" }
---@return fun(): string|nil
function Util.IterateGroupMemberNames()
return coroutine.wrap(function()
local units = IsInRaid() and raidUnits or partyUnits
for _, unit in ipairs(units) do
local name = UnitName(unit)
if name and name ~= UNKNOWNOBJECT then
coroutine.yield(name)
end
end
end)
end
---@generic T
---@param t T[]
---@return fun(): T|nil
function Util.IterateTable(t)
local i = 0
return function()
i = i + 1
return t[i]
end
end
---@generic T
---@param value T
---@return fun(): T|nil
function Util.IterateSingleValue(value)
local done = false
return function()
if not done then
done = true
return value
end
end
end