aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/signal_api.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-07-04 17:48:33 +0200
committerorwell96 <orwell@bleipb.de>2018-07-04 17:48:33 +0200
commit031aab4633f6f140a2ffda4f00b6e0d743cf681a (patch)
treed43a3e7fac033676969a34ad45e81b7db105448b /advtrains_interlocking/signal_api.lua
parent9586a4d70922e24ba45ef018fc48455f31c4cfbb (diff)
downloadadvtrains-031aab4633f6f140a2ffda4f00b6e0d743cf681a.tar.gz
advtrains-031aab4633f6f140a2ffda4f00b6e0d743cf681a.tar.bz2
advtrains-031aab4633f6f140a2ffda4f00b6e0d743cf681a.zip
Signal assignment and route programming procedure
Diffstat (limited to 'advtrains_interlocking/signal_api.lua')
-rw-r--r--advtrains_interlocking/signal_api.lua35
1 files changed, 34 insertions, 1 deletions
diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua
index e072273..17799ae 100644
--- a/advtrains_interlocking/signal_api.lua
+++ b/advtrains_interlocking/signal_api.lua
@@ -33,6 +33,21 @@ on_rightclick = advtrains.interlocking.signal_rc_handler
]]--
+local DANGER = {
+ main = {
+ free = false,
+ speed = 0,
+ },
+ shunt = {
+ free = false,
+ },
+ dst = {
+ free = false,
+ speed = 0,
+ },
+ info = {}
+}
+
function advtrains.interlocking.signal_set_aspect(pos, asp)
local node=advtrains.ndb.get_node(pos)
local ndef=minetest.registered_nodes[node.name]
@@ -43,7 +58,13 @@ end
function advtrains.interlocking.signal_rc_handler(pos, node, player, itemstack, pointed_thing)
local pname = player:get_player_name()
- minetest.show_formspec(pname, "at_il_sigasp_"..minetest.pos_to_string(pos), "field[aspect;Set Aspect (F/D)Speed(F/D)Speed(F/D);D0D0D]")
+ local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos)
+ if sigd then
+ advtrains.interlocking.show_signalling_form(sigd, pname)
+ else
+ -- permit to set aspect manually
+ minetest.show_formspec(pname, "at_il_sigasp_"..minetest.pos_to_string(pos), "field[aspect;Set Aspect (F/D)Speed(F/D)Speed(F/D);D0D0D]")
+ end
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
@@ -73,3 +94,15 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
advtrains.interlocking.signal_set_aspect(pos, asp)
end
end)
+
+-- Returns the aspect the signal at pos is supposed to show
+function advtrains.interlocking.signal_get_aspect(pos)
+ local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos)
+ if sigd then
+ local tcbs = advtrains.interlocking.db.get_tcbs(sigd)
+ if tcbs.aspect then
+ return tcbs.aspect
+ end
+ end
+ return DANGER;
+end