mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-26 18:21:04 +00:00
Code style fixes.
This commit is contained in:
parent
24e9db07ec
commit
af3f696423
43 changed files with 493 additions and 484 deletions
|
@ -1,17 +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
|
||||
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)
|
||||
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)
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
|
||||
unittests.register("test_get_version", function()
|
||||
local version = core.get_version()
|
||||
assert(type(version) == "table")
|
||||
assert(type(version.project) == "string")
|
||||
assert(type(version.string) == "string")
|
||||
assert(type(version.proto_min) == "number")
|
||||
assert(type(version.proto_max) == "number")
|
||||
assert(version.proto_max >= version.proto_min)
|
||||
assert(type(version.is_dev) == "boolean")
|
||||
if version.is_dev then
|
||||
assert(type(version.hash) == "string")
|
||||
else
|
||||
assert(version.hash == nil)
|
||||
end
|
||||
local version = core.get_version()
|
||||
assert(type(version) == "table")
|
||||
assert(type(version.project) == "string")
|
||||
assert(type(version.string) == "string")
|
||||
assert(type(version.proto_min) == "number")
|
||||
assert(type(version.proto_max) == "number")
|
||||
assert(version.proto_max >= version.proto_min)
|
||||
assert(type(version.is_dev) == "boolean")
|
||||
if version.is_dev then
|
||||
assert(type(version.hash) == "string")
|
||||
else
|
||||
assert(version.hash == nil)
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
local function raycast_with_pointabilities(start_pos, end_pos, pointabilities)
|
||||
local ray = core.raycast(start_pos, end_pos, nil, nil, pointabilities)
|
||||
for hit in ray do
|
||||
if hit.type == "node" then
|
||||
return hit.under
|
||||
end
|
||||
if hit.type == "node" then
|
||||
return hit.under
|
||||
end
|
||||
end
|
||||
return nil
|
||||
return nil
|
||||
end
|
||||
|
||||
local function test_raycast_pointabilities(player, pos1)
|
||||
local pos2 = pos1:offset(0, 0, 1)
|
||||
local pos3 = pos1:offset(0, 0, 2)
|
||||
local pos2 = pos1:offset(0, 0, 1)
|
||||
local pos3 = pos1:offset(0, 0, 2)
|
||||
|
||||
local oldnode1 = core.get_node(pos1)
|
||||
local oldnode2 = core.get_node(pos2)
|
||||
local oldnode3 = core.get_node(pos3)
|
||||
core.swap_node(pos1, {name = "air"})
|
||||
core.swap_node(pos2, {name = "testnodes:not_pointable"})
|
||||
core.swap_node(pos3, {name = "testnodes:pointable"})
|
||||
local oldnode1 = core.get_node(pos1)
|
||||
local oldnode2 = core.get_node(pos2)
|
||||
local oldnode3 = core.get_node(pos3)
|
||||
core.swap_node(pos1, {name = "air"})
|
||||
core.swap_node(pos2, {name = "testnodes:not_pointable"})
|
||||
core.swap_node(pos3, {name = "testnodes:pointable"})
|
||||
|
||||
local p = nil
|
||||
assert(raycast_with_pointabilities(pos1, pos3, p) == pos3)
|
||||
local p = nil
|
||||
assert(raycast_with_pointabilities(pos1, pos3, p) == pos3)
|
||||
|
||||
p = core.registered_items["testtools:blocked_pointing_staff"].pointabilities
|
||||
assert(raycast_with_pointabilities(pos1, pos3, p) == nil)
|
||||
p = core.registered_items["testtools:blocked_pointing_staff"].pointabilities
|
||||
assert(raycast_with_pointabilities(pos1, pos3, p) == nil)
|
||||
|
||||
p = core.registered_items["testtools:ultimate_pointing_staff"].pointabilities
|
||||
assert(raycast_with_pointabilities(pos1, pos3, p) == pos2)
|
||||
p = core.registered_items["testtools:ultimate_pointing_staff"].pointabilities
|
||||
assert(raycast_with_pointabilities(pos1, pos3, p) == pos2)
|
||||
|
||||
core.swap_node(pos1, oldnode1)
|
||||
core.swap_node(pos2, oldnode2)
|
||||
core.swap_node(pos3, oldnode3)
|
||||
core.swap_node(pos1, oldnode1)
|
||||
core.swap_node(pos2, oldnode2)
|
||||
core.swap_node(pos3, oldnode3)
|
||||
end
|
||||
|
||||
unittests.register("test_raycast_pointabilities", test_raycast_pointabilities, {map=true})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue