From d2a6d0f46c26a881d3933e2662b369eb8e262e50 Mon Sep 17 00:00:00 2001 From: Salikh Gurgenidze Date: Wed, 19 Nov 2025 02:34:46 +0400 Subject: [PATCH] fix: sorting almost done --- Core/Utils.lua | 37 +++++++++++++++++++------------------ Sorting/SortEngine.lua | 8 ++++++-- UI/BagFrame.lua | 6 +++--- UI/BankFrame.lua | 6 +++--- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/Core/Utils.lua b/Core/Utils.lua index 6115ba0..c8d543a 100644 --- a/Core/Utils.lua +++ b/Core/Utils.lua @@ -227,25 +227,26 @@ function Utils:GetSpecializedBagType(bagID) return nil end - -- Use tooltip scanning - local tooltip = GetScanTooltip() - tooltip:ClearLines() - tooltip:SetInventoryItem("player", invSlot) + -- Use GetItemInfo to get subclass (more reliable than tooltip scanning) + local name, _, quality, iLevel, reqLevel, class, subclass = GetItemInfo(link) - -- Scan tooltip lines - for i = 1, tooltip:NumLines() do - local line = getglobal("GudaBagScanTooltipTextLeft" .. i) - if line then - local text = line:GetText() - if text then - if string.find(text, "Soul") then - return "soul" - elseif string.find(text, "Quiver") then - return "quiver" - elseif string.find(text, "Ammo Pouch") then - return "ammo" - end - end + if subclass then + -- Check for exact subclass matches + local subclassLower = string.lower(subclass) + + -- Soul Bag / Soul Pouch + if string.find(subclassLower, "soul bag") or string.find(subclassLower, "soul pouch") then + return "soul" + end + + -- Quiver + if string.find(subclassLower, "quiver") then + return "quiver" + end + + -- Ammo Pouch + if string.find(subclassLower, "ammo pouch") then + return "ammo" end end diff --git a/Sorting/SortEngine.lua b/Sorting/SortEngine.lua index 09e3da3..046a5e5 100644 --- a/Sorting/SortEngine.lua +++ b/Sorting/SortEngine.lua @@ -380,9 +380,13 @@ local function BuildTargetPositions(bagIDs, itemCount) }) end - -- Sort bags by priority descending (highest first) + -- Sort bags by priority descending (highest first), then by bag ID ascending table.sort(sortedBags, function(a, b) - return a.priority > b.priority + if a.priority ~= b.priority then + return a.priority > b.priority + end + -- When priorities are equal, sort by bag ID ascending (0, 1, 2, 3, 4) + return a.bagID < b.bagID end) -- Build positions in priority order diff --git a/UI/BagFrame.lua b/UI/BagFrame.lua index 11cd50e..25b4573 100644 --- a/UI/BagFrame.lua +++ b/UI/BagFrame.lua @@ -1043,12 +1043,12 @@ function Guda_BagFrame_Sort() -- If items were moved and we haven't hit the limit, do another pass if moveCount > 0 and passCount < maxPasses then - -- Wait for items to settle, then sort again + -- Wait for items to settle, then sort again (longer delay for many items) local frame = CreateFrame("Frame") local elapsed = 0 frame:SetScript("OnUpdate", function() elapsed = elapsed + arg1 - if elapsed >= 0.3 then + if elapsed >= 0.7 then frame:SetScript("OnUpdate", nil) DoSortPass() -- Recursive call for next pass end @@ -1066,7 +1066,7 @@ function Guda_BagFrame_Sort() local elapsed = 0 frame:SetScript("OnUpdate", function() elapsed = elapsed + arg1 - if elapsed >= 0.3 then + if elapsed >= 0.7 then frame:SetScript("OnUpdate", nil) BagFrame:Update() end diff --git a/UI/BankFrame.lua b/UI/BankFrame.lua index 7239f57..f751649 100644 --- a/UI/BankFrame.lua +++ b/UI/BankFrame.lua @@ -508,12 +508,12 @@ function Guda_BankFrame_Sort() -- If items were moved and we haven't hit the limit, do another pass if moveCount > 0 and passCount < maxPasses then - -- Wait for items to settle, then sort again + -- Wait for items to settle, then sort again (longer delay for many items) local frame = CreateFrame("Frame") local elapsed = 0 frame:SetScript("OnUpdate", function() elapsed = elapsed + arg1 - if elapsed >= 0.3 then + if elapsed >= 0.7 then frame:SetScript("OnUpdate", nil) DoSortPass() -- Recursive call for next pass end @@ -531,7 +531,7 @@ function Guda_BankFrame_Sort() local elapsed = 0 frame:SetScript("OnUpdate", function() elapsed = elapsed + arg1 - if elapsed >= 0.3 then + if elapsed >= 0.7 then frame:SetScript("OnUpdate", nil) BankFrame:Update() end