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