diff --git a/Bagnon_Forever/database/database.lua b/Bagnon_Forever/database/database.lua index 7f6daa3..4047942 100644 --- a/Bagnon_Forever/database/database.lua +++ b/Bagnon_Forever/database/database.lua @@ -30,8 +30,26 @@ local currentRealm = GetRealmName(); --what currentRealm we're on for playerName, data in BagnonDB.GetPlayers() --]] -function BagnonDB.GetPlayers() - return pairs(BagnonForeverData[currentRealm]) +function BagnonDB.GetPlayers(sort) + if not sort then + -- If sort is false, just return pairs + return pairs(BagnonForeverData[currentRealm]) + end + + -- If sort is true, create a sorted list of keys + local sortedNames = {} + for name in pairs(BagnonForeverData[currentRealm]) do + table.insert(sortedNames, name) + end + table.sort(sortedNames) + + -- Return a custom iterator function + local i = 0 + return function() + i = i + 1 + local playerName = sortedNames[i] + return playerName, BagnonForeverData[currentRealm][playerName] + end end --[[ diff --git a/Bagnon_Forever/database/ui.lua b/Bagnon_Forever/database/ui.lua index 0fc0460..9a86cc8 100644 --- a/Bagnon_Forever/database/ui.lua +++ b/Bagnon_Forever/database/ui.lua @@ -53,7 +53,7 @@ function BagnonDBUI_ShowCharacterList(parentFrame) --update button info local index = 0 - for player in BagnonDB.GetPlayers() do + for player in BagnonDB.GetPlayers(true) do index = index + 1 local button = getglobal("BagnonDBUICharacterList" .. index) or CreatePlayerButton(index, BagnonDBUICharacterList)