-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.lua
More file actions
166 lines (148 loc) · 4.77 KB
/
Utils.lua
File metadata and controls
166 lines (148 loc) · 4.77 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
local ADDON_NAME, addon = ...
addon.PlayerName = UnitName('player')
addon.PlayerClass = select(2, UnitClass('player'))
addon.PlayerNameRealm = addon.PlayerName .. '-' .. GetRealmName():gsub("%s+", "")
function addon.GetNormalizedRealmName()
local result = GetNormalizedRealmName()
if not result then
result = GetRealmName()
result = result:gsub("%s+", "")
result = result:gsub("%-", "")
end
return result
end
function addon.Console(...)
print(WrapTextInColorCode('[' .. ADDON_NAME .. ']', 'fff5e4a8'), ...)
end
function addon.PrintDebug(...)
if addon.Debug then
addon.Console(WrapTextInColorCode('D', 'C1E1C1FF'), ...)
end
end
function addon.DebugTableToString(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. addon.DebugTableToString(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
function addon.REVERSE(k1, k2)
return k2 < k1
end
function addon.PairsByKeys(t, f)
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a, f)
local i = 0
local iter = function ()
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end
function addon.IterateRoster(_, index)
index = (index or 0) + 1
if IsInRaid() then
if index > 40 then
return
end
local name, rank, _, level, class, fileName, zone, online, isDead, role, isML, combatRole = GetRaidRosterInfo(index)
if name == nil then
return addon.IterateRoster(_, index)
end
local guid = UnitGUID('raid'..index)
local namePart, realmPart = UnitFullName('raid'..index)
realmPart = realmPart or addon.GetNormalizedRealmName()
return index, name, fileName, guid, rank, level, online, isDead, combatRole, namePart .. '-' .. realmPart
else
local name, rank, subgroup, level, class, fileName, online, isDead, combatRole, _, nameWithRealm
local unit = index == 1 and 'player' or 'party'..(index-1)
local guid = UnitGUID(unit)
if not guid then
return
end
subgroup = 1
name, _ = UnitName(unit)
if _ then
name = name .. '-' .. _
nameWithRealm = name
else
nameWithRealm = name .. '-' .. addon.GetNormalizedRealmName()
end
class, fileName = UnitClass(unit)
if UnitIsGroupLeader(unit) then
rank = 2
else
rank = 0
end
level = UnitLevel(unit)
if UnitIsConnected(unit) then
online = true
end
if UnitIsDeadOrGhost(unit) then
isDead = true
end
combatRole = UnitGroupRolesAssigned(unit)
return index, name, fileName, guid, rank, level, online, isDead, combatRole, nameWithRealm
end
end
function addon.IterateGuildRoster(_, index)
index = (index or 0) + 1
if not IsInGuild() then
return
end
if index > GetNumGuildMembers() then
return
end
local nameWithRealm, rankName, rankIndex, level, classDisplayName, zone, publicNote,
officerNote, isOnline, status, class, achievementPoints, achievementRank, isMobile,
canSoR, repStanding, guid = GetGuildRosterInfo(index)
if not nameWithRealm then
return
end
local shortName = Ambiguate(nameWithRealm, 'guild')
local canSpeakInOfficerChat = C_GuildInfo.GuildControlGetRankFlags(rankIndex + 1)[4]
return index, shortName, class, guid, rankIndex + 1, level, isOnline, nameWithRealm, canSpeakInOfficerChat
end
function addon.GetWeakAuras()
if not WeakAurasSaved then
return {}
end
local wa = {}
for waName, waData in pairs(WeakAurasSaved.displays) do
wa[waName] = waData
end
return wa
end
function addon.GetAddons()
local addons = {}
for i = 1, C_AddOns.GetNumAddOns() do
local name, title, _, _, notLoadableReason, _, _ = C_AddOns.GetAddOnInfo(i)
addons[name] = {
name = name,
title = title,
version = C_AddOns.GetAddOnMetadata(name, 'Version') or '',
notLoadableReason = notLoadableReason,
}
end
return addons
end
function addon.IsRaidLead()
return (IsInRaid() and (UnitIsGroupAssistant('player') or UnitIsGroupLeader('player')))
end
function addon.IsPartyLead()
return (IsInGroup() and (UnitIsGroupAssistant('player') or UnitIsGroupLeader('player')))
end
function addon.IsOfficer()
return C_GuildInfo.IsGuildOfficer()
end
function addon.GetGroupRank()
return UnitIsGroupLeader('player') and 2 or UnitIsGroupAssistant('player') and 1 or 0
end