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()
addon:Print("Starting 6-phase bag sort...")
local bagIDs = addon.Constants.BAGS
-- Phase 1: Detect specialized bags
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
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)
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)
local specializedMoves = 0
@@ -529,39 +518,29 @@ function SortEngine:SortBags()
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
local regularMoves = 0
local regularBagIDs = containers.regular
if table.getn(regularBagIDs) > 0 then
local items = CollectItems(regularBagIDs)
if table.getn(items) > 0 then
items = SortItems(items)
local targetPositions = BuildTargetPositions(regularBagIDs, table.getn(items))
local moveCount = ApplySort(regularBagIDs, items, targetPositions)
if moveCount > 0 then
addon:Print("Phase 4b: Sorted and compressed %d items in regular bags", moveCount)
end
regularMoves = ApplySort(regularBagIDs, items, targetPositions)
end
end
-- Phase 6: Validate
ValidateSort(bagIDs)
addon:Print("Sort complete!")
-- Return total moves made (used to determine if another pass is needed)
return routeCount + consolidateCount + specializedMoves + regularMoves
end
function SortEngine:SortBank()
if not addon.Modules.BankScanner:IsBankOpen() then
addon:Print("Bank must be open to sort!")
return
return 0
end
addon:Print("Starting 6-phase bank sort...")
local bagIDs = addon.Constants.BANK_BAGS
-- Phase 1: Detect specialized bags
@@ -569,15 +548,9 @@ function SortEngine:SortBank()
-- Phase 2: Route specialized items
local routeCount = RouteSpecializedItems(bagIDs, containers)
if routeCount > 0 then
addon:Print("Routed %d specialized items", routeCount)
end
-- Phase 3: Consolidate stacks
local consolidateCount = ConsolidateStacks(bagIDs)
if consolidateCount > 0 then
addon:Print("Consolidated %d stacks", consolidateCount)
end
-- Phase 4: Sort items WITHIN each specialized bag
local specializedMoves = 0
@@ -606,5 +579,6 @@ function SortEngine:SortBank()
end
end
addon:Print("Bank sort complete! Moved %d items", specializedMoves + regularMoves)
-- Return total moves made
return routeCount + consolidateCount + specializedMoves + regularMoves
end
+45 -11
View File
@@ -1023,25 +1023,59 @@ function Guda_BagFrame_ToggleKeyring()
BagFrame:Update()
end
-- Sort button handler
-- Sort button handler with auto-repeat
function Guda_BagFrame_Sort()
if currentViewChar then
addon:Print("Cannot sort another character's bags!")
return
end
addon.Modules.SortEngine:SortBags()
addon:Print("Sorting bags...")
-- Update after a delay to allow items to move
local frame = CreateFrame("Frame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed >= 0.5 then
frame:SetScript("OnUpdate", nil)
BagFrame:Update()
local passCount = 0
local maxPasses = 10 -- Safety limit
local function DoSortPass()
passCount = passCount + 1
-- Perform one sort pass
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
-- Start the first pass
DoSortPass()
end
-- Hook to default bag opening
+45 -10
View File
@@ -488,24 +488,59 @@ function Guda_BankFrame_OnSearchChanged(self)
end
end
-- Sort button handler
-- Sort button handler with auto-repeat
function Guda_BankFrame_Sort()
if isReadOnlyMode or currentViewChar then
addon:Print("Cannot sort in read-only mode!")
return
end
addon.Modules.SortEngine:SortBank()
addon:Print("Sorting bank...")
local frame = CreateFrame("Frame")
local elapsed = 0
frame:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed >= 0.5 then
frame:SetScript("OnUpdate", nil)
BankFrame:Update()
local passCount = 0
local maxPasses = 10 -- Safety limit
local function DoSortPass()
passCount = passCount + 1
-- 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
-- Start the first pass
DoSortPass()
end
-- Switch to Blizzard bank UI