@ -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