mesecons_x/mesecons_autotools/book/misc.lua
Deet Mit 68aadf9953 fix
2020-09-04 16:21:35 +02:00

49 lines
1.2 KiB
Lua

function rotate_node_to_direction(node,direction)
local add = 0
if direction.x == 1 then add = 3 end
if direction.x == -1 then add = 1 end
if direction.z == 1 then add = 0 end
if direction.z == -1 then add = 2 end
local param2 = node.param2
param2 = (param2+add)% 4
return { name = node.name , param2 = param2 }
end
local function direction_to_number(direction)
if( direction.z == 1 ) then
return 1
elseif( direction.x == 1 ) then
return 2
elseif(direction.z == -1 )then
return 3
else
return 4
end
end
function rotate_node(node, saved_direction,direction)
local values =
{
{0,1,2,3},
{3,0,1,2},
{2,3,0,1},
{1,2,3,0}
}
local rotate =
values[direction_to_number(saved_direction)][direction_to_number(direction)]
local new_node = {}
new_node.name = node.name
new_node.param2 = (node.param2+rotate)%4
return new_node
end