feat: improved sorting added analyse and prediction of maxPasses before start sorting
This commit is contained in:
+22
-8
@@ -494,17 +494,29 @@ function Guda_BankFrame_OnSearchChanged(self)
|
||||
end
|
||||
end
|
||||
|
||||
-- Sort button handler with auto-repeat
|
||||
-- Sort button handler with auto-repeat and smart pass calculation
|
||||
function Guda_BankFrame_Sort()
|
||||
if isReadOnlyMode or currentViewChar then
|
||||
addon:Print("Cannot sort in read-only mode!")
|
||||
return
|
||||
end
|
||||
|
||||
addon:Print("Sorting bank...")
|
||||
-- Analyze bank to determine how many passes are needed
|
||||
local analysis = addon.Modules.SortEngine:AnalyzeBank()
|
||||
|
||||
-- Check if already sorted
|
||||
if analysis.alreadySorted then
|
||||
addon:Print("Bank is already sorted!")
|
||||
return
|
||||
end
|
||||
|
||||
-- Print analysis results
|
||||
addon:Print("Sorting bank... (%d/%d items need sorting, estimated %d passes)",
|
||||
analysis.itemsOutOfPlace, analysis.totalItems, analysis.passes)
|
||||
|
||||
local passCount = 0
|
||||
local maxPasses = 10 -- Safety limit
|
||||
local maxPasses = math.max(analysis.passes, 1) -- Use estimated passes, minimum 1
|
||||
local safetyLimit = maxPasses + 3 -- Add 3 extra passes as safety margin
|
||||
|
||||
local function DoSortPass()
|
||||
passCount = passCount + 1
|
||||
@@ -513,8 +525,8 @@ function Guda_BankFrame_Sort()
|
||||
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 (longer delay for many items)
|
||||
if moveCount > 0 and passCount < safetyLimit then
|
||||
-- Wait for items to settle, then sort again
|
||||
local frame = CreateFrame("Frame")
|
||||
local elapsed = 0
|
||||
frame:SetScript("OnUpdate", function()
|
||||
@@ -526,10 +538,12 @@ function Guda_BankFrame_Sort()
|
||||
end)
|
||||
else
|
||||
-- Sorting complete
|
||||
if passCount >= maxPasses then
|
||||
addon:Print("Bank sort complete! (reached max passes)")
|
||||
if passCount >= safetyLimit then
|
||||
addon:Print("Bank sort complete! (reached safety limit after %d passes)", passCount)
|
||||
elseif passCount <= maxPasses then
|
||||
addon:Print("Bank sort complete! (%d passes, as predicted)", passCount)
|
||||
else
|
||||
addon:Print("Bank sort complete! (%d passes)", passCount)
|
||||
addon:Print("Bank sort complete! (%d passes, %d more than estimated)", passCount, passCount - maxPasses)
|
||||
end
|
||||
|
||||
-- Final update
|
||||
|
||||
Reference in New Issue
Block a user