Quantcast WoWInterface - View Single Post - Wraper functions for 8.0.1 spell/aura changes
View Single Post
04-29-18, 05:54 AM   #1
Edik
A Murloc Raider
 
Edik's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 5
Wraper functions for 8.0.1 spell/aura changes

I have set of functions to wrap changes without no need to modify old code for transcending period in addon development. It allows still use code in 7.3 and 8.x. Just replace P. with your add-on name and then inlude at start of your code:

Lua Code:
  1. local GetSpellInfo = P.GetSpellInfo; assert(GetSpellInfo ~= nil,'GetSpellInfo')

If you want to use GetSpellInfo without need to worry about client version. Here are wrappers

Lua Code:
  1. -- LINT frinedly declaration
  2. local GetBuildInfo = _G.GetBuildInfo; assert(GetBuildInfo ~= nil,'GetBuildInfo')
  3. -- transience 7.x na 8.x
  4. local _, _, _, tocVersion = GetBuildInfo() -- resolve version
  5. -- wrappers
  6. function P.UnitChannelInfo(unit) -- 7.x to 8.x transience 2nd return value removed
  7.   if tocVersion < 80000 then return _G.UnitChannelInfo(unit) end
  8.   local retTable = {_G.UnitChannelInfo(unit)}
  9.   if retTable[1] then table.insert(retTable,2,'') end
  10.   return unpack(retTable)
  11. end
  12. function P.UnitCastingInfo(...) -- 7.x to 8.x transience 2nd return value removed
  13.   if tocVersion < 80000 then return _G.UnitCastingInfo(...) end
  14.   local retTable = {_G.UnitCastingInfo(...)}
  15.   if retTable[1] then table.insert(retTable,2,'') end
  16.   return unpack(retTable)
  17. end
  18. function P.GetSpellInfo(...) -- 7.x to 8.x transience 2nd return value replaced with nil
  19.   if tocVersion < 80000 then return _G.GetSpellInfo(...) end
  20.   local retTable = {_G.GetSpellInfo(...)}
  21.   if retTable[1] then retTable[2] = '' end
  22.   return unpack(retTable)
  23. end
  24. function P.GetMacroSpell(...) -- 7.x to 8.x transience 1st and 2nd return value removed
  25.   if (tocVersion < 80000) then return _G.GetMacroSpell(...) end
  26.   local retTable = {_G.GetMacroSpell(...)}
  27.   if retTable[1] then
  28.     local name = _G.GetSpellInfo(retTable[1])
  29.     if name then
  30.       table.insert(retTable,1,'')
  31.       table.insert(retTable,1,name)
  32.     end
  33.   end
  34.   return unpack(retTable)
  35. end
  36. function P.GetPetActionInfo(...) -- 7.x to 8.x transience 2nd return value removed
  37.   if (tocVersion < 80000) then return _G.GetPetActionInfo(...) end
  38.   local retTable = {_G.GetPetActionInfo(...)}
  39.   if retTable[1] then table.insert(retTable,2,'') end
  40.   return unpack(retTable)
  41. end
  42. function P.GetPossessInfo(...) -- 7.x to 8.x transience 2nd return value changed from spell name to spell ID.
  43.   if (tocVersion < 80000) then return _G.GetPossessInfo(...) end
  44.   local retTable = {_G.GetPossessInfo(...)}
  45.   if retTable[2] then
  46.     local name = _G.GetSpellInfo(retTable[2])
  47.     retTable[2] = name
  48.   end
  49.   return unpack(retTable)
  50. end
  51. function P.GetItemSpell(...) -- 7.x to 8.x transience 2nd return value removed
  52.   if (tocVersion < 80000) then return _G.GetItemSpell(...) end
  53.   local retTable = {_G.GetItemSpell(...)}
  54.   if retTable[1] then table.insert(retTable,2,'') end
  55.   return unpack(retTable)
  56. end
  57. function P.GetSpellLink(...) -- 7.x to 8.x transience 2nd return value removed
  58.   if (tocVersion < 80000) then return _G.GetSpellLink(...) end
  59.   local retTable = {_G.GetSpellLink(...)}
  60.   if retTable[1] then table.insert(retTable,2,_G.GetSpellTradeSkillLink(...)) end
  61.   return unpack(retTable)
  62. end
  63. local UnitAuraCache = {} -- cached values are updated ten times per second and stored by unit+filter
  64. function P.UnitAura(unit, ...) -- 7.x to 8.x transience 2nd return value removed and only spellID argument is supported
  65.   if tocVersion < 80000 then return _G.UnitAura(unit, ...) end
  66.   local retTable
  67.   local index = select(1,...)
  68.   if type(index) == 'number' then -- now only spellID is accepted
  69.     retTable = {_G.UnitAura(unit, ...)}
  70.     if retTable[1] then table.insert(retTable,2,'') end
  71.   elseif type(index) == 'string' then -- lokup by spellName must be done on own by fetching all auras and then looking up by name
  72.     local index, _, filter = select(1,...)
  73.     local key = string.lower(filter or 'default')
  74.     index = string.lower(index) -- lookup by spell name
  75.     unit = string.lower(unit)
  76.     local cache = UnitAuraCache[unit] -- fetch unit aura cache
  77.     if cache and cache[key] and cache[key]['stamp'] == ("%.1f"):format(GetTime()) then -- cached values updated 10 times per second
  78.       if cache[key][index] then retTable = cache[key][index] else retTable = {} end
  79.     else -- fetch new cached values
  80.       if not UnitAuraCache[unit] then UnitAuraCache[unit] = {} end
  81.       if not UnitAuraCache[unit][key] then UnitAuraCache[unit][key] = {} else table.wipe(UnitAuraCache[unit][key]) end
  82.       cache = UnitAuraCache[unit][key]
  83.       local n = 1
  84.       local name
  85.       repeat
  86.         retTable = {_G.UnitAura(unit, n, filter)}
  87.         name = retTable[1]
  88.         if name then
  89.           table.insert(retTable,2,'')
  90.           cache[string.lower(name)] = table.copy(retTable)
  91.         end
  92.         n = n + 1
  93.       until not name;
  94.       cache['stamp'] = ("%.1f"):format(GetTime())
  95.       if cache[index] then
  96.         retTable = cache[index]
  97.       else
  98.         retTable = {nil}
  99.       end
  100.     end
  101.   end
  102.   return unpack(retTable)
  103. end
  104. local UnitBuffCache = {} -- cached values are updated ten times per second and stored by unit+filter
  105. function P.UnitBuff(unit, ...) -- 7.x to 8.x transience 2nd return value removed and only spellID argument is supported
  106.   if tocVersion < 80000 then return _G.UnitBuff(unit, ...) end
  107.   local retTable
  108.   local index = select(1,...)
  109.   if type(index) == 'number' then -- now only spellID is accepted
  110.     retTable = {_G.UnitBuff(unit, ...)}
  111.     if retTable[1] then table.insert(retTable,2,'') end
  112.   elseif type(index) == 'string' then -- lokup by spellName must be done on own by fetching all auras and then looking up by name
  113.     local index, _, filter = select(1,...)
  114.     local key = string.lower(filter or 'default')
  115.     index = string.lower(index) -- lookup by spell name
  116.     unit = string.lower(unit)
  117.     local cache = UnitBuffCache[unit] -- fetch unit aura cache
  118.     if cache and cache[key] and cache[key]['stamp'] == ("%.1f"):format(GetTime()) then -- cached values updated 10 times per second
  119.       if cache[key][index] then retTable = cache[key][index] else retTable = {} end
  120.     else -- fetch new cached values
  121.       if not UnitBuffCache[unit] then UnitBuffCache[unit] = {} end
  122.       if not UnitBuffCache[unit][key] then UnitBuffCache[unit][key] = {} else table.wipe(UnitBuffCache[unit][key]) end
  123.       cache = UnitBuffCache[unit][key]
  124.       local n = 1
  125.       local name
  126.       repeat
  127.         retTable = {_G.UnitBuff(unit, n, filter)}
  128.         name = retTable[1]
  129.         if name then
  130.           table.insert(retTable,2,'')
  131.           cache[string.lower(name)] = table.copy(retTable)
  132.         end
  133.         n = n + 1
  134.       until not name;
  135.       cache['stamp'] = ("%.1f"):format(GetTime())
  136.       if cache[index] then
  137.         retTable = cache[index]
  138.       else
  139.         retTable = {nil}
  140.       end
  141.     end
  142.   end
  143.   return unpack(retTable)
  144. end
  145. local UnitDebuffCache = {} -- cached values are updated ten times per second and stored by unit+filter
  146. function P.UnitDebuff(unit, ...) -- 7.x to 8.x transience 2nd return value removed and only spellID argument is supported
  147.   if tocVersion < 80000 then return _G.UnitDebuff(unit, ...) end
  148.   local retTable
  149.   local index = select(1,...)
  150.   if type(index) == 'number' then -- now only spellID is accepted
  151.     retTable = {_G.UnitDebuff(unit, ...)}
  152.     if retTable[1] then table.insert(retTable,2,'') end
  153.   elseif type(index) == 'string' then -- lokup by spellName must be done on own by fetching all auras and then looking up by name
  154.     local index, _, filter = select(1,...)
  155.     local key = string.lower(filter or 'default')
  156.     index = string.lower(index) -- lookup by spell name
  157.     unit = string.lower(unit)
  158.     local cache = UnitDebuffCache[unit] -- fetch unit aura cache
  159.     if cache and cache[key] and cache[key]['stamp'] == ("%.1f"):format(GetTime()) then -- cached values updated 10 times per second
  160.       if cache[key][index] then retTable = cache[key][index] else retTable = {} end
  161.     else -- fetch new cached values
  162.       if not UnitDebuffCache[unit] then UnitDebuffCache[unit] = {} end
  163.       if not UnitDebuffCache[unit][key] then UnitDebuffCache[unit][key] = {} else table.wipe(UnitDebuffCache[unit][key]) end
  164.       cache = UnitDebuffCache[unit][key]
  165.       local n = 1
  166.       local name
  167.       repeat
  168.         retTable = {_G.UnitDebuff(unit, n, filter)}
  169.         name = retTable[1]
  170.         if name then
  171.           table.insert(retTable,2,'')
  172.           cache[string.lower(name)] = table.copy(retTable)
  173.         end
  174.         n = n + 1
  175.       until not name;
  176.       cache['stamp'] = ("%.1f"):format(GetTime())
  177.       if cache[index] then
  178.         retTable = cache[index]
  179.       else
  180.         retTable = {nil}
  181.       end
  182.     end
  183.   end
  184.   return unpack(retTable)
  185. end
  186. function P.GetPlayerMapPosition(...) -- 7.x to 8.x transinece function removed, this just simulate old function buth with different scale
  187.   if tocVersion < 80000 then return _G.GetPlayerMapPosition(...) end
  188.   local x, y = _G.UnitPosition(...)
  189.   if type(x) == 'number' and type(y) == 'number' then
  190.     x = x / 1000.0
  191.     y = y / 1000.0
  192.   end
  193.   return x, y
  194. end

Last edited by Edik : 04-30-18 at 11:58 PM.
  Reply With Quote