View Single Post
07-02-18, 11:57 PM   #1
thomasjohnshannon
A Theradrim Guardian
 
thomasjohnshannon's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 68
New AuraUtil Functions

The following functions got added today (7/2) in a new file called AuraUtil.lua in the FrameXML folder. I haven't had time to test them out but I figured I would post this so other people can check them out.

Lua Code:
  1. AuraUtil = {};
  2.  
  3. local function FindAuraRecurse(predicate, unit, filter, auraIndex, predicateArg1, predicateArg2, predicateArg3, ...)
  4.     if ... == nil then
  5.         return nil; -- Not found
  6.     end
  7.     if predicate(predicateArg1, predicateArg2, predicateArg3, ...) then
  8.         return ...;
  9.     end
  10.     auraIndex = auraIndex + 1;
  11.     return FindAuraRecurse(predicate, unit, filter, auraIndex, predicateArg1, predicateArg2, predicateArg3, UnitAura(unit, auraIndex, filter));
  12. end
  13.  
  14. -- Find an aura by any predicate, you can pass in up to 3 predicate specific parameters
  15. -- The predicate will also receive all aura params, if the aura data matches return true
  16. function AuraUtil.FindAura(predicate, unit, filter, predicateArg1, predicateArg2, predicateArg3)
  17.     local auraIndex = 1;
  18.     return FindAuraRecurse(predicate, unit, filter, auraIndex, predicateArg1, predicateArg2, predicateArg3, UnitAura(unit, auraIndex, filter));
  19. end
  20.  
  21. do
  22.     local function NamePredicate(auraNameToFind, _, _, auraName)
  23.         return auraNameToFind == auraName;
  24.     end
  25.  
  26.     -- Finds the first aura that matches the name
  27.     -- Notes:
  28.     --      aura names are not unique!
  29.     --      aura names are localized, what works in one locale might not work in another
  30.     --          consider that in English two auras might have different names, but once localized they have the same name, so even using the localized aura name in a search it could result in different behavior
  31.     --      the unit could have multiple auras with the same name, this will only find the first
  32.     function AuraUtil.FindAuraByName(auraName, unit, filter)
  33.         return AuraUtil.FindAura(NamePredicate, unit, filter, auraName);
  34.     end
  35. end
__________________
Thomas aka Urnn
  Reply With Quote