1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-07-20 19:02:52 +00:00

Improve argument validation in colors.fromBlit

This commit is contained in:
Erlend 2023-05-17 20:20:53 +02:00
parent 25ab7d0dcb
commit 952674a161

View File

@ -372,7 +372,7 @@ end
--- Converts the given paint/blit hex character (0-9a-f) to a color. --- Converts the given paint/blit hex character (0-9a-f) to a color.
-- --
-- This is equivalent to converting the hex character to decimal and then 2 ^ decimal -- This is equivalent to converting the hex character to a number and then 2 ^ decimal
-- --
-- @tparam string hex The paint/blit hex character to convert -- @tparam string hex The paint/blit hex character to convert
-- @treturn number The color -- @treturn number The color
@ -387,9 +387,9 @@ end
function fromBlit(hex) function fromBlit(hex)
expect(1, hex, "string") expect(1, hex, "string")
if hex:find("[^0-9a-f]") or hex == "" then if #hex ~= 1 then return nil end
return local value = tonumber(hex, 16)
end if not value then return nil end
return math.floor(2 ^ tonumber(hex, 16)) return 2 ^ value
end end