mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 15:23:48 +01:00
Fix colorspec
This commit is contained in:
parent
454ffb1a46
commit
1d76fee9db
14
minetest.lua
14
minetest.lua
@ -616,7 +616,7 @@ function colorspec.from_string(string)
|
|||||||
alpha = tonumber(alpha_text, 16)
|
alpha = tonumber(alpha_text, 16)
|
||||||
end
|
end
|
||||||
if number then
|
if number then
|
||||||
return colorspec.from_number(number * 0xFF + alpha)
|
return colorspec.from_number(number * 0x100 + alpha)
|
||||||
end
|
end
|
||||||
local hex_text = string:match(hex)
|
local hex_text = string:match(hex)
|
||||||
local len, num = hex_text:len(), tonumber(hex_text, 16)
|
local len, num = hex_text:len(), tonumber(hex_text, 16)
|
||||||
@ -624,7 +624,7 @@ function colorspec.from_string(string)
|
|||||||
return colorspec.from_number(num)
|
return colorspec.from_number(num)
|
||||||
end
|
end
|
||||||
if len == 6 then
|
if len == 6 then
|
||||||
return colorspec.from_number(num * 0xFF + 0xFF)
|
return colorspec.from_number(num * 0x100 + 0xFF)
|
||||||
end
|
end
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
if len == 4 then
|
if len == 4 then
|
||||||
@ -650,10 +650,10 @@ colorspec.from_text = colorspec.from_string
|
|||||||
function colorspec.from_number(number)
|
function colorspec.from_number(number)
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
return colorspec.from_table{
|
return colorspec.from_table{
|
||||||
a = number % 0xFF,
|
a = number % 0x100,
|
||||||
b = floor(number / 0xFF) % 0xFF,
|
b = floor(number / 0x100) % 0x100,
|
||||||
g = floor(number / 0xFFFF) % 0xFF,
|
g = floor(number / 0x10000) % 0x100,
|
||||||
r = floor(number / 0xFFFFFF)
|
r = floor(number / 0x1000000)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -684,7 +684,7 @@ function colorspec:to_string()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function colorspec:to_number()
|
function colorspec:to_number()
|
||||||
return self.r * 0xFFFFFF + self.g * 0xFFFF + self.b * 0xFF + self.a
|
return self.r * 0x1000000 + self.g * 0x10000 + self.b * 0x100 + self.a
|
||||||
end
|
end
|
||||||
|
|
||||||
colorspec_to_colorstring = _G.minetest.colorspec_to_colorstring or function(spec)
|
colorspec_to_colorstring = _G.minetest.colorspec_to_colorstring or function(spec)
|
||||||
|
4
test.lua
4
test.lua
@ -90,6 +90,10 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- colorspec
|
||||||
|
local colorspec = modlib.minetest.colorspec.from_number(0xDDCCBBAA)
|
||||||
|
assert(modlib.table.equals(colorspec, {a = 0xAA, b = 0xBB, g = 0xCC, r = 0xDD,}), dump(colorspec))
|
||||||
|
|
||||||
-- in-game tests
|
-- in-game tests
|
||||||
local tests = {
|
local tests = {
|
||||||
liquid_dir = false,
|
liquid_dir = false,
|
||||||
|
Loading…
Reference in New Issue
Block a user