aboutsummaryrefslogtreecommitdiff
path: root/advtrains/advtrains_luaautomation/p_mesecon_iface.lua
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2017-02-02 16:40:51 +0100
committerorwell96 <mono96.mml@gmail.com>2017-02-02 17:17:39 +0100
commitb19033b224f4f8ec33f10ba40327f1d811c04fbb (patch)
treef1d6340ef9aab4f93a2e355f544fa0a9ebb65130 /advtrains/advtrains_luaautomation/p_mesecon_iface.lua
parenta8f9e3d43e1a256e73e1a40c261a7145d3652f5b (diff)
downloadadvtrains-b19033b224f4f8ec33f10ba40327f1d811c04fbb.tar.gz
advtrains-b19033b224f4f8ec33f10ba40327f1d811c04fbb.tar.bz2
advtrains-b19033b224f4f8ec33f10ba40327f1d811c04fbb.zip
LuaAutomation - Basic component implementation
Implements the base code for LuaAutomation, an ATC rail and a punch-operated 'operation panel' as well as interface for passive components. Changes in advtrains code where neccessary. Supported passive components are light signals, switches and mesecon switches
Diffstat (limited to 'advtrains/advtrains_luaautomation/p_mesecon_iface.lua')
-rw-r--r--advtrains/advtrains_luaautomation/p_mesecon_iface.lua60
1 files changed, 60 insertions, 0 deletions
diff --git a/advtrains/advtrains_luaautomation/p_mesecon_iface.lua b/advtrains/advtrains_luaautomation/p_mesecon_iface.lua
new file mode 100644
index 0000000..d7e1052
--- /dev/null
+++ b/advtrains/advtrains_luaautomation/p_mesecon_iface.lua
@@ -0,0 +1,60 @@
+-- p_mesecon_iface.lua
+-- Mesecons interface by overriding the switch
+
+if not mesecon then return end
+
+minetest.override_item("mesecons_switch:mesecon_switch_off", {
+ groups = {
+ dig_immediate=2,
+ save_in_nodedb=1,
+ },
+ on_rightclick = function (pos, node)
+ if(mesecon.flipstate(pos, node) == "on") then
+ mesecon.receptor_on(pos)
+ else
+ mesecon.receptor_off(pos)
+ end
+ minetest.sound_play("mesecons_switch", {pos=pos})
+ advtrains.ndb.update(pos, node)
+ end,
+ on_updated_from_nodedb = function(pos, node)
+ mesecon.receptor_off(pos)
+ end,
+ luaautomation = {
+ getstate = "off",
+ setstate = function(pos, node, newstate)
+ if newstate=="on" then
+ advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_on", param2=node.param2})
+ mesecon.receptor_on(pos)
+ end
+ end,
+ },
+})
+
+minetest.override_item("mesecons_switch:mesecon_switch_on", {
+ groups = {
+ dig_immediate=2,
+ save_in_nodedb=1,
+ },
+ on_rightclick = function (pos, node)
+ if(mesecon.flipstate(pos, node) == "on") then
+ mesecon.receptor_on(pos)
+ else
+ mesecon.receptor_off(pos)
+ end
+ minetest.sound_play("mesecons_switch", {pos=pos})
+ advtrains.ndb.update(pos, node)
+ end,
+ on_updated_from_nodedb = function(pos, node)
+ mesecon.receptor_on(pos)
+ end,
+ luaautomation = {
+ getstate = "on",
+ setstate = function(pos, node, newstate)
+ if newstate=="off" then
+ advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_off", param2=node.param2})
+ mesecon.receptor_off(pos)
+ end
+ end,
+ },
+})