forked from Mapkov2/Midnight-Simple-Auras
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSA_BuffBridge.lua
More file actions
218 lines (186 loc) · 6.77 KB
/
MSA_BuffBridge.lua
File metadata and controls
218 lines (186 loc) · 6.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
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
-- ########################################################
-- MSA_BuffBridge.lua
-- Bridge between PlayerBuffs engine and UpdateEngine
--
-- Provides the functions that the UpdateEngine hot-path
-- calls to decide how to display an aura-type icon:
-- * Active buff -> normal icon with timer
-- * Absent buff (showWhenAbsent) -> desaturated / dimmed
-- * Absent buff (!showWhenAbsent) -> hidden
--
-- Secret-safe: no value comparisons, pcall on all API.
-- Zero idle CPU: only called when UpdateEngine is active.
-- ########################################################
local MSWA = _G.MSWA
if type(MSWA) ~= "table" then return end
local type, tonumber, pcall = type, tonumber, pcall
local GetTime = GetTime
-----------------------------------------------------------
-- Determine if a tracked key is an "aura" type
-- (vs traditional cooldown tracking)
-----------------------------------------------------------
function MSWA_IsAuraType(key)
if not key then return false end
local db = MSWA_GetDB and MSWA_GetDB()
if not db then return false end
local s = db.spellSettings and db.spellSettings[key]
if not s then return false end
return s.trackType == "aura"
end
-----------------------------------------------------------
-- Get display data for an aura-type icon
-- Returns a table suitable for the UpdateEngine icon loop:
-- show, icon, remaining, duration, stacks, alpha, desat
-----------------------------------------------------------
function MSWA_GetAuraDisplayData(key)
if not key then
return false, nil, 0, 0, 0, 1, false
end
local db = MSWA_GetDB and MSWA_GetDB()
if not db then
return false, nil, 0, 0, 0, 1, false
end
local s = db.spellSettings and db.spellSettings[key]
if not s or s.trackType ~= "aura" then
return false, nil, 0, 0, 0, 1, false
end
local active, remaining, duration, stacks, buffIcon
if MSWA_GetBuffData then
active, remaining, duration, stacks, buffIcon = MSWA_GetBuffData(key)
else
active = false
remaining = 0
duration = 0
stacks = 0
end
-- Resolve icon: buff icon > spell texture > override
local icon = buffIcon
if not icon and s.auraSpellID then
icon = MSWA_GetSpellIconSafe and MSWA_GetSpellIconSafe(s.auraSpellID)
end
if s.iconOverride then
icon = s.iconOverride
end
if active then
return true, icon, remaining, duration, stacks, 1.0, false
else
-- Not active
if s.showWhenAbsent then
local alpha = tonumber(s.alphaOnAbsent) or 0.45
local desat = (s.desaturateOnAbsent ~= false) -- default true for absent
return true, icon, 0, 0, 0, alpha, desat
else
return false, icon, 0, 0, 0, 1, false
end
end
end
-----------------------------------------------------------
-- Apply absent visual styling to an icon button
-- Called by the icon rendering loop when show=true but
-- the buff is not active.
-----------------------------------------------------------
function MSWA_ApplyAbsentStyle(btn, alpha, desaturate)
if not btn then return end
-- Alpha
local a = tonumber(alpha) or 0.45
if a < 0 then a = 0 end
if a > 1 then a = 1 end
btn:SetAlpha(a)
-- Desaturation
if desaturate then
local tex = btn.icon or btn.Icon
if tex and tex.SetDesaturated then
pcall(tex.SetDesaturated, tex, true)
end
-- Also desaturate cooldown overlay if present
local cd = btn.cooldown or btn.Cooldown
if cd and cd.SetDesaturated then
pcall(cd.SetDesaturated, cd, true)
end
end
end
-----------------------------------------------------------
-- Remove absent visual styling (buff became active)
-----------------------------------------------------------
function MSWA_ClearAbsentStyle(btn)
if not btn then return end
btn:SetAlpha(1)
local tex = btn.icon or btn.Icon
if tex and tex.SetDesaturated then
pcall(tex.SetDesaturated, tex, false)
end
local cd = btn.cooldown or btn.Cooldown
if cd and cd.SetDesaturated then
pcall(cd.SetDesaturated, cd, false)
end
end
-----------------------------------------------------------
-- Icon tooltip for aura-type entries
-- Adds the buff spell ID + source info to the tooltip
-----------------------------------------------------------
function MSWA_SetAuraTooltip(tooltip, key)
if not tooltip or not key then return end
local db = MSWA_GetDB and MSWA_GetDB()
if not db then return end
local s = db.spellSettings and db.spellSettings[key]
if not s or s.trackType ~= "aura" then return end
local spellID = s.auraSpellID
if spellID then
tooltip:AddLine(" ")
tooltip:AddLine(("Tracked Buff ID: |cffffffff%d|r"):format(spellID), 0.5, 0.8, 1)
end
local buff = MSWA._activeBuffs and MSWA._activeBuffs[key]
if buff then
if buff.active then
tooltip:AddLine("|cff00ff00Active|r", 0.5, 1, 0.5)
if buff.stacks and buff.stacks > 0 then
tooltip:AddLine(("Stacks: |cffffffff%d|r"):format(buff.stacks), 0.7, 0.7, 0.7)
end
else
tooltip:AddLine("|cffff4444Absent|r", 1, 0.3, 0.3)
end
end
end
-----------------------------------------------------------
-- Ensure buff watches are registered when aura-type
-- entries are first enabled or settings change
-----------------------------------------------------------
function MSWA_EnsureBuffWatch(key)
if not key then return end
local db = MSWA_GetDB and MSWA_GetDB()
if not db then return end
local s = db.spellSettings and db.spellSettings[key]
if not s or s.trackType ~= "aura" then return end
if not s.auraSpellID then return end
if MSWA_RegisterBuffWatch then
MSWA_RegisterBuffWatch(
key,
s.auraSpellID,
s.auraUnit or "player",
s.auraFilter or "HELPFUL"
)
end
end
-----------------------------------------------------------
-- Count active buffs in a group (for group header display)
-----------------------------------------------------------
function MSWA_CountActiveBuffsInGroup(gid)
if not gid then return 0, 0 end
local db = MSWA_GetDB and MSWA_GetDB()
if not db or not db.auraGroups then return 0, 0 end
local total = 0
local active = 0
for key, g in pairs(db.auraGroups) do
if g == gid then
local s = db.spellSettings and db.spellSettings[key]
if s and s.trackType == "aura" then
total = total + 1
local buff = MSWA._activeBuffs and MSWA._activeBuffs[key]
if buff and buff.active then
active = active + 1
end
end
end
end
return active, total
end