mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
fix(math): torgba types and alpha value
This commit is contained in:
@@ -32,7 +32,7 @@ function math.toscalars(input, min, max, round)
|
|||||||
local i = 0
|
local i = 0
|
||||||
|
|
||||||
for s in string.gmatch(input:gsub('[%w]+%w?%(', ''), '(-?[%w.%w]+)') do
|
for s in string.gmatch(input:gsub('[%w]+%w?%(', ''), '(-?[%w.%w]+)') do
|
||||||
local n = parseNumber(s, min, max, round)
|
local n = parseNumber(s, min, max, round and (round == true or i < round))
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
arr[i] = n
|
arr[i] = n
|
||||||
@@ -45,7 +45,7 @@ end
|
|||||||
---@param input string | table
|
---@param input string | table
|
||||||
---@param min? number
|
---@param min? number
|
||||||
---@param max? number
|
---@param max? number
|
||||||
---@param round? boolean
|
---@param round? boolean | number If round is a number, only round n values.
|
||||||
---@return number | vector2 | vector3 | vector4
|
---@return number | vector2 | vector3 | vector4
|
||||||
function math.tovector(input, min, max, round)
|
function math.tovector(input, min, max, round)
|
||||||
local inputType = type(input)
|
local inputType = type(input)
|
||||||
@@ -89,11 +89,14 @@ function math.normaltorotation(input)
|
|||||||
error(('cannot convert type %s to a rotation vector'):format(inputType), 2)
|
error(('cannot convert type %s to a rotation vector'):format(inputType), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Tries to convert its argument to a vector.
|
---Tries to convert its argument to a vector4.
|
||||||
---@param input string | table
|
---@param input string | table
|
||||||
---@return number | vector2 | vector3 | vector4
|
---@return vector4
|
||||||
function math.torgba(input)
|
function math.torgba(input)
|
||||||
return math.tovector(input, 0, 255, true)
|
local res = math.tovector(input, 0, 255, 3)
|
||||||
|
assert(type(res) == 'vector4', 'cannot convert input to rgba')
|
||||||
|
parseNumber(res.a, 0, 1)
|
||||||
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
---Takes a hexidecimal string and returns three integers.
|
---Takes a hexidecimal string and returns three integers.
|
||||||
|
|||||||
Reference in New Issue
Block a user