From d44b2b82420fc155b2acaa11dd1eb4f4065c7914 Mon Sep 17 00:00:00 2001 From: TylerR909 Date: Thu, 1 Jul 2021 00:38:05 -0700 Subject: [PATCH] fix(builds): sort builds --- TalentedTalentFrame.lua | 16 ++++++++-------- TalentedTools.lua | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/TalentedTalentFrame.lua b/TalentedTalentFrame.lua index 8f9e365..a4fc638 100644 --- a/TalentedTalentFrame.lua +++ b/TalentedTalentFrame.lua @@ -58,11 +58,11 @@ function Talented:InitPvEDropdown() { text=TALENTS, isTitle=true, notCheckable=true} } - for _,build in pairs(self.db.class[specid].PvE) do + for name,build in self.tools.traverseBuilds(self.db.class[specid].PvE) do local btn = { - text = build.name, - value = build.build, - checked = compare(build.build, activeBuild), + text = name, + value = build, + checked = compare(build, activeBuild), func = function(btn) self.tools.LearnTalentString(btn.value) end } tinsert(menu, btn) @@ -102,11 +102,11 @@ function Talented:InitPvPDropdown() { text = PVP..' '..TALENTS, isTitle=true, notCheckable=true} } - for _,build in pairs(self.db.class[specid].PvP) do + for name,build in self.tools.traverseBuilds(self.db.class[specid].PvP) do local btn = { - text = build.name, - value = build.build, - checked = compare(build.build, activeBuild), + text = name, + value = build, + checked = compare(build, activeBuild), func = function(btn) self.tools.LearnPvPTalentGroup(btn.value) end } tinsert(menu, btn) diff --git a/TalentedTools.lua b/TalentedTools.lua index 26f2102..c57e30a 100644 --- a/TalentedTools.lua +++ b/TalentedTools.lua @@ -83,6 +83,24 @@ function tools.CompareTalentStrings(a,b) return true end +function tools.traverseBuilds(builds) + local a = {} + for k in pairs(builds) do tinsert(a, k) end + table.sort(a, function(left,right) + return string.lower(left) < string.lower(right) + end) + + local i = 0 + local iter = function() + i = i+1 + if a[i] == nil then return nil end + local build = builds[a[i]] + return build.name, build.build + end + + return iter +end + function tools.ComparePvPTalentBuilds(a,b) if #a ~= #b then return false end local tala, talb;