-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMSA_LoadConditions.lua
More file actions
220 lines (192 loc) · 7.99 KB
/
MSA_LoadConditions.lua
File metadata and controls
220 lines (192 loc) · 7.99 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
-- ########################################################
-- MSA_LoadConditions.lua
-- Centralized load-condition evaluation + class/spec data
--
-- v3: ShouldLoadAura accepts (s, inCombat, inEncounter) to
-- avoid calling InCombatLockdown/IsEncounterInProgress
-- per icon. Caller caches once per update frame.
-- ########################################################
local type, tostring, tonumber = type, tostring, tonumber
local pcall = pcall
-----------------------------------------------------------
-- Player identity cache (computed once, never changes)
-----------------------------------------------------------
local playerName
local playerRealm
local playerFullName
local playerClassToken
local playerSpecIndex
function MSWA_RefreshPlayerIdentity()
playerName = UnitName("player") or ""
playerRealm = ""
if GetNormalizedRealmName then
playerRealm = GetNormalizedRealmName() or ""
elseif GetRealmName then
playerRealm = (GetRealmName() or ""):gsub("%s+", "")
end
playerRealm = tostring(playerRealm):gsub("%s+", "")
if playerRealm ~= "" then
playerFullName = (playerName .. "-" .. playerRealm):lower()
else
playerFullName = playerName:lower()
end
local _, classToken = UnitClass("player")
playerClassToken = classToken or "UNKNOWN"
if GetSpecialization then
playerSpecIndex = GetSpecialization() or 0
else
playerSpecIndex = 0
end
end
function MSWA_GetPlayerFullName() return playerFullName end
function MSWA_GetPlayerRealm() return playerRealm end
function MSWA_GetPlayerName() return playerName end
function MSWA_GetPlayerClassToken() return playerClassToken end
function MSWA_GetPlayerSpecIndex() return playerSpecIndex end
-----------------------------------------------------------
-- Class / Spec data (unchanged)
-----------------------------------------------------------
MSWA_CLASS_LIST = {
{ token = "WARRIOR", name = "Warrior", color = "C69B6D" },
{ token = "PALADIN", name = "Paladin", color = "F48CBA" },
{ token = "HUNTER", name = "Hunter", color = "AAD372" },
{ token = "ROGUE", name = "Rogue", color = "FFF468" },
{ token = "PRIEST", name = "Priest", color = "FFFFFF" },
{ token = "DEATHKNIGHT", name = "Death Knight", color = "C41E3A" },
{ token = "SHAMAN", name = "Shaman", color = "0070DD" },
{ token = "MAGE", name = "Mage", color = "3FC7EB" },
{ token = "WARLOCK", name = "Warlock", color = "8788EE" },
{ token = "MONK", name = "Monk", color = "00FF98" },
{ token = "DRUID", name = "Druid", color = "FF7C0A" },
{ token = "DEMONHUNTER", name = "Demon Hunter", color = "A330C9" },
{ token = "EVOKER", name = "Evoker", color = "33937F" },
}
MSWA_CLASS_INFO = {}
for _, c in ipairs(MSWA_CLASS_LIST) do
MSWA_CLASS_INFO[c.token] = c
end
MSWA_SPEC_DATA = {
WARRIOR = { "Arms", "Fury", "Protection" },
PALADIN = { "Holy", "Protection", "Retribution" },
HUNTER = { "Beast Mastery", "Marksmanship", "Survival" },
ROGUE = { "Assassination", "Outlaw", "Subtlety" },
PRIEST = { "Discipline", "Holy", "Shadow" },
DEATHKNIGHT = { "Blood", "Frost", "Unholy" },
SHAMAN = { "Elemental", "Enhancement", "Restoration" },
MAGE = { "Arcane", "Fire", "Frost" },
WARLOCK = { "Affliction", "Demonology", "Destruction" },
MONK = { "Brewmaster", "Mistweaver", "Windwalker" },
DRUID = { "Balance", "Feral", "Guardian", "Restoration" },
DEMONHUNTER = { "Havoc", "Vengeance" },
EVOKER = { "Devastation", "Preservation", "Augmentation" },
}
function MSWA_GetSpecName(classToken, specIdx)
local specs = classToken and MSWA_SPEC_DATA[classToken]
if specs and specIdx and specIdx >= 1 and specIdx <= #specs then
return specs[specIdx]
end
return nil
end
-----------------------------------------------------------
-- NormalizeCharName (local, called rarely)
-----------------------------------------------------------
local function NormalizeCharName(raw)
if type(raw) ~= "string" then return nil end
local s = raw:gsub("^%s+", ""):gsub("%s+$", ""):gsub("%s", "")
if s == "" then return nil end
if not s:find("%-") then
if playerRealm and playerRealm ~= "" then
s = s .. "-" .. playerRealm
end
end
return s:lower()
end
-----------------------------------------------------------
-- MSWA_ShouldLoadAura(settings, inCombat, inEncounter)
--
-- inCombat / inEncounter: OPTIONAL. If nil, calls API.
-- Hot path should pass cached values to avoid per-icon API calls.
-----------------------------------------------------------
function MSWA_ShouldLoadAura(s, inCombat, inEncounter)
if not s then return true end
-- Never
if s.loadNever == true or s.loadMode == "NEVER" then
return false
end
-- Character filter
local wantChar = s.loadCharName or s.loadChar
if wantChar and wantChar ~= "" then
if not playerFullName then MSWA_RefreshPlayerIdentity() end
local normalized = NormalizeCharName(wantChar)
if normalized and normalized ~= playerFullName then
return false
end
end
-- Class filter
local wantClass = s.loadClass
if wantClass and wantClass ~= "" then
if not playerClassToken then MSWA_RefreshPlayerIdentity() end
if wantClass ~= playerClassToken then
return false
end
end
-- Spec filter
local wantSpec = s.loadSpec
if wantSpec then
wantSpec = tonumber(wantSpec)
if wantSpec and wantSpec > 0 then
if not playerSpecIndex then MSWA_RefreshPlayerIdentity() end
if wantSpec ~= playerSpecIndex then
return false
end
end
end
-- Combat filter (use cached value if provided)
if inCombat == nil then
inCombat = InCombatLockdown and InCombatLockdown() and true or false
end
local cm = s.loadCombatMode
if cm == "IN" then
if not inCombat then return false end
elseif cm == "OUT" then
if inCombat then return false end
end
if not cm then
if s.loadMode == "IN_COMBAT" and not inCombat then return false end
if s.loadMode == "OUT_OF_COMBAT" and inCombat then return false end
end
-- Encounter filter (use cached value if provided)
if inEncounter == nil then
inEncounter = IsEncounterInProgress and IsEncounterInProgress() and true or false
end
local em = s.loadEncounterMode
if em == "IN" then
if not inEncounter then return false end
elseif em == "OUT" then
if inEncounter then return false end
end
return true
end
-----------------------------------------------------------
-- Event frame: refresh identity on login + spec change
-----------------------------------------------------------
local identityFrame = CreateFrame("Frame")
identityFrame:RegisterEvent("PLAYER_LOGIN")
identityFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
if identityFrame.RegisterEvent then
pcall(identityFrame.RegisterEvent, identityFrame, "ACTIVE_TALENT_GROUP_CHANGED")
pcall(identityFrame.RegisterEvent, identityFrame, "PLAYER_SPECIALIZATION_CHANGED")
pcall(identityFrame.RegisterEvent, identityFrame, "PLAYER_TALENT_UPDATE")
end
identityFrame:SetScript("OnEvent", function(self, event)
MSWA_RefreshPlayerIdentity()
if event == "ACTIVE_TALENT_GROUP_CHANGED"
or event == "PLAYER_SPECIALIZATION_CHANGED"
or event == "PLAYER_TALENT_UPDATE" then
if MSWA_RequestUpdateSpells then MSWA_RequestUpdateSpells() end
if MSWA_RefreshOptionsList and MSWA and MSWA.optionsFrame
and MSWA.optionsFrame:IsShown() then
MSWA_RefreshOptionsList()
end
end
end)