mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add colorspec_to_table to the Lua API
This commit is contained in:
parent
c54f5a2137
commit
f9c0354af1
5 changed files with 42 additions and 0 deletions
17
games/devtest/mods/unittests/color.lua
Normal file
17
games/devtest/mods/unittests/color.lua
Normal file
|
@ -0,0 +1,17 @@
|
|||
local function assert_colors_equal(c1, c2)
|
||||
if type(c1) == "table" and type(c2) == "table" then
|
||||
assert(c1.r == c2.r and c1.g == c2.g and c1.b == c2.b and c1.a == c2.a)
|
||||
else
|
||||
assert(c1 == c2)
|
||||
end
|
||||
end
|
||||
|
||||
local function test_color_conversion()
|
||||
assert_colors_equal(core.colorspec_to_table("#fff"), {r = 255, g = 255, b = 255, a = 255})
|
||||
assert_colors_equal(core.colorspec_to_table(0xFF00FF00), {r = 0, g = 255, b = 0, a = 255})
|
||||
assert_colors_equal(core.colorspec_to_table("#00000000"), {r = 0, g = 0, b = 0, a = 0})
|
||||
assert_colors_equal(core.colorspec_to_table("green"), {r = 0, g = 128, b = 0, a = 255})
|
||||
assert_colors_equal(core.colorspec_to_table("gren"), nil)
|
||||
end
|
||||
|
||||
unittests.register("test_color_conversion", test_color_conversion)
|
|
@ -187,6 +187,7 @@ dofile(modpath .. "/raycast.lua")
|
|||
dofile(modpath .. "/inventory.lua")
|
||||
dofile(modpath .. "/load_time.lua")
|
||||
dofile(modpath .. "/on_shutdown.lua")
|
||||
dofile(modpath .. "/color.lua")
|
||||
|
||||
--------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue