fix: sort is working

This commit is contained in:
Salikh Gurgenidze
2025-11-19 01:56:00 +04:00
parent 948fee6b6f
commit 7abea59a5c
3 changed files with 97 additions and 54 deletions
+7 -33
View File
@@ -492,27 +492,16 @@ end
--=========================================================================== --===========================================================================
function SortEngine:SortBags() function SortEngine:SortBags()
addon:Print("Starting 6-phase bag sort...")
local bagIDs = addon.Constants.BAGS local bagIDs = addon.Constants.BAGS
-- Phase 1: Detect specialized bags -- Phase 1: Detect specialized bags
local containers = DetectSpecializedBags(bagIDs) local containers = DetectSpecializedBags(bagIDs)
addon:Print("Phase 1: Detected %d soul, %d quiver, %d ammo, %d regular bags",
table.getn(containers.soul), table.getn(containers.quiver),
table.getn(containers.ammo), table.getn(containers.regular))
-- Phase 2: Route specialized items to their bags -- Phase 2: Route specialized items to their bags
local routeCount = RouteSpecializedItems(bagIDs, containers) local routeCount = RouteSpecializedItems(bagIDs, containers)
if routeCount > 0 then
addon:Print("Phase 2: Routed %d specialized items", routeCount)
end
-- Phase 3: Consolidate stacks in ALL bags (including specialized) -- Phase 3: Consolidate stacks in ALL bags (including specialized)
local consolidateCount = ConsolidateStacks(bagIDs) local consolidateCount = ConsolidateStacks(bagIDs)
if consolidateCount > 0 then
addon:Print("Phase 3: Consolidated %d stacks", consolidateCount)
end
-- Phase 4: Sort items WITHIN each specialized bag (soul, quiver, ammo) -- Phase 4: Sort items WITHIN each specialized bag (soul, quiver, ammo)
local specializedMoves = 0 local specializedMoves = 0
@@ -529,39 +518,29 @@ function SortEngine:SortBags()
end end
end end
end end
if specializedMoves > 0 then
addon:Print("Phase 4a: Sorted %d items within specialized bags", specializedMoves)
end
-- Phase 5: Categorical sort regular bags -- Phase 5: Categorical sort regular bags
local regularMoves = 0
local regularBagIDs = containers.regular local regularBagIDs = containers.regular
if table.getn(regularBagIDs) > 0 then if table.getn(regularBagIDs) > 0 then
local items = CollectItems(regularBagIDs) local items = CollectItems(regularBagIDs)
if table.getn(items) > 0 then if table.getn(items) > 0 then
items = SortItems(items) items = SortItems(items)
local targetPositions = BuildTargetPositions(regularBagIDs, table.getn(items)) local targetPositions = BuildTargetPositions(regularBagIDs, table.getn(items))
local moveCount = ApplySort(regularBagIDs, items, targetPositions) regularMoves = ApplySort(regularBagIDs, items, targetPositions)
if moveCount > 0 then
addon:Print("Phase 4b: Sorted and compressed %d items in regular bags", moveCount)
end
end end
end end
-- Phase 6: Validate -- Return total moves made (used to determine if another pass is needed)
ValidateSort(bagIDs) return routeCount + consolidateCount + specializedMoves + regularMoves
addon:Print("Sort complete!")
end end
function SortEngine:SortBank() function SortEngine:SortBank()
if not addon.Modules.BankScanner:IsBankOpen() then if not addon.Modules.BankScanner:IsBankOpen() then
addon:Print("Bank must be open to sort!") addon:Print("Bank must be open to sort!")
return return 0
end end
addon:Print("Starting 6-phase bank sort...")
local bagIDs = addon.Constants.BANK_BAGS local bagIDs = addon.Constants.BANK_BAGS
-- Phase 1: Detect specialized bags -- Phase 1: Detect specialized bags
@@ -569,15 +548,9 @@ function SortEngine:SortBank()
-- Phase 2: Route specialized items -- Phase 2: Route specialized items
local routeCount = RouteSpecializedItems(bagIDs, containers) local routeCount = RouteSpecializedItems(bagIDs, containers)
if routeCount > 0 then
addon:Print("Routed %d specialized items", routeCount)
end
-- Phase 3: Consolidate stacks -- Phase 3: Consolidate stacks
local consolidateCount = ConsolidateStacks(bagIDs) local consolidateCount = ConsolidateStacks(bagIDs)
if consolidateCount > 0 then
addon:Print("Consolidated %d stacks", consolidateCount)
end
-- Phase 4: Sort items WITHIN each specialized bag -- Phase 4: Sort items WITHIN each specialized bag
local specializedMoves = 0 local specializedMoves = 0
@@ -606,5 +579,6 @@ function SortEngine:SortBank()
end end
end end
addon:Print("Bank sort complete! Moved %d items", specializedMoves + regularMoves) -- Return total moves made
return routeCount + consolidateCount + specializedMoves + regularMoves
end end
+45 -11
View File
@@ -1023,25 +1023,59 @@ function Guda_BagFrame_ToggleKeyring()
BagFrame:Update() BagFrame:Update()
end end
-- Sort button handler -- Sort button handler with auto-repeat
function Guda_BagFrame_Sort() function Guda_BagFrame_Sort()
if currentViewChar then if currentViewChar then
addon:Print("Cannot sort another character's bags!") addon:Print("Cannot sort another character's bags!")
return return
end end
addon.Modules.SortEngine:SortBags() addon:Print("Sorting bags...")
-- Update after a delay to allow items to move local passCount = 0
local frame = CreateFrame("Frame") local maxPasses = 10 -- Safety limit
local elapsed = 0
frame:SetScript("OnUpdate", function() local function DoSortPass()
elapsed = elapsed + arg1 passCount = passCount + 1
if elapsed >= 0.5 then
frame:SetScript("OnUpdate", nil) -- Perform one sort pass
BagFrame:Update() local moveCount = addon.Modules.SortEngine:SortBags()
-- 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
local frame = CreateFrame("Frame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed >= 0.3 then
frame:SetScript("OnUpdate", nil)
DoSortPass() -- Recursive call for next pass
end
end)
else
-- Sorting complete
if passCount >= maxPasses then
addon:Print("Sort complete! (reached max passes)")
else
addon:Print("Sort complete! (%d passes)", passCount)
end
-- Final update
local frame = CreateFrame("Frame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed >= 0.3 then
frame:SetScript("OnUpdate", nil)
BagFrame:Update()
end
end)
end end
end) end
-- Start the first pass
DoSortPass()
end end
-- Hook to default bag opening -- Hook to default bag opening
+45 -10
View File
@@ -488,24 +488,59 @@ function Guda_BankFrame_OnSearchChanged(self)
end end
end end
-- Sort button handler -- Sort button handler with auto-repeat
function Guda_BankFrame_Sort() function Guda_BankFrame_Sort()
if isReadOnlyMode or currentViewChar then if isReadOnlyMode or currentViewChar then
addon:Print("Cannot sort in read-only mode!") addon:Print("Cannot sort in read-only mode!")
return return
end end
addon.Modules.SortEngine:SortBank() addon:Print("Sorting bank...")
local frame = CreateFrame("Frame") local passCount = 0
local elapsed = 0 local maxPasses = 10 -- Safety limit
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1 local function DoSortPass()
if elapsed >= 0.5 then passCount = passCount + 1
frame:SetScript("OnUpdate", nil)
BankFrame:Update() -- Perform one sort pass
local moveCount = addon.Modules.SortEngine:SortBank()
-- 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
local frame = CreateFrame("Frame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed >= 0.3 then
frame:SetScript("OnUpdate", nil)
DoSortPass() -- Recursive call for next pass
end
end)
else
-- Sorting complete
if passCount >= maxPasses then
addon:Print("Bank sort complete! (reached max passes)")
else
addon:Print("Bank sort complete! (%d passes)", passCount)
end
-- Final update
local frame = CreateFrame("Frame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed >= 0.3 then
frame:SetScript("OnUpdate", nil)
BankFrame:Update()
end
end)
end end
end) end
-- Start the first pass
DoSortPass()
end end
-- Switch to Blizzard bank UI -- Switch to Blizzard bank UI