diff options
-rw-r--r-- | .luacheckrc | 7 | ||||
-rw-r--r-- | depends.txt | 1 | ||||
-rw-r--r-- | init.lua | 84 | ||||
-rw-r--r-- | mod.conf | 3 |
4 files changed, 64 insertions, 31 deletions
diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..8d851f8 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,7 @@ +max_line_length = 160 + +read_globals = { + "minetest", + "digilines", + "default", +} diff --git a/depends.txt b/depends.txt deleted file mode 100644 index da1d119..0000000 --- a/depends.txt +++ /dev/null @@ -1 +0,0 @@ -digilines @@ -1,28 +1,30 @@ +local function schedule(time,pos,channel,message) + minetest.after(time,function() + digilines.receptor_send(pos,digilines.rules.default,channel,message) + end) +end + local emit_signals = function(pos) local meta = minetest.get_meta(pos) - if meta:get_string("locked")~="true" then + if meta:get_string("locked") ~= "true" then meta:set_string("locked","true") - digiline:receptor_send(pos, digiline.rules.default, "main", "RED") - minetest.after(5,function(pos) - digiline:receptor_send(pos, digiline.rules.default, "side", "GREEN") - minetest.after(10,function(pos) - digiline:receptor_send(pos, digiline.rules.default, "side", "RED") - minetest.after(5,function(pos) - digiline:receptor_send(pos, digiline.rules.default, "main", "GREEN") - minetest.after(15,function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("locked","false") - end,pos) - end,pos) - end,pos) - end,pos) + schedule(0,pos,"main","YELLOW") + schedule(3,pos,"main","RED") + schedule(4,pos,"side","GREEN") + schedule(14,pos,"side","YELLOW") + schedule(17,pos,"side","RED") + schedule(18,pos,"main","GREEN") + minetest.after(30,function() + if minetest.get_node(pos).name == "lightcontroller:trafficnext" then + meta:set_string("locked","") + end + end) end end local lc_scan = function(pos) local objs = minetest.get_objects_inside_radius(pos, 6) if objs then - local _,obj for _,obj in ipairs(objs) do if obj:is_player() then emit_signals(pos) @@ -35,49 +37,59 @@ end local lc_slave_scan = function(pos) local objs = minetest.get_objects_inside_radius(pos, 6) if objs then - local _,obj for _,obj in ipairs(objs) do if obj:is_player() then - digiline:receptor_send(pos, digiline.rules.default, "detector", "car") + digilines.receptor_send(pos, digilines.rules.default, "detector", "car") return end end end end -local on_digiline_receive = function (pos, node, channel, msg) - if channel=="detector" then emit_signals(pos) end +local on_digiline_receive = function(pos,_,channel) + if channel == "detector" then emit_signals(pos) end end minetest.register_node("lightcontroller:trafficnext", { description = "TrafficNeXt SoC - Master", - tiles = {"streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png^streets_tl_green.png","streets_tl_bg.png^streets_tl_green.png","streets_tl_bg.png^streets_tl_green.png","streets_tl_bg.png^streets_tl_green.png"}, + tiles = { + "streets_tl_bg.png", + "streets_tl_bg.png", + "streets_tl_bg.png^streets_tl_green.png", + "streets_tl_bg.png^streets_tl_green.png", + "streets_tl_bg.png^streets_tl_green.png", + "streets_tl_bg.png^streets_tl_green.png" + }, groups = {cracky=3, stone=1}, sounds = default.node_sound_stone_defaults(), - digiline = - { + digiline = { receptor = {}, effector = { action = on_digiline_receive }, }, - on_punch = function(pos) emit_signals(pos) end + on_punch = emit_signals, }) minetest.register_abm({ nodenames = {"lightcontroller:trafficnext"}, interval = 1.0, chance = 1, - action = function(pos) lc_scan(pos) end + action = lc_scan, }) minetest.register_node("lightcontroller:trafficnext_slave", { description = "TrafficNeXt SoC - Slave", - tiles = {"streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png^streets_tl_red.png","streets_tl_bg.png^streets_tl_red.png","streets_tl_bg.png^streets_tl_red.png","streets_tl_bg.png^streets_tl_red.png"}, + tiles = { + "streets_tl_bg.png", + "streets_tl_bg.png", + "streets_tl_bg.png^streets_tl_red.png", + "streets_tl_bg.png^streets_tl_red.png", + "streets_tl_bg.png^streets_tl_red.png", + "streets_tl_bg.png^streets_tl_red.png" + }, groups = {cracky=3, stone=1}, sounds = default.node_sound_stone_defaults(), - digiline = - { + digiline = { receptor = {}, - effector = { action = function() end}, }, }) @@ -85,5 +97,17 @@ minetest.register_abm({ nodenames = {"lightcontroller:trafficnext_slave"}, interval = 1.0, chance = 1, - action = function(pos) lc_slave_scan(pos) end + action = lc_slave_scan, +}) + +minetest.register_lbm({ + name = "lightcontroller:reset", + label = "Reset TrafficNeXt SoCs", + nodenames = {"lightcontroller:trafficnext"}, + run_at_every_load = true, + action = function(pos) + minetest.get_meta(pos):set_string("locked","") + digilines.receptor_send(pos,digilines.rules.default,"main","GREEN") + digilines.receptor_send(pos,digilines.rules.default,"side","RED") + end, }) diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..856e10d --- /dev/null +++ b/mod.conf @@ -0,0 +1,3 @@ +name = lightcontroller +description = TrafficNeXt SoC (deprecated) +depends = default,digilines |