Hi,
just got started with LUA and currently working on my own oUF layout.
I run into a problem with aura sorting and can't figure out what I'm doing wrong.
What I plan to to:
- display auras on my playerframe selected by the spellID using the filter function (working)
- sorting the auras by a manual assigned priority
- sorting goes like: auras I want to show in a special order > auras I don't want to show > unused icons
The funny stuff is that the table sorts exactly the way I want it to. But the displayed Auras show really strange behaviors. Buffs are missing. empty icons showing up. Nothing gets sorted at all.
Please enlighten me how hard I fail at LUA!
The code:
Aura list:
Code:
local spells = {
[12880] = 1, -- Enrage (Warrior)
[169667] = 2, -- Shield Charge (Warrior)
[47788] = 20, -- Guardian Spirit (Priest)
[33206] = 21, -- Pain Suppression (Priest)
[62618] = 22, -- Power Word: Barrier (Priest)
[114039] = 12, -- Hand of Purity (Paladin)
[6940] = 11, -- Hand of Sacrifice (Paladin)
[1022] = 10, -- Hand of Protection (Paladin)
[172106] = 5, -- Aspect of the Fox (Hunter)
[5171] = 1, -- Slice and Dice (Rogue)
[84745] = 2, -- Shallow Insight (Rogue)
[84746] = 3, -- Moderate Insight (Rogue)
[84747] = 4, -- Deep Insight (Rogue)
}
Filter:
Code:
function FilterPlayerAuras(self, unit, icon, ...)
local _, _, _, _, _, _, _, _, _, _, id = ...
icon.spellID = id -- just in case I need it
if(spells[id]) then
icon.spellPrio = spells[id]
return true
else
icon.spellPrio = math.huge
return true -- set to true for testing sort
end
end
Sorting:
Code:
local SortAuras = function(a, b)
if (a:IsShown() and b:IsShown()) then
return a.spellPrio < b.spellPrio
elseif (a:IsShown()) then
return true
end
end
Code:
local PreSetPosition = function(Auras)
table.sort(Auras, SortAuras)
end
Function to show the table contend for testing. Not mine, found it here and modified it.
Code:
local PrintAuras = function(Auras)
local button
local text = {}
for i = 1, #Auras do
button = Auras[i]
if (not button) then
tinsert(text, i, "NC") -- not created
elseif (button:IsShown()) then
local _, _, icon = GetSpellInfo(button.spellID)
if (button.spellPrio == math.huge) then
tinsert(text, i, "|cffff0000(|r".."|T"..icon..":0|t".."|cffff0000)|r")
else
tinsert(text, i, "|cff00ff00(|r".."|T"..icon..":0|t".."|cff00ff00)|r")
end
else
tinsert(text, i, "U") -- unused, hidden
end
end
return table.concat(text, "-")
end