Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort loadouts dropdown based on name + number #7759

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Modules/Build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,21 @@ function buildMode:SyncLoadouts(reset)
end
end

table.sort(filteredList, function(a, b)
local aText, aNum = a:match("^(.+) {%d+}$"), tonumber(a:match("{(%d+)}"))
local bText, bNum = b:match("^(.+) {%d+}$"), tonumber(b:match("{(%d+)}"))
Comment on lines +977 to +978
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local aText, aNum = a:match("^(.+) {%d+}$"), tonumber(a:match("{(%d+)}"))
local bText, bNum = b:match("^(.+) {%d+}$"), tonumber(b:match("{(%d+)}"))
local aText, aNum = a:match("^(.+) {%w+}$"), tonumber(a:match("{(%d+)}"))
local bText, bNum = b:match("^(.+) {%w+}$"), tonumber(b:match("{(%d+)}"))

The identifier doesn't have to be a number and I think we still want to sort by name if it's not

if not aText then
aText, aNum = a, 0
end
if not bText then
bText, bNum = b, 0
end
if aText ~= bText then
return aText < bText
end
return aNum < bNum
end)

t_insert(filteredList, "-----")
t_insert(filteredList, "New Loadout")
t_insert(filteredList, "Sync")
Expand Down
Loading