Skip to content

Commit

Permalink
Total Profit and Crafting Costs and Auctionator API adaptions and toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
derfloh205 committed Dec 13, 2023
1 parent aa2a8b5 commit 64b3284
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 35 deletions.
2 changes: 1 addition & 1 deletion CraftSim.toc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Title: CraftSim
## Notes: Calculates the average profit based on your profession stats and other tools for dragonflight gold making
## Author: genju
## Version: 11.3.4
## Version: 11.3.5
## X-Curse-Project-ID: 705015
## X-Wago-ID: 0mNwaPKo
## X-WoWI-ID: 26519
Expand Down
3 changes: 2 additions & 1 deletion Data/News.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function CraftSim.NEWS:GET_NEWS()
return
f.bb(" Hello and thank you for using CraftSim!\n") ..
f.bb(" ( You are awesome! )") ..
newP("11.3.4") ..
newP("11.3.5") ..
f.s .. f.bb("CraftQueue") .. " now shows total average profit and crafting costs" ..
f.s .. "Updated Italian Localizations" ..
f.a .. "Thanks to " .. f.bb("https://github.com/SirDester") ..
f.p .. f.bb("CraftQueue") .. " Restock Options now correctly display" ..
Expand Down
2 changes: 1 addition & 1 deletion Libs/GUTIL
Submodule GUTIL updated 1 files
+7 −5 GUTIL.lua
5 changes: 4 additions & 1 deletion Locals/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ function CraftSim.LOCAL_EN:GetData()
[CraftSim.CONST.TEXT.CRAFT_QUEUE_TITLE] = "CraftSim Craft Queue",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_AMOUNT_LEFT_HEADER] = "Queued",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_PROFESSION_GEAR_HEADER] = "Profession Gear",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFTING_COSTS_HEADER] = "Crafting Costs",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_BUTTON_ROW_LABEL] = "Craft",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_BUTTON_ROW_LABEL_WRONG_GEAR] = "Wrong Tools",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_BUTTON_ROW_LABEL_NO_MATS] = "No Materials",
Expand All @@ -464,7 +465,7 @@ function CraftSim.LOCAL_EN:GetData()
[CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_BUTTON_ROW_LABEL_WRONG_PROFESSION] = "Wrong Profession",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_BUTTON_ROW_LABEL_ON_COOLDOWN] = "On Cooldown",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_REAGENT_INFO_HEADER] = "Reagents",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_REAGENT_INFO_BUTTON_LABEL] = "Reagents (Hover)",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_REAGENT_INFO_BUTTON_LABEL] = "?",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_NEXT_BUTTON_LABEL] = "Craft Next",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_AVAILABLE_AMOUNT] = "Craftable",
[CraftSim.CONST.TEXT.CRAFTQUEUE_AUCTIONATOR_SHOPPING_LIST_BUTTON_LABEL] = "Create Auctionator Shopping List",
Expand All @@ -491,5 +492,7 @@ greater or equal the configured sale rate threshold.
[CraftSim.CONST.TEXT.CRAFT_QUEUE_RESTOCK_OPTIONS_ENABLE_RECIPE_LABEL] = "Enable:",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_RESTOCK_OPTIONS_GENERAL_OPTIONS_LABEL] = "General Options (All Recipes)",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_RESTOCK_OPTIONS_ENABLE_RECIPE_TOOLTIP] = "If this is toggled off, the recipe will be restocked based on the general options above",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_TOTAL_PROFIT_LABEL] = "Total Ø Profit:",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_TOTAL_CRAFTING_COSTS_LABEL] = "Total Crafting Costs:",
}
end
18 changes: 12 additions & 6 deletions Modules/CraftQueue/CraftQueue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CraftSim.CRAFTQ.CraftSimCalledCraftRecipe = false
--- if canCraft and such functions are not called by craftqueue it should be nil
CraftSim.CRAFTQ.itemCountCache = nil

CraftSim.CRAFTQ.useAuctionatorShoppingListAPI = false

local print=CraftSim.UTIL:SetDebugPrint(CraftSim.CONST.DEBUG_IDS.CRAFTQ)

---@param itemID number
Expand Down Expand Up @@ -227,7 +229,7 @@ function CraftSim.CRAFTQ:CreateAuctionatorShoppingList()
end
end

if not Auctionator.API.v1.CreateShoppingList then
if not CraftSim.CRAFTQ.useAuctionatorShoppingListAPI then
print("NOT Using Auctionator.API.v1.CreateShoppingList new API")
-- create shoppinglist import string?
-- format: Test^"Frostfire Alloy";;0;0;0;0;0;0;0;0;;3;;#;;99
Expand Down Expand Up @@ -259,18 +261,22 @@ function CraftSim.CRAFTQ:CreateAuctionatorShoppingList()
Auctionator.Shopping.Lists.BatchImportFromString(shoppingListImportString)
else
print("Using Auctionator.API.v1.CreateShoppingList new API")
--- convert to Auctionator Search Terms and deduct item count
local searchTerms = CraftSim.GUTIL:Map(reagentMap, function (info, itemID)
--- convert to Auctionator Search Strings and deduct item count
local searchStrings = CraftSim.GUTIL:Map(reagentMap, function (info, itemID)
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCache(itemID, true, false, true)
return {
local searchTerm = {
searchString = info.itemName,
categoryKey = "",
tier = info.qualityID,
quantity = math.max(info.quantity - itemCount, 0),
isExact = true,
}
if searchTerm.quantity == 0 then
return nil -- do not put into table
end
local searchString = Auctionator.API.v1.ConvertToSearchString(CraftSimAddonName, searchTerm)
return searchString
end)
Auctionator.API.v1.CreateShoppingList(CraftSimAddonName, CraftSim.CONST.AUCTIONATOR_SHOPPING_LIST_QUEUE_NAME, searchTerms)
Auctionator.API.v1.CreateShoppingList(CraftSimAddonName, CraftSim.CONST.AUCTIONATOR_SHOPPING_LIST_QUEUE_NAME, searchStrings)
end

CraftSim.UTIL:StopProfiling("CreateAuctionatorShopping")
Expand Down
107 changes: 82 additions & 25 deletions Modules/CraftQueue/Frames.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local print=CraftSim.UTIL:SetDebugPrint(CraftSim.CONST.DEBUG_IDS.CRAFTQ)


function CraftSim.CRAFTQ.FRAMES:Init()
local sizeX=930
local sizeX=1000
local sizeY=420

---@class CraftSim.CraftQueue.Frame : GGUI.Frame
Expand All @@ -29,17 +29,20 @@ function CraftSim.CRAFTQ.FRAMES:Init()
---@param frame CraftSim.CraftQueue.Frame
local function createContent(frame)

local tabContentSizeX = 930
local tabContentSizeY = 330

---@type GGUI.Tab
frame.content.queueTab = CraftSim.GGUI.Tab({
buttonOptions={parent=frame.content, anchorParent=frame.title.frame, anchorA="TOP", anchorB="BOTTOM", offsetX=-62, offsetY=-20,
label=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFT_QUEUE_QUEUE_TAB_LABEL), adjustWidth=true},
parent=frame.content,anchorParent=frame.content, sizeX=930, sizeY=400, canBeEnabled=true, offsetY=-30,
parent=frame.content,anchorParent=frame.content, sizeX=tabContentSizeX, sizeY=tabContentSizeY, canBeEnabled=true, offsetY=-30,
})
---@type GGUI.Tab
frame.content.restockOptionsTab = CraftSim.GGUI.Tab({
buttonOptions={parent=frame.content, anchorParent=frame.content.queueTab.button.frame, anchorA="LEFT", anchorB="RIGHT", offsetX=5,
label=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFT_QUEUE_RESTOCK_OPTIONS_TAB_LABEL), adjustWidth=true},
parent=frame.content,anchorParent=frame.content, sizeX=930, sizeY=400, canBeEnabled=true, offsetY=-30,
parent=frame.content,anchorParent=frame.content, sizeX=tabContentSizeX, sizeY=tabContentSizeY, canBeEnabled=true, offsetY=-30,
})
local restockOptionsTab = frame.content.restockOptionsTab
local queueTab = frame.content.queueTab
Expand All @@ -58,26 +61,31 @@ function CraftSim.CRAFTQ.FRAMES:Init()
},
{
label=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.RECIPE_SCAN_AVERAGE_PROFIT_HEADER),
width=140,
width=120,
},
{
label=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFT_QUEUE_REAGENT_INFO_HEADER),
label=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFTING_COSTS_HEADER),
width=100,
justifyOptions={type="H", align="RIGHT"}
},
{
label=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFT_QUEUE_REAGENT_INFO_HEADER),
width=75,
justifyOptions={type="H", align="CENTER"}
},
{
label=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_PROFESSION_GEAR_HEADER), -- here a button is needed to switch to the top gear for this recipe
width=150,
width=110,
justifyOptions={type="H", align="CENTER"}
},
{
label=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_AVAILABLE_AMOUNT),
width=80,
width=100,
justifyOptions={type="H", align="CENTER"}
},
{
label=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_AMOUNT_LEFT_HEADER),
width=80,
width=60,
justifyOptions={type="H", align="CENTER"}
},
{
Expand All @@ -95,19 +103,20 @@ function CraftSim.CRAFTQ.FRAMES:Init()
---@type GGUI.FrameList
queueTab.content.craftList = CraftSim.GGUI.FrameList({
parent = queueTab.content, anchorParent=frame.title.frame, anchorA="TOP", anchorB="TOP",
showHeaderLine=true, scale=0.95,
showHeaderLine=true, scale=0.95, showBorder=true,
sizeY=230, offsetY=-90,
columnOptions=columnOptions,
rowConstructor=function (columns)
local switchToRecipeColumn = columns[1]
local recipeColumn = columns[2]
local averageProfitColumn = columns[3]
local reagentInfoColumn = columns[4]
local topGearColumn = columns[5]
local craftableColumn = columns[6]
local craftAmountColumn = columns[7]
local craftButtonColumn = columns[8]
local removeRowColumn = columns[9]
local craftingCostsColumn = columns[4]
local reagentInfoColumn = columns[5]
local topGearColumn = columns[6]
local craftableColumn = columns[7]
local craftAmountColumn = columns[8]
local craftButtonColumn = columns[9]
local removeRowColumn = columns[10]

switchToRecipeColumn.switchButton = CraftSim.GGUI.Button({
parent=switchToRecipeColumn,anchorParent=switchToRecipeColumn, sizeX=25, sizeY=25,
Expand All @@ -128,6 +137,12 @@ function CraftSim.CRAFTQ.FRAMES:Init()
{
parent=averageProfitColumn,anchorParent=averageProfitColumn, anchorA="LEFT", anchorB="LEFT", scale = 0.9,

})
---@type GGUI.Text | GGUI.Widget
craftingCostsColumn.text = CraftSim.GGUI.Text(
{
parent=craftingCostsColumn,anchorParent=craftingCostsColumn, anchorA="RIGHT", anchorB="RIGHT", scale = 0.9, justifyOptions={type="H",align="RIGHT"}

})

reagentInfoColumn.reagentInfoButton = CraftSim.GGUI.HelpIcon({
Expand Down Expand Up @@ -185,9 +200,11 @@ function CraftSim.CRAFTQ.FRAMES:Init()
end
})

local craftQueueButtonsOffsetY=-5

---@type GGUI.Button
queueTab.content.importRecipeScanButton = CraftSim.GGUI.Button({
parent=queueTab.content, anchorParent=queueTab.content.craftList.frame, anchorA="TOPLEFT", anchorB="BOTTOMLEFT", offsetY=0, offsetX=0,
parent=queueTab.content, anchorParent=queueTab.content.craftList.frame, anchorA="TOPLEFT", anchorB="BOTTOMLEFT", offsetY=craftQueueButtonsOffsetY, offsetX=0,
adjustWidth=true,
label=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFT_QUEUE_IMPORT_RECIPE_SCAN_BUTTON_LABEL), clickCallback=function ()
CraftSim.CRAFTQ:ImportRecipeScan()
Expand All @@ -214,7 +231,7 @@ function CraftSim.CRAFTQ.FRAMES:Init()

---@type GGUI.Button
queueTab.content.craftNextButton = CraftSim.GGUI.Button({
parent=queueTab.content, anchorParent=queueTab.content.craftList.frame, anchorA="TOPRIGHT", anchorB="BOTTOMRIGHT", offsetY=0, offsetX=0,
parent=queueTab.content, anchorParent=queueTab.content.craftList.frame, anchorA="TOPRIGHT", anchorB="BOTTOMRIGHT", offsetY=craftQueueButtonsOffsetY, offsetX=0,
adjustWidth=true,
label=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFT_QUEUE_CRAFT_NEXT_BUTTON_LABEL), clickCallback=nil
})
Expand All @@ -223,14 +240,33 @@ function CraftSim.CRAFTQ.FRAMES:Init()
if select(2, C_AddOns.IsAddOnLoaded(CraftSim.CONST.SUPPORTED_PRICE_API_ADDONS[2])) then
---@type GGUI.Button
queueTab.content.createAuctionatorShoppingList = CraftSim.GGUI.Button({
parent=queueTab.content, anchorParent=queueTab.content.craftList.frame, anchorA="TOP", anchorB="BOTTOM", adjustWidth=true,
parent=queueTab.content, anchorParent=queueTab.content, anchorA="BOTTOM", anchorB="BOTTOM", adjustWidth=true, offsetY=0,
clickCallback=function ()
CraftSim.CRAFTQ:CreateAuctionatorShoppingList()
end,
label=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFTQUEUE_AUCTIONATOR_SHOPPING_LIST_BUTTON_LABEL)
})
end

-- summaries

queueTab.content.totalAverageProfitLabel = CraftSim.GGUI.Text({parent=queueTab.content, anchorParent=queueTab.content.importRecipeScanButton.frame,
scale=0.9*0.9, anchorA="LEFT", anchorB="RIGHT", offsetX=10, text=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFT_QUEUE_TOTAL_PROFIT_LABEL),
justifyOptions={type="H", align="RIGHT"}
})
queueTab.content.totalAverageProfit = CraftSim.GGUI.Text({parent=queueTab.content, anchorParent=queueTab.content.totalAverageProfitLabel.frame,
scale=0.9*0.9, anchorA="LEFT", anchorB="RIGHT", offsetX=5, text=CraftSim.GUTIL:FormatMoney(0, true),
justifyOptions={type="H", align="LEFT"}
})
queueTab.content.totalCraftingCostsLabel = CraftSim.GGUI.Text({parent=queueTab.content, anchorParent=queueTab.content.totalAverageProfitLabel.frame,
scale=0.9*0.9, anchorA="TOPRIGHT", anchorB="BOTTOMRIGHT", offsetY=-19, text=CraftSim.LOCAL:GetText(CraftSim.CONST.TEXT.CRAFT_QUEUE_TOTAL_CRAFTING_COSTS_LABEL),
justifyOptions={type="H", align="RIGHT"}
})
queueTab.content.totalCraftingCosts = CraftSim.GGUI.Text({parent=queueTab.content, anchorParent=queueTab.content.totalCraftingCostsLabel.frame,
scale=0.9*0.9, anchorA="LEFT", anchorB="RIGHT", offsetX=5, text=CraftSim.GUTIL:FormatMoney(0, true),
justifyOptions={type="H", align="RIGHT"}
})

-- restock Options

restockOptionsTab.content.generalOptionsFrame = CreateFrame("frame", nil, restockOptionsTab.content)
Expand Down Expand Up @@ -401,13 +437,16 @@ function CraftSim.CRAFTQ.FRAMES:Init()
end

function CraftSim.CRAFTQ.FRAMES:UpdateFrameListByCraftQueue()
local f = CraftSim.UTIL:GetFormatter()
-- multiples should be possible (different reagent setup)
-- but if there already is a configuration just increase the count?

CraftSim.UTIL:StartProfiling("FrameListUpdate")

---@type GGUI.Tab
local queueTab = CraftSim.CRAFTQ.frame.content.queueTab
---@type GGUI.FrameList
local craftList = CraftSim.CRAFTQ.frame.content.queueTab.content.craftList
local craftList = queueTab.content.craftList

local craftQueue = CraftSim.CRAFTQ.craftQueue or CraftSim.CraftQueue({})

Expand Down Expand Up @@ -447,31 +486,45 @@ function CraftSim.CRAFTQ.FRAMES:UpdateFrameListByCraftQueue()

craftList:Remove()

local totalAverageProfit = 0
local totalCraftingCosts = 0
local totalReagents = {}

CraftSim.UTIL:StartProfiling("- FrameListUpdate Add Rows")
for _, craftQueueItem in pairs(craftQueue.craftQueueItems) do
local recipeData = craftQueueItem.recipeData
craftList:Add(
function (row)

local profilingID = "- FrameListUpdate Add Recipe: " .. craftQueueItem.recipeData.recipeName
CraftSim.UTIL:StartProfiling(profilingID)
local columns = row.columns
local switchToRecipeColumn = columns[1]
local recipeColumn = columns[2]
local averageProfitColumn = columns[3]
local reagentInfoColumn = columns[4]
local topGearColumn = columns[5]
local craftAbleColumn = columns[6]
local craftAmountColumn = columns[7]
local craftButtonColumn = columns[8]
local removeRowColumn = columns[9]
local craftingCostsColumn = columns[4]
local reagentInfoColumn = columns[5]
local topGearColumn = columns[6]
local craftAbleColumn = columns[7]
local craftAmountColumn = columns[8]
local craftButtonColumn = columns[9]
local removeRowColumn = columns[10]

switchToRecipeColumn.switchButton:SetEnabled(craftQueueItem.correctProfessionOpen)
switchToRecipeColumn.switchButton.recipeID = recipeData.recipeID

local averageProfit = recipeData.averageProfitCached or recipeData:GetAverageProfit()
totalAverageProfit = totalAverageProfit + averageProfit
recipeColumn.text:SetText(recipeData.recipeName)
averageProfitColumn.text:SetText(CraftSim.GUTIL:FormatMoney(select(1, averageProfit), true, recipeData.priceData.craftingCosts))

-- update price data and profit?
recipeData.priceData:Update()
recipeData:GetAverageProfit()
local craftingCosts = recipeData.priceData.craftingCosts
totalCraftingCosts = totalCraftingCosts + craftingCosts
craftingCostsColumn.text:SetText(f.r(CraftSim.GUTIL:FormatMoney(craftingCosts)))

reagentInfoColumn.reagentInfoButton:SetText(recipeData.reagentData:GetTooltipText(craftQueueItem.amount))

if craftQueueItem.gearEquipped then
Expand Down Expand Up @@ -557,6 +610,10 @@ function CraftSim.CRAFTQ.FRAMES:UpdateFrameListByCraftQueue()
--- sort by craftable status
craftList:UpdateDisplay()

queueTab.content.totalAverageProfit:SetText(CraftSim.GUTIL:FormatMoney(totalAverageProfit, true, totalCraftingCosts))
queueTab.content.totalCraftingCosts:SetText(f.r(CraftSim.GUTIL:FormatMoney(totalCraftingCosts)))


CraftSim.UTIL:StopProfiling("FrameListUpdate")
end

Expand Down
3 changes: 3 additions & 0 deletions Util/Const.lua
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ CraftSim.CONST.TEXT = {
CRAFT_QUEUE_TITLE = "CRAFT_QUEUE_TITLE",
CRAFT_QUEUE_CRAFT_AMOUNT_LEFT_HEADER= "CRAFT_QUEUE_CRAFT_AMOUNT_LEFT_HEADER",
CRAFT_QUEUE_CRAFT_PROFESSION_GEAR_HEADER = "CRAFT_QUEUE_CRAFT_PROFESSION_GEAR_HEADER",
CRAFT_QUEUE_CRAFTING_COSTS_HEADER = "CRAFT_QUEUE_CRAFTING_COSTS_HEADER",
CRAFT_QUEUE_CRAFT_BUTTON_ROW_LABEL = "CRAFT_QUEUE_CRAFT_BUTTON_ROW_LABEL",
CRAFT_QUEUE_CRAFT_BUTTON_ROW_LABEL_WRONG_GEAR = "CRAFT_QUEUE_CRAFT_BUTTON_ROW_LABEL_WRONG_GEAR",
CRAFT_QUEUE_CRAFT_BUTTON_ROW_LABEL_NO_MATS = "CRAFT_QUEUE_CRAFT_BUTTON_ROW_LABEL_NO_MATS",
Expand All @@ -933,6 +934,8 @@ CraftSim.CONST.TEXT = {
CRAFT_QUEUE_RESTOCK_OPTIONS_ENABLE_RECIPE_TOOLTIP = "CRAFT_QUEUE_RESTOCK_OPTIONS_ENABLE_RECIPE_TOOLTIP",
CRAFT_QUEUE_RESTOCK_OPTIONS_GENERAL_OPTIONS_LABEL = "CRAFT_QUEUE_RESTOCK_OPTIONS_GENERAL_OPTIONS_LABEL",
CRAFT_QUEUE_RESTOCK_OPTIONS_TSM_SALE_RATE_TOOLTIP_GENERAL = "CRAFT_QUEUE_RESTOCK_OPTIONS_TSM_SALE_RATE_TOOLTIP_GENERAL",
CRAFT_QUEUE_TOTAL_PROFIT_LABEL = "CRAFT_QUEUE_TOTAL_PROFIT_LABEL",
CRAFT_QUEUE_TOTAL_CRAFTING_COSTS_LABEL = "CRAFT_QUEUE_TOTAL_CRAFTING_COSTS_LABEL",
}

CraftSim.CONST.IMPLEMENTED_SKILL_BUILD_UP = function()
Expand Down

0 comments on commit 64b3284

Please sign in to comment.