Colorspec: From & to ARGB / RGBA number renamings

This commit is contained in:
Lars Mueller 2021-11-13 23:44:29 +01:00
parent 9a70d4cc98
commit aac9eea46e

@ -241,8 +241,7 @@ end
colorspec.from_text = colorspec.from_string colorspec.from_text = colorspec.from_string
--! This does not take a Minetest-accepted number, use :to_number_argb() instead function colorspec.from_number_rgba(number)
function colorspec.from_number(number)
return colorspec.from_table{ return colorspec.from_table{
a = number % 0x100, a = number % 0x100,
b = floor(number / 0x100) % 0x100, b = floor(number / 0x100) % 0x100,
@ -260,7 +259,7 @@ function colorspec.from_number_rgb(number)
} }
end end
function colorspec.from_number_argb(number) function colorspec.from_number(number)
return colorspec.from_table{ return colorspec.from_table{
b = number % 0x100, b = number % 0x100,
g = floor(number / 0x100) % 0x100, g = floor(number / 0x100) % 0x100,
@ -278,7 +277,7 @@ function colorspec.from_any(value)
return colorspec.from_string(value) return colorspec.from_string(value)
end end
if type == "number" then if type == "number" then
return colorspec.from_number_argb(value) return colorspec.from_number(value)
end end
error("Unsupported type " .. type) error("Unsupported type " .. type)
end end
@ -296,8 +295,7 @@ function colorspec:to_string()
end end
metatable.__tostring = colorspec.to_string metatable.__tostring = colorspec.to_string
--! This is not a Minetest-accepted number, use :to_number_argb() instead function colorspec:to_number_rgba()
function colorspec:to_number()
return self.r * 0x1000000 + self.g * 0x10000 + self.b * 0x100 + self.a return self.r * 0x1000000 + self.g * 0x10000 + self.b * 0x100 + self.a
end end
@ -305,7 +303,7 @@ function colorspec:to_number_rgb()
return self.r * 0x10000 + self.g * 0x100 + self.b return self.r * 0x10000 + self.g * 0x100 + self.b
end end
function colorspec:to_number_argb() function colorspec:to_number()
return self.a * 0x1000000 + self.r * 0x10000 + self.g * 0x100 + self.b return self.a * 0x1000000 + self.r * 0x10000 + self.g * 0x100 + self.b
end end