aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/signal_api.lua
diff options
context:
space:
mode:
authororwell <orwell@bleipb.de>2024-06-22 19:35:48 +0200
committerorwell <orwell@bleipb.de>2024-06-22 19:35:48 +0200
commit3606a9bdfcd3dda888ff528b7e5071d35df05ef9 (patch)
tree6ebb525128ad790fcf2bd75f3ef47fd63fac5a2f /advtrains_interlocking/signal_api.lua
parent2239ba314b0a39b7e6d2351d582c396df821b281 (diff)
downloadadvtrains-3606a9bdfcd3dda888ff528b7e5071d35df05ef9.tar.gz
advtrains-3606a9bdfcd3dda888ff528b7e5071d35df05ef9.tar.bz2
advtrains-3606a9bdfcd3dda888ff528b7e5071d35df05ef9.zip
Unassign signal on dig instead of needing button in signal form
Diffstat (limited to 'advtrains_interlocking/signal_api.lua')
-rw-r--r--advtrains_interlocking/signal_api.lua23
1 files changed, 20 insertions, 3 deletions
diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua
index 65fc787..eddf9da 100644
--- a/advtrains_interlocking/signal_api.lua
+++ b/advtrains_interlocking/signal_api.lua
@@ -419,12 +419,29 @@ end
----------------
function signal.can_dig(pos)
- return not advtrains.interlocking.db.get_sigd_for_signal(pos)
+ local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos)
+ if sigd then
+ local tcbs = advtrains.interlocking.db.get_tcbs(sigd)
+ if tcbs.routeset then
+ return false
+ end
+ end
+ return true
end
-function signal.after_dig(pos)
+function signal.after_dig(pos, oldnode, oldmetadata, player)
+ -- unassign signal if necessary
+ local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos)
+ if sigd then
+ local tcbs = advtrains.interlocking.db.get_tcbs(sigd)
+ advtrains.interlocking.db.set_sigd_for_signal(pos, nil)
+ tcbs.signal = nil
+ tcbs.route_aspect = nil
+ tcbs.route_remote = nil
+ minetest.chat_send_player(player:get_player_name(), "Signal has been unassigned. Name and routes are kept for reuse.")
+ end
-- TODO clear influence point
- advtrains.interlocking.signal.clear_aspect(pos)
+ advtrains.interlocking.signal.unregister_aspect(pos)
end
function signal.on_rightclick(pos, node, player, itemstack, pointed_thing)