Originally Posted by Fizzlemizz
I don't Ace so I don't know what format AddOnList is supposed to be in, I was going on the sort you were using which was on the key "name".
|
In Ace,
values = AddOnList is a table, and it looks like the key is a number and value in this case is a string (although it could be anything valid). In other words:
No worries that you don't use Ace; the good news in this case is that is tables, not a mysterious API.
I am looking at GatherMate2's returned table, which needs to be a lot more complex than what I am doing, largely because GM2's table has zone, expansion, and gathered item data. It is also a metatable, which might be useful in case data is added or removed (maybe, in my case, if the user toggled AddOns on/off).
For reference, in GM's options table, it has
values = sortedFilter["Archaeology"] or
values = sortedFilter["Treasure"] etc.
My addon is not a plugin for GatherMate; I am merely looking at its code for reference on how to populate a table (values) with a set of unknown quantities (I have no idea which addons the user has installed, or how many).
Below is code from GatherMate2. It is the return from
values = blah in the options table.
Lua Code:
-- Setup some storage arrays by db to sort node names and zones alphabetically
local delocalizedZones = {}
local denormalizedNames = {}
local sortedFilter = setmetatable({}, {__index = function(t, k)
local new = {}
table.wipe(delocalizedZones)
if k == "zones" then
for index, zoneID in pairs(GatherMate.HBD:GetAllMapIDs()) do
local name = GatherMate:MapLocalize(zoneID)
new[name] = name
delocalizedZones[name] = zoneID
end
else
local map = GatherMate.nodeIDs[k]
for name in pairs(map) do
local idx = #new+1
new[idx] = name
denormalizedNames[name] = name
end
local expansion = GatherMate.nodeExpansion[k]
if expansion then
-- We only end up creating one function per tracked type anyway
table.sort(new, function(a, b)
local mA, mB = expansion[map[a]], expansion[map[b]]
if not mA or not mB or mA == mB then return map[a] > map[b]
else return mA > mB end
end)
else
table.sort(new)
end
end
rawset(t, k, new)
return new
end})