From 425fefd4812356d5a356a6ec0edeefd066fa0616 Mon Sep 17 00:00:00 2001 From: cheapie Date: Thu, 14 Jan 2016 13:42:44 -0600 Subject: Make the lane control lights work and add a downward-pointing yellow arrow --- infrastructure/advanced_lane_control_lights.lua | 60 ++++++++++++--------- .../infrastructure_lane_control_lights_6.png | Bin 0 -> 4160 bytes 2 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 infrastructure/textures/infrastructure_lane_control_lights_6.png diff --git a/infrastructure/advanced_lane_control_lights.lua b/infrastructure/advanced_lane_control_lights.lua index ff9d0f5..195f809 100644 --- a/infrastructure/advanced_lane_control_lights.lua +++ b/infrastructure/advanced_lane_control_lights.lua @@ -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 diff --git a/infrastructure/textures/infrastructure_lane_control_lights_6.png b/infrastructure/textures/infrastructure_lane_control_lights_6.png new file mode 100644 index 0000000..6e149d7 Binary files /dev/null and b/infrastructure/textures/infrastructure_lane_control_lights_6.png differ -- cgit v1.2.3