aboutsummaryrefslogtreecommitdiff
path: root/advtrains_luaautomation
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-08-16 19:18:03 +0200
committerorwell96 <orwell@bleipb.de>2018-08-16 19:18:03 +0200
commit05cb6090ac9537650a900b64768bf3ed959cebed (patch)
tree11b7e3ab4bb846ab069fc10832b07cb36d6eb6dd /advtrains_luaautomation
parent5fad61e9c981115a183527ffe58a7bbe26fea4e7 (diff)
downloadadvtrains-05cb6090ac9537650a900b64768bf3ed959cebed.tar.gz
advtrains-05cb6090ac9537650a900b64768bf3ed959cebed.tar.bz2
advtrains-05cb6090ac9537650a900b64768bf3ed959cebed.zip
Move passive API to the advtrains core
to remove dependency of interlocking on luaautomation
Diffstat (limited to 'advtrains_luaautomation')
-rw-r--r--advtrains_luaautomation/environment.lua10
-rw-r--r--advtrains_luaautomation/passive.lua52
-rw-r--r--advtrains_luaautomation/passive_api.txt5
-rw-r--r--advtrains_luaautomation/pcnaming.lua18
4 files changed, 15 insertions, 70 deletions
diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua
index 52d36a4..65d5700 100644
--- a/advtrains_luaautomation/environment.lua
+++ b/advtrains_luaautomation/environment.lua
@@ -86,7 +86,6 @@ local function safe_string_find(...)
end
local mp=minetest.get_modpath("advtrains_luaautomation")
-local p_api_getstate, p_api_setstate, p_api_is_passive = dofile(mp.."/passive.lua")
local static_env = {
--core LUA functions
@@ -148,12 +147,13 @@ local static_env = {
date = safe_date,
},
POS = function(x,y,z) return {x=x, y=y, z=z} end,
- getstate = p_api_getstate,
- setstate = p_api_setstate,
- is_passive = p_api_is_passive,
+ getstate = advtrains.getstate,
+ setstate = advtrains.setstate,
+ is_passive = advtrains.is_passive,
--interrupts are handled per node, position unknown. (same goes for digilines)
--however external interrupts can be set here.
- interrupt_pos = function(pos, imesg)
+ interrupt_pos = function(parpos, imesg)
+ local pos=atlatc.pcnaming.resolve_pos(parpos)
if not type(pos)=="table" or not pos.x or not pos.y or not pos.z then
debug.sethook()
error("Invalid position supplied to interrupt_pos")
diff --git a/advtrains_luaautomation/passive.lua b/advtrains_luaautomation/passive.lua
deleted file mode 100644
index e0902f5..0000000
--- a/advtrains_luaautomation/passive.lua
+++ /dev/null
@@ -1,52 +0,0 @@
--- passive.lua
--- API to passive components, as described in passive_api.txt
-
-local function getstate(parpos)
- local pos=atlatc.pcnaming.resolve_pos(parpos)
- if type(pos)~="table" or (not pos.x or not pos.y or not pos.z) then
- debug.sethook()
- error("Invalid position supplied to getstate")
- end
- local node=advtrains.ndb.get_node(pos)
- local ndef=minetest.registered_nodes[node.name]
- if ndef and ndef.luaautomation and ndef.luaautomation.getstate then
- local st=ndef.luaautomation.getstate
- if type(st)=="function" then
- return st(pos, node)
- else
- return st
- end
- end
- return nil
-end
-
-local function setstate(parpos, newstate)
- local pos=atlatc.pcnaming.resolve_pos(parpos)
- if type(pos)~="table" or (not pos.x or not pos.y or not pos.z) then
- debug.sethook()
- error("Invalid position supplied to setstate")
- end
- local node=advtrains.ndb.get_node(pos)
- local ndef=minetest.registered_nodes[node.name]
- if ndef and ndef.luaautomation and ndef.luaautomation.setstate then
- local st=ndef.luaautomation.setstate
- st(pos, node, newstate)
- end
-end
-
-local function is_passive(parpos)
- local pos=atlatc.pcnaming.resolve_pos(parpos)
- if type(pos)~="table" or (not pos.x or not pos.y or not pos.z) then
- return false
- end
- local node=advtrains.ndb.get_node(pos)
- local ndef=minetest.registered_nodes[node.name]
- if ndef and ndef.luaautomation and ndef.luaautomation.getstate then
- return true
- end
- return false
-end
-
--- gets called from environment.lua
--- return the values here to keep them local
-return getstate, setstate, is_passive
diff --git a/advtrains_luaautomation/passive_api.txt b/advtrains_luaautomation/passive_api.txt
index a735208..9852e94 100644
--- a/advtrains_luaautomation/passive_api.txt
+++ b/advtrains_luaautomation/passive_api.txt
@@ -5,10 +5,11 @@ Switches
Signals
Displays
Mesecon Transmitter
+Those passive components can also be used inside interlocking systems.
-All passive components have a table called 'luaautomation' in their node definition and have the group 'save_in_nodedb' set, so they work in unloaded chunks.
+All passive components have a table called 'advtrains' in their node definition and have the group 'save_in_nodedb' set, so they work in unloaded chunks.
Example for a switch:
-luaautomation = {
+advtrains = {
getstate = function(pos, node)
return "st"
end,
diff --git a/advtrains_luaautomation/pcnaming.lua b/advtrains_luaautomation/pcnaming.lua
index 56ed2d6..4910f1d 100644
--- a/advtrains_luaautomation/pcnaming.lua
+++ b/advtrains_luaautomation/pcnaming.lua
@@ -38,19 +38,15 @@ minetest.register_craftitem("advtrains_luaautomation:pcnaming",{
minetest.record_protection_violation(pos, pname)
return
end
- local node=minetest.get_node(pos)
- local ndef=minetest.registered_nodes[node.name]
- if ndef then
- if ndef.luaautomation then
- --look if this one already has a name
- local pn=""
- for name, npos in pairs(atlatc.pcnaming.name_map) do
- if vector.equals(npos, pos) then
- pn=name
- end
+ if advtrains.is_passive(pos) then
+ --look if this one already has a name
+ local pn=""
+ for name, npos in pairs(atlatc.pcnaming.name_map) do
+ if vector.equals(npos, pos) then
+ pn=name
end
- minetest.show_formspec(pname, "atlatc_naming_"..minetest.pos_to_string(pos), "field[pn;Set name of component (empty to clear);"..pn.."]")
end
+ minetest.show_formspec(pname, "atlatc_naming_"..minetest.pos_to_string(pos), "field[pn;Set name of component (empty to clear);"..pn.."]")
end
end
end,