Skip to content

Instantly share code, notes, and snippets.

@kesor
Last active December 9, 2018 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kesor/243ea31b14efab37204dcf2b4a0ed890 to your computer and use it in GitHub Desktop.
Save kesor/243ea31b14efab37204dcf2b4a0ed890 to your computer and use it in GitHub Desktop.
TradeSkillMaster Crafting Operation restock quantity from CustomPrice source
diff --git a/Core/Service/Crafting/Core.lua b/Core/Service/Crafting/Core.lua
index c2e2bf3..752013f 100644
--- a/Core/Service/Crafting/Core.lua
+++ b/Core/Service/Crafting/Core.lua
@@ -548,7 +548,10 @@ function Crafting.RestockHelp(link)
end
+ local maxRestock = TSMAPI_FOUR.CustomPrice.GetValue(opSettings.maxRestock, itemString)
+ local minRestock = TSMAPI_FOUR.CustomPrice.GetValue(opSettings.minRestock, itemString)
+
-- check if it's an invalid operation
- if opSettings.minRestock > opSettings.maxRestock then
- return print(format(L["The operation applied to this item is invalid! Min restock of %d is higher than max restock of %d."], opSettings.minRestock, opSettings.maxRestock))
+ if minRestock > maxRestock then
+ return print(format(L["The operation applied to this item is invalid! Min restock of %d is higher than max restock of %d."], minRestock, maxRestock))
end
@@ -560,8 +563,8 @@ function Crafting.RestockHelp(link)
-- check the restock quantity
local numHave = TSMAPI_FOUR.Inventory.GetTotalQuantity(itemString)
- if numHave >= opSettings.maxRestock then
- return print(format(L["You already have at least your max restock quantity of this item. You have %d and the max restock quantity is %d"], numHave, opSettings.maxRestock))
- elseif (opSettings.maxRestock - numHave) < opSettings.minRestock then
- return print(format(L["The number which would be queued (%d) is less than the min restock quantity (%d)."], (opSettings.maxRestock - numHave), opSettings.minRestock))
+ if numHave >= maxRestock then
+ return print(format(L["You already have at least your max restock quantity of this item. You have %d and the max restock quantity is %d"], numHave, maxRestock))
+ elseif (maxRestock - numHave) < minRestock then
+ return print(format(L["The number which would be queued (%d) is less than the min restock quantity (%d)."], (maxRestock - numHave), minRestock))
end
diff --git a/Core/Service/Crafting/Queue.lua b/Core/Service/Crafting/Queue.lua
index dba6c34..95d30e2 100644
--- a/Core/Service/Crafting/Queue.lua
+++ b/Core/Service/Crafting/Queue.lua
@@ -143,7 +143,10 @@ end
function private.IsOperationValid(operationName, operationSettings)
- if operationSettings.minRestock > operationSettings.maxRestock then
+ local maxRestock = TSMAPI_FOUR.CustomPrice.GetValue(opSettings.maxRestock, itemString)
+ local minRestock = TSMAPI_FOUR.CustomPrice.GetValue(opSettings.minRestock, itemString)
+
+ if minRestock > maxRestock then
-- invalid cause min > max restock quantity (shouldn't happen)
- TSM:Printf(L["'%s' is an invalid operation! Min restock of %d is higher than max restock of %d."], operationName, operationSettings.minRestock, operationSettings.maxRestock)
+ TSM:Printf(L["'%s' is an invalid operation! Min restock of %d is higher than max restock of %d."], operationName, minRestock, maxRestock)
return false
end
@@ -188,9 +191,13 @@ function private.RestockItem(itemString, operationSettings)
end
assert(haveQuantity >= 0)
- local neededQuantity = operationSettings.maxRestock - haveQuantity
+
+ local maxRestock = TSMAPI_FOUR.CustomPrice.GetValue(opSettings.maxRestock, itemString)
+ local minRestock = TSMAPI_FOUR.CustomPrice.GetValue(opSettings.minRestock, itemString)
+
+ local neededQuantity = maxRestock - haveQuantity
if neededQuantity <= 0 then
-- don't need to queue any
return
- elseif neededQuantity < operationSettings.minRestock then
+ elseif neededQuantity < minRestock then
-- we're below the min restock quantity
return
diff --git a/Core/Service/Operations/Crafting.lua b/Core/Service/Operations/Crafting.lua
index 7759a1c..6ddafa7 100644
--- a/Core/Service/Operations/Crafting.lua
+++ b/Core/Service/Operations/Crafting.lua
@@ -12,6 +12,6 @@ local private = {}
local L = TSM.L
local OPERATION_INFO = {
- minRestock = { type = "number", default = 1 },
- maxRestock = { type = "number", default = 3 },
+ minRestock = { type = "string", default = "1" },
+ maxRestock = { type = "string", default = "3" },
minProfit = { type = "string", default = "100g" },
craftPriceMethod = { type = "string", default = "" },
@@ -35,8 +35,11 @@ end
function private.GetOperationInfo(operationSettings)
+ local maxRestock = TSMAPI_FOUR.CustomPrice.GetValue(opSettings.maxRestock, itemString)
+ local minRestock = TSMAPI_FOUR.CustomPrice.GetValue(opSettings.minRestock, itemString)
+
if operationSettings.minProfit ~= "" then
- return format(L["Restocking to a max of %d (min of %d) with a min profit."], operationSettings.maxRestock, operationSettings.minRestock)
+ return format(L["Restocking to a max of %d (min of %d) with a min profit."], maxRestock, minRestock)
else
- return format(L["Restocking to a max of %d (min of %d) with no min profit."], operationSettings.maxRestock, operationSettings.minRestock)
+ return format(L["Restocking to a max of %d (min of %d) with no min profit."], maxRestock, minRestock)
end
end
diff --git a/Core/UI/MainUI/Operations/Crafting.lua b/Core/UI/MainUI/Operations/Crafting.lua
index f93aa67..5c006c8 100644
--- a/Core/UI/MainUI/Operations/Crafting.lua
+++ b/Core/UI/MainUI/Operations/Crafting.lua
@@ -44,6 +44,38 @@ function private.GetCraftingOperationSettings(operationName)
:SetStyle("padding.top", -8)
:AddChild(TSM.MainUI.Operations.CreateHeadingLine("restockQuantity", L["Restock Quantity Settings"]))
- :AddChild(private.CreateNumericInputLine("minRestock", L["Minimum restock quantity:"], 1, 2000))
- :AddChild(private.CreateNumericInputLine("maxRestock", L["Maximum restock quantity:"], 1, 2000))
+ :AddChild(TSMAPI_FOUR.UI.NewElement("Frame", "minRestockInputFrame")
+ :SetLayout("VERTICAL")
+ :AddChild(TSM.MainUI.Operations.CreateLinkedSettingLine("minRestock", L["Minimum restock quantity:"], operation.minRestock == "")
+ :AddChild(TSMAPI_FOUR.UI.NewElement("Input", "input")
+ :SetStyle("background", "#5c5c5c")
+ :SetStyle("font", TSM.UI.Fonts.MontserratMedium)
+ :SetStyle("fontHeight", 16)
+ :SetStyle("justifyH", "LEFT")
+ :SetStyle("textColor", "#ffffff")
+ :SetDisabled(TSM.Operations.HasRelationship("Crafting", private.currentOperationName, "minRestock") or operation.minRestock == "")
+ :SetSettingInfo(operation, "minRestock", TSM.MainUI.Operations.CheckCustomPrice)
+ :SetText(operation.minRestock)
+ )
+ )
+ )
+ :AddChild(TSMAPI_FOUR.UI.NewElement("Frame", "maxRestockInputFrame")
+ :SetLayout("VERTICAL")
+ :AddChild(TSM.MainUI.Operations.CreateLinkedSettingLine("maxRestock", L["Maximum restock quantity:"], operation.maxRestock == "")
+ :AddChild(TSMAPI_FOUR.UI.NewElement("Input", "input")
+ :SetStyle("background", "#5c5c5c")
+ :SetStyle("font", TSM.UI.Fonts.MontserratMedium)
+ :SetStyle("fontHeight", 16)
+ :SetStyle("justifyH", "LEFT")
+ :SetStyle("textColor", "#ffffff")
+ :SetDisabled(TSM.Operations.HasRelationship("Crafting", private.currentOperationName, "maxRestock") or operation.maxRestock == "")
+ :SetSettingInfo(operation, "maxRestock", TSM.MainUI.Operations.CheckCustomPrice)
+ :SetText(operation.maxRestock)
+ )
+ )
+ )
:AddChild(TSM.MainUI.Operations.CreateLinkedSettingLine("minProfit", L["Set minimum profit?"])
:AddChild(TSMAPI_FOUR.UI.NewElement("Frame", "minProfitEnabledFrame")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment