Thread Tools Display Modes
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
07-04-18, 10:32 AM   #2
yoshimo
An Aku'mai Servant
Join Date: May 2006
Posts: 30
Mhmm why always rely on the name of an aura instead of a more unique , non localised spellid?
  Reply With Quote
07-09-18, 03:00 AM   #3
Cogwerkz
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2017
Posts: 12
Originally Posted by yoshimo View Post
Mhmm why always rely on the name of an aura instead of a more unique , non localised spellid?
Well it seems to me like the whole purpose of this little file IS to find an aura by name. The rest are just functions that iterate over the currently active auras until they either find it or don't. While if we're looking for an aura by it's spellID, all we have to do is a normal iteration over the active auras and directly compare the values.

I'm not sure why they have added this, no part of the UI uses it yet. But it could be useful if an aura have several versions but the same name, and all we want to know if it's there at all. I wouldn't do it this way, though. Localized strings are just such a bad, bad way to do anything when actual spellIDs exist! The easy way out always comes with its own problems.
  Reply With Quote

WoWInterface » PTR » PTR API and Graphics Changes » New AuraUtil Functions

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off