a296877 - Add option to iterate over UnitAura instead of aura list
authorAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Wed, 14 Mar 2018 10:48:06 +0000
committerAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Wed, 14 Mar 2018 10:48:06 +0000
OmaTMW/TellMeWhen.lua

index cb35b0b..155f75c 100644 (file)
@@ -52,7 +52,7 @@ local chars = {
         },
         ["Gedren"] = {
             {
-                totems = {1},
+                totems = {1}, -- Efflorescence
                 x = 570,
                 y = 440,
                 width = 80,
@@ -66,6 +66,7 @@ local chars = {
 -- unit = unitID where to check auras, not required for totem checkers
 -- spec = player spec index to show frame, if nil show always
 -- auras = list of auras to track, in priority order
+-- iterateAuras = iterate over UnitAura() instead of auras list
 -- auraFilter = filter for UnitAura
 -- totems = list of totem slots to track, in priority order, only checked if auras is nil
 -- x = x position relative to UIParent bottom left
@@ -91,6 +92,7 @@ local settings = {
             "Blazing Eruption", "Shattering Scream", "Consuming Hunger", "Unstable Soul",
             "Time Bomb", "Broken Shard",
         },
+        iterateAuras = true, -- typically fewer debuffs on player than this list
         auraFilter = "HARMFUL",
         x = 660,
         y = 530,
@@ -114,24 +116,52 @@ local function updateAuraFrame(frame)
     local unit = frame.unit;
     if UnitExists(unit) and (not frame.spec or frame.spec == currentSpec) then
         local name, icon, count, duration, expires;
-        for _, aura in pairs(frame.auras) do
-            name, _, icon, count, _, duration, expires = UnitAura(unit, aura, nil, frame.auraFilter);
-            if name then
-                if count > 0 then
-                    frame.stack:SetText(count);
-                    frame.stack:Show();
-                else
-                    frame.stack:Hide();
+        local auraFilter = frame.auraFilter;
+        if frame.iterateAuras then
+            local i = 1;
+            while true do
+                name, _, icon, count, _, duration, expires = UnitAura(unit, i, auraFilter);
+                if not name then break end
+                -- possible improvement to add spellID as an option
+                if frame.auras[name] then
+                    if count > 0 then
+                        frame.stack:SetText(count);
+                        frame.stack:Show();
+                    else
+                        frame.stack:Hide();
+                    end
+                    if expires > 0 then
+                        frame.cd:SetCooldown(expires - duration, duration);
+                        frame.cd:Show();
+                    else
+                        frame.cd:Hide();
+                    end
+                    frame.icon:SetTexture(icon);
+                    frame:Show();
+                    return;
                 end
-                if expires > 0 then
-                    frame.cd:SetCooldown(expires - duration, duration);
-                    frame.cd:Show();
-                else
-                    frame.cd:Hide();
+                i = i + 1;
+            end
+        else
+            for _, aura in pairs(frame.auras) do
+                name, _, icon, count, _, duration, expires = UnitAura(unit, aura, nil, auraFilter);
+                if name then
+                    if count > 0 then
+                        frame.stack:SetText(count);
+                        frame.stack:Show();
+                    else
+                        frame.stack:Hide();
+                    end
+                    if expires > 0 then
+                        frame.cd:SetCooldown(expires - duration, duration);
+                        frame.cd:Show();
+                    else
+                        frame.cd:Hide();
+                    end
+                    frame.icon:SetTexture(icon);
+                    frame:Show();
+                    return;
                 end
-                frame.icon:SetTexture(icon);
-                frame:Show();
-                return;
             end
         end
     end
@@ -172,7 +202,15 @@ local function createTMW(name, config, parent)
     frame:SetPoint("BOTTOMRIGHT", parent, "BOTTOMLEFT", config.x+config.width, config.y);
     frame.unit = config.unit;
     frame.spec = config.spec;
-    frame.auras = config.auras;
+    frame.iterateAuras = config.iterateAuras;
+    if frame.iterateAuras then
+        frame.auras = {};
+        for _, v in pairs(config.auras) do
+            frame.auras[v] = true;
+        end
+    else
+        frame.auras = config.auras;
+    end
     frame.auraFilter = config.auraFilter;
     frame.totems = config.totems;
     frame:Hide();