Skip to content

Commit

Permalink
Merge pull request #2 from DBFBlackbull/sort-names
Browse files Browse the repository at this point in the history
Sort Bagnon_Forever Character names
  • Loading branch information
McPewPew authored Aug 30, 2024
2 parents 8166e38 + a7cb781 commit 1e4aae9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions Bagnon_Forever/database/database.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

--[[
Expand Down
2 changes: 1 addition & 1 deletion Bagnon_Forever/database/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1e4aae9

Please sign in to comment.