Skip to content

Commit

Permalink
Feature/send2craftqueue (#670)
Browse files Browse the repository at this point in the history
* wip

* finished
  • Loading branch information
derfloh205 authored Oct 31, 2024
1 parent f37624c commit 76c7722
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 172 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 the war within gold making
## Author: genju
## Version: 19.2.0
## Version: 19.3.0
## X-Curse-Project-ID: 705015
## X-Wago-ID: 0mNwaPKo
## X-WoWI-ID: 26519
Expand Down
8 changes: 7 additions & 1 deletion Data/News.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ function CraftSim.NEWS:GET_NEWS(itemMap)
local news = {
f.bb(" Hello and thank you for using CraftSim!\n"),
f.bb(" ( You are awesome! )"),
newP("19.3.0"),
f.P .. "Reintroduced " .. f.g("Restock from Scan"),
f.a .. "- Now called " .. f.bb("'Send to CraftQueue'"),
f.a .. "- Moved to Recipe Scan Module",
f.P .. f.bb("UI Improvements") .. " for Scan Options",
f.a .. "- Will be further moved into context menus in future updates",
newP("19.2.0"),
f.p .. "Restock Favorites Feature added",
f.a .. f.bb("Experimental") .. " - More Options will come soon",
f.a .. f.bb("Experimental") .. " - More Options will come soon",
newP("19.1.0"),
f.p .. "11.0.5 Updates",
newP("19.0.1"),
Expand Down
2 changes: 1 addition & 1 deletion Locals/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ function CraftSim.LOCAL_EN:GetData()
[CraftSim.CONST.TEXT.CRAFT_QUEUE_ADD_PATRON_ORDERS_ALLOW_CONCENTRATION_TOOLTIP] =
"If minimum quality cannot be reached, use " .. f.l("Concentration") .. " if possible",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_CLEAR_ALL_BUTTON_LABEL] = "Clear All",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_RESTOCK_FAVORITES_BUTTON_LABEL] = "Restock Favorites",
[CraftSim.CONST.TEXT.CRAFT_QUEUE_RESTOCK_FAVORITES_BUTTON_LABEL] = "Queue Favorites",
[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_CRAFT_BUTTON_ROW_LABEL_WRONG_CRAFTER] = "Wrong Crafter",
Expand Down
25 changes: 0 additions & 25 deletions Modules/CraftQueue/CraftQueue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -655,31 +655,6 @@ function CraftSim.CRAFTQ:GetRestockOptionsForRecipe(recipeID)
return restockPerRecipeOptions[recipeID]
end

-- Function to determine the restock quantity for a given expected item.
--
-- This function retrieves the default restock amount from the database options.
-- If a custom restock key for TSM (TradeSkillMaster) is specified, it attempts to get the restock amount
-- using the TSM API based on the expected item's link. If a valid restock amount is found, it returns that value.
-- Otherwise, it falls back to the default restock amount.
--
---@param expectedItem ItemMixin The item for which the restock quantity is being determined.
---@return number restockAmount Restock quantity for the given expected item.
function CraftSim.CRAFTQ:GetRestockQuantity(expectedItem)
local defaultRestockAmount = CraftSim.DB.OPTIONS:Get("CRAFTQUEUE_GENERAL_RESTOCK_RESTOCK_AMOUNT") or 1
local tsmExpressionEnabled = CraftSim.DB.OPTIONS:Get("TSM_RESTOCK_KEY_ITEMS_ENABLED")
if tsmExpressionEnabled and TSM_API and expectedItem and CraftSim.DB.OPTIONS:Get("TSM_RESTOCK_KEY_ITEMS") ~= "" then
local restockAmount = TSM_API.GetCustomPriceValue(CraftSim.DB.OPTIONS:Get("TSM_RESTOCK_KEY_ITEMS"),
TSM_API.ToItemString(expectedItem:GetItemLink()))
if restockAmount ~= nil then
return restockAmount
else
return defaultRestockAmount
end
else
return defaultRestockAmount
end
end

---@param recipeData CraftSim.RecipeData
---@param usedQualitiesTable table<number, boolean>?
---@param saleRateThreshold number
Expand Down
13 changes: 1 addition & 12 deletions Modules/Options/Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ function CraftSim.OPTIONS:InitTSMTab(TSMTab)
adjustWidth = true,
label = L(CraftSim.CONST.TEXT.OPTIONS_TSM_RESET),
clickCallback = function()
tsmRestockExpression:SetText("")
tsmRestockExpression:SetText("1")
end
})

Expand All @@ -431,15 +431,4 @@ function CraftSim.OPTIONS:InitTSMTab(TSMTab)
validationInfoItems:SetPoint("LEFT", tsmRestockExpression, "RIGHT", 5, 0)
validationInfoItems:SetText(CraftSim.GUTIL:ColorizeText(
L(CraftSim.CONST.TEXT.OPTIONS_TSM_VALID_EXPRESSION), CraftSim.GUTIL.COLORS.GREEN))

GGUI.Checkbox {
parent = TSMTab.content,
anchorParent = tsmRestockDefaultButton.frame,
anchorA = "RIGHT", anchorB = "LEFT", offsetX = -15, offsetY = -1,
tooltip = "Enable TSM Restock Expression",
initialValue = CraftSim.DB.OPTIONS:Get("TSM_RESTOCK_KEY_ITEMS_ENABLED"),
clickCallback = function(_, checked)
CraftSim.DB.OPTIONS:Save("TSM_RESTOCK_KEY_ITEMS_ENABLED", checked)
end
}
end
62 changes: 62 additions & 0 deletions Modules/RecipeScan/RecipeScan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,65 @@ function CraftSim.RECIPE_SCAN:EndProfessionScan()
.professionList --[[@as GGUI.FrameList]]
professionList:SetSelectionEnabled(true)
end

function CraftSim.RECIPE_SCAN:SendToCraftQueue()
local professionList = CraftSim.RECIPE_SCAN.frame.content.recipeScanTab.content
.professionList --[[@as GGUI.FrameList]]
local activeRows = professionList.activeRows --[[@as table<number, CraftSim.RECIPE_SCAN.PROFESSION_LIST.ROW>]]

if #activeRows <= 0 then return end

local selectedRow = professionList.selectedRow --[[@as CraftSim.RECIPE_SCAN.PROFESSION_LIST.ROW]]

if not selectedRow then
return
end

local results = selectedRow.currentResults

if #results == 0 then
return
end

local filteredResults = GUTIL:Filter(results, function(recipeData)
local marginThreshold = CraftSim.DB.OPTIONS:Get("RECIPESCAN_SEND_TO_CRAFTQUEUE_PROFIT_MARGIN_THRESHOLD")
local relativeProfit = recipeData.relativeProfitCached
return relativeProfit >= marginThreshold;
end)

local sendToCraftQueueButton = CraftSim.RECIPE_SCAN.frame.content.recipeScanTab.content
.sendToCraftQueueButton --[[@as GGUI.Button]]

sendToCraftQueueButton:SetEnabled(false)

local concentrationEnabled = CraftSim.DB.OPTIONS:Get("RECIPESCAN_ENABLE_CONCENTRATION")

GUTIL.FrameDistributor {
iterationTable = filteredResults,
iterationsPerFrame = 5,
finally = function()
sendToCraftQueueButton:SetStatus("Ready")
end,
continue = function(frameDistributor, _, recipeData, _, progress)
recipeData = recipeData --[[@as CraftSim.RecipeData]]
sendToCraftQueueButton:SetText(string.format("%.0f%%", progress))

if concentrationEnabled and recipeData.supportsQualities then
recipeData.concentrating = true
recipeData:Update()
end

local restockAmount = CraftSim.DB.OPTIONS:Get("RECIPESCAN_SEND_TO_CRAFTQUEUE_DEFAULT_QUEUE_AMOUNT") or 1

if TSM_API and CraftSim.DB.OPTIONS:Get("RECIPESCAN_SEND_TO_CRAFTQUEUE_USE_TSM_RESTOCK_EXPRESSION") then
local tsmItemString = TSM_API.ToItemString(recipeData.resultData.expectedItem:GetItemLink())
restockAmount = TSM_API.GetCustomPriceValue(CraftSim.DB.OPTIONS:Get("TSM_RESTOCK_KEY_ITEMS"),
tsmItemString) or 1
end

CraftSim.CRAFTQ:AddRecipe { recipeData = recipeData, amount = restockAmount }

frameDistributor:Continue()
end
}:Continue()
end
Loading

0 comments on commit 76c7722

Please sign in to comment.