mirror of
https://gitlab.com/deetmit/mesecons_x.git
synced 2024-10-11 03:53:12 +02:00
49 lines
1.2 KiB
Lua
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
|