View Single Post
11-03-18, 10:20 AM   #7
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by Fizzlemizz View Post
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:
Code:
values = k, v
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:
  1. -- Setup some storage arrays by db to sort node names and zones alphabetically
  2. local delocalizedZones = {}
  3. local denormalizedNames = {}
  4. local sortedFilter = setmetatable({}, {__index = function(t, k)
  5.     local new = {}
  6.     table.wipe(delocalizedZones)
  7.     if k == "zones" then
  8.         for index, zoneID in pairs(GatherMate.HBD:GetAllMapIDs()) do
  9.             local name = GatherMate:MapLocalize(zoneID)
  10.             new[name] = name
  11.             delocalizedZones[name] = zoneID
  12.         end
  13.     else
  14.         local map = GatherMate.nodeIDs[k]
  15.         for name in pairs(map) do
  16.             local idx = #new+1
  17.             new[idx] = name
  18.             denormalizedNames[name] = name
  19.         end
  20.         local expansion = GatherMate.nodeExpansion[k]
  21.         if expansion then
  22.             -- We only end up creating one function per tracked type anyway
  23.             table.sort(new, function(a, b)
  24.                 local mA, mB = expansion[map[a]], expansion[map[b]]
  25.                 if not mA or not mB or mA == mB then return map[a] > map[b]
  26.                 else return mA > mB end
  27.             end)
  28.         else
  29.             table.sort(new)
  30.         end
  31.     end
  32.     rawset(t, k, new)
  33.     return new
  34. end})
  Reply With Quote