2 local pairs, ipairs = pairs, ipairs;
3 local floor = math.floor;
4 local GetTime = GetTime;
5 local UnitAura = UnitAura;
6 local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected;
7 local CTimerAfter = C_Timer.After;
9 local Settings = OmaRFSettings;
10 local majorAuras = Settings.MajorAuras;
12 local watchedAuras = {};
16 local auraFilters = {"HELPFUL", "HARMFUL"};
21 local function remaining(text, expires, current)
26 local remain = expires - current;
30 text:SetText(floor(remain+0.5));
35 local function updateIndicators(frame, unit)
36 if not frame:IsShown() or not UnitIsConnected(unit) or UnitIsDeadOrGhost(unit) then
37 updating[frame] = nil;
41 local needUpdate = false;
42 local current = GetTime();
43 for _, pos in pairs(positions) do
44 local ind = frame.inds[pos];
45 if ind.expires ~= nil then
46 needUpdate = remaining(ind.text, ind.expires, current) or needUpdate;
50 local ind = frame.major[i];
51 if ind.expires ~= nil then
52 needUpdate = remaining(ind.text, ind.expires, current) or needUpdate;
56 CTimerAfter(0.16, updaters[frame]);
58 updating[frame] = nil;
62 function M.CheckIndicators(frame, unit)
63 for _, pos in pairs(positions) do
64 frame.inds[pos].expires = nil;
65 frame.inds[pos]:Hide();
66 frame.inds[pos].text:Hide();
69 frame.major[i].expires = nil;
70 frame.major[i]:Hide();
71 frame.major[i].text:Hide();
72 frame.major[i].stack:Hide();
74 local name, icon, count, expires, caster, id;
75 local showInds, showMajors, needUpdate = false, false, false;
77 local current = GetTime();
78 for _, filter in ipairs(auraFilters) do
81 name, _, icon, count, _, _, expires, caster, _, _, id = UnitAura(unit, i, filter);
82 if not id then break end
83 local pos = watchedAuras[id] or watchedAuras[name];
84 if pos and caster == "player" then
85 needUpdate = remaining(frame.inds[pos].text, expires, current);
86 frame.inds[pos].expires = expires;
87 frame.inds[pos]:Show();
88 frame.inds[pos].text:Show();
91 if (majorAuras[id] or majorAuras[name]) and majorPos <= 3 then
92 needUpdate = remaining(frame.major[majorPos].text, expires, current);
93 frame.major[majorPos].expires = expires;
94 frame.major[majorPos]:SetTexture(icon);
95 frame.major[majorPos]:Show();
96 frame.major[majorPos].text:Show();
98 frame.major[majorPos].stack:SetText(count);
99 frame.major[majorPos].stack:Show();
102 majorPos = majorPos + 1;
107 if showInds or showMajors then
110 if needUpdate and not updating[frame] then
111 updating[frame] = true; -- race?
112 -- create a function for updating the indicator
113 local func = updaters[frame];
115 func = function() updateIndicators(frame, unit) end;
116 updaters[frame] = func;
118 CTimerAfter(0.16, func);
126 function M.LoadChar()
127 watchedAuras = Settings.Character["WatchedAuras"];
128 positions = Settings.Character.Positions;