Skip to content

Commit

Permalink
Add more sorting error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
b-morgan committed Sep 25, 2024
1 parent 998d1cb commit 4d2e66a
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 39 deletions.
69 changes: 50 additions & 19 deletions Plugins/Auctionator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,10 @@ local function GetRecipeData(recipe)
profit = buyout * ah_tax - cost
percentage = profit * 100 / cost
--DA.DEBUG(0,"GetRecipeData: buyout= "..tostring(buyout)..", profit= "..tostring(profit)..", percentage= "..tostring(percentage))
recipe.buyout = buyout
recipe.cost = cost
recipe.profit = profit
recipe.percentage = percentage
recipe.buyout = buyout or 0
recipe.cost = cost or 0
recipe.profit = profit or 0
recipe.percentage = percentage or 0
-- recipe.mostsold = successCount
-- recipe.salesrate = salesRate
recipe.suffix = SetATRsuffix(recipe)
Expand All @@ -642,8 +642,13 @@ end
-- Sort by Auctionator Buyout price
--
function plugin.SortByBuyout(skill,a,b)
if a.subGroup or b.subGroup then
return NOSORT(skill, a, b)
--DA.DEBUG(0,"SortByBuyout: skill= "..tostring(skill)..", a="..tostring(a)..", b="..tostring(b))
if a and b then
if a.subGroup or b.subGroup then
return NOSORT(skill, a, b)
end
else
return false
end
local recipeA, recipeB, idA, idB, buyoutA, buyoutB
recipeA = Skillet:GetRecipe(a.recipeID)
Expand All @@ -666,8 +671,13 @@ end
-- Sort by Auctionator Cost
--
function plugin.SortByCost(skill,a,b)
if a.subGroup or b.subGroup then
return NOSORT(skill, a, b)
--DA.DEBUG(0,"SortByCost: skill= "..tostring(skill)..", a="..tostring(a)..", b="..tostring(b))
if a and b then
if a.subGroup or b.subGroup then
return NOSORT(skill, a, b)
end
else
return false
end
local recipeA, recipeB, idA, idB, costA, costB
recipeA = Skillet:GetRecipe(a.recipeID)
Expand All @@ -690,8 +700,13 @@ end
-- Sort by calculated profit value
--
function plugin.SortByProfit(skill,a,b)
if a.subGroup or b.subGroup then
return NOSORT(skill, a, b)
--DA.DEBUG(0,"SortByProfit: skill= "..tostring(skill)..", a="..tostring(a)..", b="..tostring(b))
if a and b then
if a.subGroup or b.subGroup then
return NOSORT(skill, a, b)
end
else
return false
end
local recipeA, recipeB, idA, idB, profitA, profitB
recipeA = Skillet:GetRecipe(a.recipeID)
Expand All @@ -714,14 +729,22 @@ end
-- Sort by calculated profit percentage
--
function plugin.SortByPercent(skill,a,b)
if a.subGroup or b.subGroup then
return NOSORT(skill, a, b)
--DA.DEBUG(0,"SortByPercent: skill= "..tostring(skill)..", a="..tostring(a)..", b="..tostring(b))
if a and b then
--DA.DEBUG(1,"SortByPercent: a= "..DA.DUMP1(a,1))
--DA.DEBUG(1,"SortByPercent: b= "..DA.DUMP1(b,1))
if a.subGroup or b.subGroup then
-- return NOSORT(skill, a, b)
return false
end
else
return false
end
local recipeA, recipeB, idA, idB, percentA, percentB
recipeA = Skillet:GetRecipe(a.recipeID)
--DA.DEBUG(0,"SortByPercent: recipeA= "..DA.DUMP1(recipeA))
--DA.DEBUG(1,"SortByPercent: recipeA= "..DA.DUMP1(recipeA))
recipeB = Skillet:GetRecipe(b.recipeID)
--DA.DEBUG(0,"SortByPercent: recipeB= "..DA.DUMP1(recipeB))
--DA.DEBUG(1,"SortByPercent: recipeB= "..DA.DUMP1(recipeB))
if not recipeA.percentage then
GetRecipeData(recipeA)
end
Expand All @@ -730,7 +753,7 @@ function plugin.SortByPercent(skill,a,b)
GetRecipeData(recipeB)
end
percentB = recipeB.percentage or 0
--DA.DEBUG(0,"SortByPercent: percentA= "..tostring(percentA)..", percentB= "..tostring(percentB))
--DA.DEBUG(1,"SortByPercent: percentA= "..tostring(percentA)..", percentB= "..tostring(percentB))
return (percentA > percentB)
end

Expand All @@ -740,8 +763,12 @@ end
-- For enchanting, use the scrollID instead of the itemID
--
function plugin.SortMostSold(skill,a,b)
if a.subGroup or b.subGroup then
return NOSORT(skill, a, b)
if a and b then
if a.subGroup or b.subGroup then
return NOSORT(skill, a, b)
end
else
return
end
local recipeA, recipeB, itemNameA, itemNameB, successCountA, successCountB
recipeA = Skillet:GetRecipe(a.recipeID)
Expand Down Expand Up @@ -778,8 +805,12 @@ end
-- For enchanting, use the scrollID instead of the itemID
--
function plugin.SortSalesRate(skill,a,b)
if a.subGroup or b.subGroup then
return NOSORT(skill, a, b)
if a and b then
if a.subGroup or b.subGroup then
return NOSORT(skill, a, b)
end
else
return
end
local recipeA, recipeB, itemNameA, itemNameB, successCountA, successCountB
local failedCountA, failedCountB, salesRateA, salesRateB
Expand Down
26 changes: 20 additions & 6 deletions RecipeGroups.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,21 @@ function Skillet:RecipeGroupNew(player, tradeID, label, name)
end
end

function Skillet:RecipeGroupClearEntries(group)
function Skillet:RecipeGroupClearEntries(group, n)
--DA.DEBUG(0,"RecipeGroupClearEntries("..DA.DUMP1(group,1))
if not n then
n = 0
--DA.DEBUG(0,"RecipeGroupClearEntries("..DA.DUMP1(group,1))
end
if group then
--DA.DEBUG(1,"RecipeGroupClearEntries: n="..tostring(n)..", name= "..tostring(group.name)..", #group.entries= "..tostring(#group.entries))
for i=1,#group.entries do
if group.entries[i].subGroup then
self:RecipeGroupClearEntries(group.entries[i].subGroup)
if group.entries[i] then
if group.entries[i].subGroup then
self:RecipeGroupClearEntries(group.entries[i].subGroup, n+1)
end
else
--DA.DEBUG(2,"RecipeGroupClearEntries: i="..tostring(i)..", entry= "..DA.DUMP1(group.entries[i],1))
end
end
group.entries = {}
Expand Down Expand Up @@ -337,15 +346,20 @@ function Skillet:RecipeGroupRenameEntry(entry, name)
end
end

function Skillet:RecipeGroupSort(group, sortMethod, reverse)
function Skillet:RecipeGroupSort(group, sortMethod, reverse, n)
--DA.DEBUG(0,"RecipeGroupSort("..tostring(group.skillIndex)..", "..tostring(sortMethod)..","..tostring(reverse)..")")
if not n then
n = 0
--DA.DEBUG(0,"RecipeGroupSort("..DA.DUMP1(group,1))
end
--DA.DEBUG(0,"RecipeGroupSort: skillIndex="..tostring(group.skillIndex)..", name="..tostring(group.name)..", reverse="..tostring(reverse)..", n="..tostring(n))
if group then
for v, entry in pairs(group.entries) do
if entry.subGroup and entry.subGroup ~= group then
self:RecipeGroupSort(entry.subGroup, sortMethod, reverse)
self:RecipeGroupSort(entry.subGroup, sortMethod, reverse, n+1)
end
end
if group.entries and #group.entries>1 then
if group.entries and #group.entries > 1 then
if reverse then
table.sort(group.entries, function(a,b)
return sortMethod(Skillet.currentTrade, b, a)
Expand Down
10 changes: 7 additions & 3 deletions SkilletData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -652,22 +652,26 @@ local function GetMyCategories(player, tradeID)
--DA.DEBUG(1,"GetMyCategories: categories= "..DA.DUMP1(categories))
for i, categoryID in ipairs(categories) do
local catInfo = C_TradeSkillUI.GetCategoryInfo(categoryID)
--DA.DEBUG(2,"GetMyCategories: i= "..tostring(i)..", categoryID= "..tostring(categoryID)..", catInfo.name= "..tostring(catInfo.name))
--DA.DEBUG(2,"GetMyCategories: i= "..tostring(i)..", categoryID= "..tostring(categoryID)..
-- ", catInfo.name= "..tostring(catInfo.name)..", type= "..tostring(catInfo.type)..", hasProgressBar= "..tostring(catInfo.hasProgressBar))
--DA.DEBUG(3,"GetMyCategories: catInfo= "..DA.DUMP1(catInfo))
Skillet.db.global.Categories[tradeID][categoryID] = catInfo

local subCategories = { C_TradeSkillUI.GetSubCategories(categoryID) }
--DA.DEBUG(4,"GetMyCategories: subCategories= "..DA.DUMP1(subCategories))
for j, subCategory in ipairs(subCategories) do
local subCatInfo = C_TradeSkillUI.GetCategoryInfo(subCategory)
--DA.DEBUG(3,"GetMyCategories: j= "..tostring(j)..", subCategory= "..tostring(subCategory)..", subCatInfo.name= "..tostring(subCatInfo.name))
--DA.DEBUG(3,"GetMyCategories: j= "..tostring(j)..", subCategory= "..tostring(subCategory)..
-- ", subCatInfo.name= "..tostring(subCatInfo.name)..", type= "..tostring(subCatInfo.type)..", hasProgressBar= "..tostring(subCatInfo.hasProgressBar))
--DA.DEBUG(4,"GetMyCategories: subCatInfo= "..DA.DUMP1(subCatInfo))
Skillet.db.global.Categories[tradeID][subCategory] = subCatInfo

local subsubCategories = { C_TradeSkillUI.GetSubCategories(subCategory) }
--DA.DEBUG(5,"GetMyCategories: subsubCategories= "..DA.DUMP1(subsubCategories))
for k, subsubCategory in ipairs(subsubCategories) do
local subsubCatInfo = C_TradeSkillUI.GetCategoryInfo(subsubCategory)
--DA.DEBUG(4,"GetMyCategories: k= "..tostring(k)..", subsubCategory= "..tostring(subsubCategory)..", subsubCatInfo.name= "..tostring(subsubCatInfo.name))
--DA.DEBUG(4,"GetMyCategories: k= "..tostring(k)..", subsubCategory= "..tostring(subsubCategory)..
-- ", subsubCatInfo.name= "..tostring(subsubCatInfo.name)..", type= "..tostring(subsubCatInfo.type)..", hasProgressBar= "..tostring(subsubCatInfo.hasProgressBar))
--DA.DEBUG(5,"GetMyCategories: subsubCatInfo= "..DA.DUMP1(subsubCatInfo))
Skillet.db.global.Categories[tradeID][subsubCategory] = subsubCatInfo

Expand Down
1 change: 1 addition & 0 deletions SkilletNewsData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Skillet.NewsData = {
{ name = "Fixes",
data = {
{ header = "EasyMenu", body = "Replace EasyMenu calls" },
{ header = "Sorting", body = "Add more error checks" },
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion SkilletQueue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ function Skillet:ProcessQueue(altMode)
else
self.recipeTransaction = CreateProfessionsRecipeTransaction(C_TradeSkillUI.GetRecipeSchematic(command.recipeID, false, recipeLevel))
ApplyAllocations(self.recipeTransaction, command.modifiedReagents, command.requiredReagents, command.optionalReagents, command.finishingReagents)
--DA.DEBUG(1,"ProcessQueue: recipeLevel= "..tostring(recipeLevel)..", recipeTransaction= "..DA.DUMP(self.recipeTransaction))
DA.DEBUG(1,"ProcessQueue: recipeLevel= "..tostring(recipeLevel)..", recipeTransaction= "..DA.DUMP(self.recipeTransaction))
end
--
-- For debugging, save the command and TraceLog setting. Restored in ContinueCast.
Expand Down Expand Up @@ -708,6 +708,7 @@ function Skillet:ProcessQueue(altMode)
C_TradeSkillUI.CraftRecipe(command.recipeID, command.count, reagentInfoTbl, recipeLevel)
else
DA.MARK3("Insufficient (Required) Materials available")
DA.DEBUG(1,"ProcessQueue: reagentInfoTbl= "..DA.DUMP(reagentInfoTbl))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion UI/MainFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ function Skillet:UpdateTradeSkillWindow()
SkilletUseHighestQuality:SetChecked(self.db.profile.best_quality)
SkilletUseHighestQuality:Show()
SkilletUseConcentration:SetChecked(self.db.profile.use_concentration)
SkilletUseConcentration:Show()
-- SkilletUseConcentration:Show()
SkilletHideUncraftableRecipes:SetChecked(self:GetTradeSkillOption("hideuncraftable"))
C_TradeSkillUI.SetOnlyShowMakeableRecipes(self:GetTradeSkillOption("hideuncraftable"))
self:UpdateQueueWindow()
Expand Down
22 changes: 13 additions & 9 deletions UI/Sorting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,20 @@ local function sort_recipe_by_item_quality(tradeskill, a, b)
end

local function sort_recipe_by_index(tradeskill, a, b)
if a.subGroup and not b.subGroup then
return true
end
if b.subGroup and not a.subGroup then
return false
end
if (a.skillIndex or 0) == (b.skillIndex or 0) then
return (a.name or "A") < (b.name or "B")
if a and b then
if a.subGroup and not b.subGroup then
return true
end
if b.subGroup and not a.subGroup then
return false
end
if (a.skillIndex or 0) == (b.skillIndex or 0) then
return (a.name or "A") < (b.name or "B")
else
return (a.skillIndex or 0) < (b.skillIndex or 0)
end
else
return (a.skillIndex or 0) < (b.skillIndex or 0)
return false
end
end

Expand Down

0 comments on commit 4d2e66a

Please sign in to comment.