Make the lane control lights work and add a downward-pointing yellow arrow

master
cheapie 2016-01-14 13:42:44 -06:00
parent bd608bcb02
commit 425fefd481
2 changed files with 36 additions and 24 deletions

View File

@ -1,20 +1,6 @@
-- Lane control lights
function lane_control_change(pos, node)
local node = minetest.env:get_node(pos)
if node.name == "infrastructure:lane_control_lights_1" then
minetest.swap_node(pos, {name = "infrastructure:lane_control_lights_2", param2 = node.param2})
elseif node.name == "infrastructure:lane_control_lights_2" then
minetest.swap_node(pos, {name = "infrastructure:lane_control_lights_3", param2 = node.param2})
elseif node.name == "infrastructure:lane_control_lights_3" then
minetest.swap_node(pos, {name = "infrastructure:lane_control_lights_4", param2 = node.param2})
elseif node.name == "infrastructure:lane_control_lights_4" then
minetest.swap_node(pos, {name = "infrastructure:lane_control_lights_5", param2 = node.param2})
elseif node.name == "infrastructure:lane_control_lights_5" then
minetest.swap_node(pos, {name = "infrastructure:lane_control_lights_1", param2 = node.param2})
end
end
for i = 1, 5 do
for i = 1, 6 do
local groups = {}
if i == 1 then
groups = {cracky = 3}
@ -35,6 +21,10 @@ for i = 1, 5 do
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "field[channel;Channel;${channel}]")
end,
groups = {cracky = 3, not_in_creative_inventory = (i == 1 and 0 or 1)},
light_source = TRAFFIC_LIGHTS_LIGHT_RANGE,
drop = "infrastructure:lane_control_lights_1",
@ -63,16 +53,38 @@ for i = 1, 5 do
}
},
on_punch = function(pos, node)
lane_control_change(pos, node)
on_receive_fields = function(pos, formname, fields)
if (fields.channel) then
minetest.get_meta(pos):set_string("channel", fields.channel)
end
end,
mesecons = {effector = {
action_on = function (pos, node)
lane_control_change(pos, node)
end,
}}
digiline = {
receptor = {},
effector = {
action = function(pos, node, channel, msg)
local setchan = minetest.get_meta(pos):get_string("channel")
if setchan ~= channel then
return
end
msg = msg:lower()
if (msg=="off") then
node.name = "infrastructure:lane_control_lights_1"
elseif (msg=="green") then
node.name = "infrastructure:lane_control_lights_3"
elseif (msg=="red") then
node.name = "infrastructure:lane_control_lights_2"
elseif (msg=="yellowleft") then
node.name = "infrastructure:lane_control_lights_5"
elseif (msg=="yellowright") then
node.name = "infrastructure:lane_control_lights_4"
elseif (msg=="yellow") then
node.name = "infrastructure:lane_control_lights_6"
end
minetest.set_node(pos,node)
minetest.get_meta(pos):set_string("channel",setchan)
end
}
}
})
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB