Browse Source

add more custom price options

dev
Jørgen Lien Sellæg 4 months ago
parent
commit
8ec1d3fd08
  1. 73
      TradeSkillMaster/Core/Prices.lua
  2. 4
      TradeSkillMaster_Accounting/Locale/enUS.lua
  3. 36
      TradeSkillMaster_Accounting/TradeSkillMaster_Accounting.lua

73
TradeSkillMaster/Core/Prices.lua

@ -28,6 +28,14 @@ local MATH_FUNCTIONS = {
["max"] = "_max", ["max"] = "_max",
["first"] = "_first", ["first"] = "_first",
["check"] = "_check", ["check"] = "_check",
["ifgt"] = "_ifgt",
["ifgte"] = "_ifgte",
["iflt"] = "_iflt",
["iflte"] = "_iflte",
["ifeq"] = "_ifeq",
["round"] = "_round",
["roundup"] = "_roundup",
["rounddown"] = "_rounddown",
} }
function TSMAPI:GetPriceSources() function TSMAPI:GetPriceSources()
@ -68,7 +76,7 @@ end
-- validates a price string that was passed into TSMAPI:ParseCustomPrice -- validates a price string that was passed into TSMAPI:ParseCustomPrice
local supportedOperators = { "+", "-", "*", "/" } local supportedOperators = { "+", "-", "*", "/", "^" }
local function ParsePriceString(str, badPriceSource) local function ParsePriceString(str, badPriceSource)
if tonumber(str) then if tonumber(str) then
return function() return tonumber(str) end return function() return tonumber(str) end
@ -396,6 +404,67 @@ local function ParsePriceString(str, badPriceSource)
elseValue = elseValue or NAN elseValue = elseValue or NAN
return check > 0 and ifValue or elseValue return check > 0 and ifValue or elseValue
end end
local function _ifgt(...)
local a, b, c, d = ...
if isNAN(a) or isNAN(b) then return NAN end
if a > b then
return (c and not isNAN(c)) and c or NAN
end
return (d and not isNAN(d)) and d or NAN
end
local function _ifgte(...)
local a, b, c, d = ...
if isNAN(a) or isNAN(b) then return NAN end
if a >= b then
return (c and not isNAN(c)) and c or NAN
end
return (d and not isNAN(d)) and d or NAN
end
local function _iflt(...)
local a, b, c, d = ...
if isNAN(a) or isNAN(b) then return NAN end
if a < b then
return (c and not isNAN(c)) and c or NAN
end
return (d and not isNAN(d)) and d or NAN
end
local function _iflte(...)
local a, b, c, d = ...
if isNAN(a) or isNAN(b) then return NAN end
if a <= b then
return (c and not isNAN(c)) and c or NAN
end
return (d and not isNAN(d)) and d or NAN
end
local function _ifeq(...)
local a, b, c, d = ...
if isNAN(a) or isNAN(b) then return NAN end
if a == b then
return (c and not isNAN(c)) and c or NAN
end
return (d and not isNAN(d)) and d or NAN
end
local function _round(...)
local a, b = ...
if isNAN(a) then return NAN end
b = b or 1
if isNAN(b) or b == 0 then return NAN end
return floor(a / b + 0.5) * b
end
local function _roundup(...)
local a, b = ...
if isNAN(a) then return NAN end
b = b or 1
if isNAN(b) or b == 0 then return NAN end
return ceil(a / b) * b
end
local function _rounddown(...)
local a, b = ...
if isNAN(a) then return NAN end
b = b or 1
if isNAN(b) or b == 0 then return NAN end
return floor(a / b) * b
end
local values = {} local values = {}
for i, params in ipairs({%s}) do for i, params in ipairs({%s}) do
local itemString, key, extraParam = unpack(params) local itemString, key, extraParam = unpack(params)
@ -455,4 +524,4 @@ function TSMAPI:GetCustomPriceSourceValue(itemString, key)
local func = TSMAPI:ParseCustomPrice(source) local func = TSMAPI:ParseCustomPrice(source)
if not func then return end if not func then return end
return func(itemString) return func(itemString)
end end

4
TradeSkillMaster_Accounting/Locale/enUS.lua

@ -81,6 +81,8 @@ L["Market Value Source"] = true
L["Market Value"] = true L["Market Value"] = true
L["Max Buy Price"] = true L["Max Buy Price"] = true
L["Max Sell Price"] = true L["Max Sell Price"] = true
L["Min Buy Price"] = true
L["Min Sell Price"] = true
L["None"] = true L["None"] = true
L["Options"] = true L["Options"] = true
L["Other Income"] = true L["Other Income"] = true
@ -150,4 +152,4 @@ L["YY/MM/DD HH:MM"] = true
L["Yesterday"] = true L["Yesterday"] = true
L["You can use the options below to clear old data. It is recommened to occasionally clear your old data to keep Accounting running smoothly. Select the minimum number of days old to be removed in the dropdown, then click the button.\n\nNOTE: There is no confirmation."] = true L["You can use the options below to clear old data. It is recommened to occasionally clear your old data to keep Accounting running smoothly. Select the minimum number of days old to be removed in the dropdown, then click the button.\n\nNOTE: There is no confirmation."] = true
L["_ Hr _ Min ago"] = true L["_ Hr _ Min ago"] = true
L["none"] = true L["none"] = true

36
TradeSkillMaster_Accounting/TradeSkillMaster_Accounting.lua

@ -127,6 +127,8 @@ function TSM:RegisterModule()
{ key = "avgBuy", label = L["Avg Buy Price"], callback = "GetAvgBuyPrice" }, { key = "avgBuy", label = L["Avg Buy Price"], callback = "GetAvgBuyPrice" },
{ key = "maxSell", label = L["Max Sell Price"], callback = "GetMaxSellPrice" }, { key = "maxSell", label = L["Max Sell Price"], callback = "GetMaxSellPrice" },
{ key = "maxBuy", label = L["Max Buy Price"], callback = "GetMaxBuyPrice" }, { key = "maxBuy", label = L["Max Buy Price"], callback = "GetMaxBuyPrice" },
{ key = "minSell", label = L["Min Sell Price"], callback = "GetMinSellPrice" },
{ key = "minBuy", label = L["Min Buy Price"], callback = "GetMinBuyPrice" },
} }
TSM.tooltipOptions = { callback = "GUI:LoadTooltipOptions" } TSM.tooltipOptions = { callback = "GUI:LoadTooltipOptions" }
@ -496,6 +498,22 @@ function TSM:GetMaxSellPrice(itemString)
return TSM.cache[itemString].maxSellPrice return TSM.cache[itemString].maxSellPrice
end end
function TSM:GetMinSellPrice(itemString)
itemString = TSMAPI:GetItemString(select(2, TSMAPI:GetSafeItemInfo(itemString)))
if not (itemString and TSM.items[itemString] and #TSM.items[itemString].sales > 0) then return end
TSM.cache[itemString] = TSM.cache[itemString] or {}
if not TSM.cache[itemString].minSellPrice then
local minPrice = math.huge
for _, record in ipairs(TSM.items[itemString].sales) do
minPrice = min(minPrice, record.copper)
end
TSM.cache[itemString].minSellPrice = minPrice
end
return TSM.cache[itemString].minSellPrice
end
function TSM:GetMaxBuyPrice(itemString) function TSM:GetMaxBuyPrice(itemString)
itemString = TSMAPI:GetItemString(select(2, TSMAPI:GetSafeItemInfo(itemString))) itemString = TSMAPI:GetItemString(select(2, TSMAPI:GetSafeItemInfo(itemString)))
if not (itemString and TSM.items[itemString] and #TSM.items[itemString].buys > 0) then return end if not (itemString and TSM.items[itemString] and #TSM.items[itemString].buys > 0) then return end
@ -512,9 +530,25 @@ function TSM:GetMaxBuyPrice(itemString)
return TSM.cache[itemString].maxBuyPrice return TSM.cache[itemString].maxBuyPrice
end end
function TSM:GetMinBuyPrice(itemString)
itemString = TSMAPI:GetItemString(select(2, TSMAPI:GetSafeItemInfo(itemString)))
if not (itemString and TSM.items[itemString] and #TSM.items[itemString].buys > 0) then return end
TSM.cache[itemString] = TSM.cache[itemString] or {}
if not TSM.cache[itemString].minBuyPrice then
local minPrice = math.huge
for _, record in ipairs(TSM.items[itemString].buys) do
minPrice = min(minPrice, record.copper)
end
TSM.cache[itemString].minBuyPrice = minPrice
end
return TSM.cache[itemString].minBuyPrice
end
function TSM:Round(value, sig) function TSM:Round(value, sig)
sig = sig or 1 sig = sig or 1
local gold = value / sig local gold = value / sig
gold = floor(gold + 0.5) gold = floor(gold + 0.5)
return gold * sig return gold * sig
end end

Loading…
Cancel
Save