WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   PTR API and Graphics Changes (https://www.wowinterface.com/forums/forumdisplay.php?f=175)
-   -   New AuraUtil Functions (https://www.wowinterface.com/forums/showthread.php?t=56332)

thomasjohnshannon 07-02-18 11:57 PM

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

yoshimo 07-04-18 10:32 AM

Mhmm why always rely on the name of an aura instead of a more unique , non localised spellid?

Cogwerkz 07-09-18 03:00 AM

Quote:

Originally Posted by yoshimo (Post 328540)
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.


All times are GMT -6. The time now is 02:17 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI