mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-09-24 13:20:30 +02:00
Add rotation test
This commit is contained in:
parent
bc1f14a492
commit
dc42847077
23
mesecons/spec/fixtures/mesecons.lua
vendored
23
mesecons/spec/fixtures/mesecons.lua
vendored
|
@ -80,6 +80,29 @@ do
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local function get_rules(node)
|
||||||
|
local rules = {{x = 1, y = 0, z = 0}, {x = -1, y = 0, z = 0}}
|
||||||
|
if node.param2 == 1 or node.param2 == 3 then
|
||||||
|
rules = mesecon.rotate_rules_right(rules)
|
||||||
|
end
|
||||||
|
return rules
|
||||||
|
end
|
||||||
|
local off_spec = {conductor = {
|
||||||
|
state = mesecon.state.off,
|
||||||
|
rules = get_rules,
|
||||||
|
onstate = "mesecons:test_conductor_rot_on",
|
||||||
|
}}
|
||||||
|
local on_spec = {conductor = {
|
||||||
|
state = mesecon.state.on,
|
||||||
|
rules = get_rules,
|
||||||
|
offstate = "mesecons:test_conductor_rot_off",
|
||||||
|
}}
|
||||||
|
mesecon.register_node("mesecons:test_conductor_rot", {
|
||||||
|
description = "Rotatable Test Conductor",
|
||||||
|
}, {mesecons = off_spec}, {mesecons = on_spec})
|
||||||
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local mesecons_spec = {conductor = {
|
local mesecons_spec = {conductor = {
|
||||||
rules = {
|
rules = {
|
||||||
|
|
|
@ -68,6 +68,37 @@ describe("state", function()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe("rotation", function()
|
||||||
|
local layout = {
|
||||||
|
{{x = 0, y = 0, z = 0}, "mesecons:test_receptor_off"},
|
||||||
|
{{x = 1, y = 0, z = 0}, {name = "mesecons:test_conductor_rot_off", param2 = 0}},
|
||||||
|
{{x = 0, y = 0, z = 1}, {name = "mesecons:test_conductor_rot_off", param2 = 1}},
|
||||||
|
{{x = -1, y = 0, z = 0}, {name = "mesecons:test_conductor_rot_off", param2 = 2}},
|
||||||
|
{{x = 0, y = 0, z = -1}, {name = "mesecons:test_conductor_rot_off", param2 = 3}},
|
||||||
|
}
|
||||||
|
|
||||||
|
before_each(function()
|
||||||
|
for _, entry in ipairs(layout) do
|
||||||
|
world.set_node(entry[1], entry[2])
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
after_each(function()
|
||||||
|
mesecon._test_reset()
|
||||||
|
world.clear()
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("works", function()
|
||||||
|
mesecon.swap_node_force(layout[1][1], "mesecons:test_receptor_on")
|
||||||
|
mesecon.receptor_on(layout[1][1], mesecon.rules.alldirs)
|
||||||
|
mineunit:execute_globalstep()
|
||||||
|
assert.equal("mesecons:test_conductor_rot_on", world.get_node(layout[2][1]).name)
|
||||||
|
assert.equal("mesecons:test_conductor_rot_on", world.get_node(layout[3][1]).name)
|
||||||
|
assert.equal("mesecons:test_conductor_rot_on", world.get_node(layout[4][1]).name)
|
||||||
|
assert.equal("mesecons:test_conductor_rot_on", world.get_node(layout[5][1]).name)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe("multiconductor", function()
|
describe("multiconductor", function()
|
||||||
local layout = {
|
local layout = {
|
||||||
{{x = 1, y = 0, z = 0}, "mesecons:test_receptor_off"},
|
{{x = 1, y = 0, z = 0}, "mesecons:test_receptor_off"},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user