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:
local CustomAuraFilter = function(icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster)
local isPlayer
if(caster == 'player' or caster == 'vehicle') then
isPlayer = true
end
if((icons.onlyShowPlayer and isPlayer) or (not icons.onlyShowPlayer and name)) then
icon.isPlayer = isPlayer
icon.owner = caster
-- We set it to math.huge, because it lasts until cancelled.
if(timeLeft == 0) then
icon.timeLeft = math.huge
else
icon.timeLeft = timeLeft
end
return true
end
end
local sort = function(a, b)
return (a.timeLeft and a.timeLeft) > (b.timeLeft and b.timeLeft)
end
local PreAuraSetPosition = function(self, auras, max)
-- Make all hidden icons "invalid"
for i=1, max do
local icon = auras[i]
if(not icon:IsShown()) then
icon.timeLeft = nil
end
end
table.sort(auras, sort)
end
CustomAuraFilter is pretty much a copy/paste of the one oUF uses internally, but with timeLeft added.