View Single Post
11-28-09, 09:24 AM   #10
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by haste View Post
There's a couple of things you want to think of when you want to sort auras using table.sort:
1. Auras that aren't shown also have outdated information.
2. Auras with no duration are represented as 0 in duration.

The following should handle both those cases:
Lua Code:
  1. local CustomAuraFilter = function(icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster)
  2.        local isPlayer
  3.  
  4.        if(caster == 'player' or caster == 'vehicle') then
  5.                isPlayer = true
  6.        end
  7.  
  8.        if((icons.onlyShowPlayer and isPlayer) or (not icons.onlyShowPlayer and name)) then
  9.                icon.isPlayer = isPlayer
  10.                icon.owner = caster
  11.  
  12.                -- We set it to math.huge, because it lasts until cancelled.
  13.                if(timeLeft == 0) then
  14.                        icon.timeLeft = math.huge
  15.                else
  16.                        icon.timeLeft = timeLeft
  17.                end
  18.  
  19.                return true
  20.        end
  21. end
  22.  
  23. local sort = function(a, b)
  24.        return (a.timeLeft and a.timeLeft) > (b.timeLeft and b.timeLeft)
  25. end
  26. local PreAuraSetPosition = function(self, auras, max)
  27.        -- Make all hidden icons "invalid"
  28.        for i=1, max do
  29.                local icon = auras[i]
  30.                if(not icon:IsShown()) then
  31.                        icon.timeLeft = nil
  32.                end
  33.        end
  34.  
  35.        table.sort(auras, sort)
  36. end
CustomAuraFilter is pretty much a copy/paste of the one oUF uses internally, but with timeLeft added.
Error on line 24, comparing number with nil.
  Reply With Quote