fpga: Make rotatable with screwdrivers

This commit is contained in:
DS-Minetest 2017-09-05 20:12:49 +02:00 committed by sfan5
parent 1963d8b3d5
commit fa58607546
2 changed files with 39 additions and 0 deletions

View File

@ -1 +1,2 @@
mesecons mesecons
screwdriver?

View File

@ -116,6 +116,44 @@ plg.register_nodes({
after_dig_node = function(pos, node) after_dig_node = function(pos, node)
mesecon.receptor_off(pos, plg.rules[node.name]) mesecon.receptor_off(pos, plg.rules[node.name])
end, end,
on_rotate = function(pos, node, user, mode)
local abcd1 = {"A", "B", "C", "D"}
local abcd2 = {A = 1, B = 2, C = 3, D = 4}
local ops = {"op1", "op2", "dst"}
local dir = 0
if mode == screwdriver.ROTATE_FACE then -- clock-wise
dir = 1
if user and user:is_player() then
minetest.chat_send_player(user:get_player_name(),
"FPGA ports have been rotated clockwise.")
end
elseif mode == screwdriver.ROTATE_AXIS then -- counter-clockwise
dir = -1
if user and user:is_player() then
minetest.chat_send_player(user:get_player_name(),
"FPGA ports have been rotated counter-clockwise.")
end
end
local meta = minetest.get_meta(pos)
local instr = lcore.deserialize(meta:get_string("instr"))
for i = 1, #instr do
for _, op in ipairs(ops) do
local o = instr[i][op]
if o and o.type == "io" then
local num = abcd2[o.port]
num = num + dir
if num > 4 then num = 1
elseif num < 1 then num = 4 end
instr[i][op].port = abcd1[num]
end
end
end
meta:set_string("instr", lcore.serialize(instr))
plg.update_formspec(pos, instr)
return true
end,
}) })