From ae394a43b8a715570ee3b94b19e70b8d66f597e4 Mon Sep 17 00:00:00 2001 From: 1F616EMO Date: Sun, 30 Jun 2024 06:20:42 +0800 Subject: Remove TCB marker on TCB removal This patch fixes the following problem: * TCB marker is not removed on TCB removal * TCB marker is recreated on removal --- advtrains_interlocking/database.lua | 9 ++++++--- advtrains_interlocking/tcb_ts_ui.lua | 11 ++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua index 6787c50..5096d48 100644 --- a/advtrains_interlocking/database.lua +++ b/advtrains_interlocking/database.lua @@ -425,7 +425,7 @@ function ildb.link_track_sections(merge_id, root_id) merge_ts(root_id, merge_id) end -function ildb.remove_from_interlocking(sigd) +function ildb.remove_from_interlocking(sigd, no_tcb_marker) local tcbs = ildb.get_tcbs(sigd) if not ildb.may_modify_tcbs(tcbs) then return false end @@ -455,7 +455,9 @@ function ildb.remove_from_interlocking(sigd) track_sections[tsid] = nil end end - advtrains.interlocking.show_tcb_marker(sigd.p) + if not no_tcb_marker then + advtrains.interlocking.show_tcb_marker(sigd.p) + end if tcbs.signal then return false end @@ -468,10 +470,11 @@ function ildb.remove_tcb(pos) return true --FIX: not an error, because tcb is already removed end for connid=1,2 do - if not ildb.remove_from_interlocking({p=pos, s=connid}) then + if not ildb.remove_from_interlocking({p=pos, s=connid}, true) then return false end end + advtrains.interlocking.remove_tcb_marker_pts(pts) track_circuit_breaks[pts] = nil return true end diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua index 0cc10da..96edadb 100755 --- a/advtrains_interlocking/tcb_ts_ui.lua +++ b/advtrains_interlocking/tcb_ts_ui.lua @@ -550,6 +550,13 @@ minetest.register_entity("advtrains_interlocking:tcbmarker", { static_save = false, }) +function advtrains.interlocking.remove_tcb_marker_pts(pts) + if markerent[pts] then + markerent[pts]:remove() + markerent[pts] = nil + end +end + function advtrains.interlocking.show_tcb_marker(pos) --atdebug("showing tcb marker",pos) local tcb = ildb.get_tcb(pos) @@ -573,9 +580,7 @@ function advtrains.interlocking.show_tcb_marker(pos) end local pts = advtrains.roundfloorpts(pos) - if markerent[pts] then - markerent[pts]:remove() - end + advtrains.interlocking.remove_tcb_marker_pts(pts) local obj = minetest.add_entity(pos, "advtrains_interlocking:tcbmarker") if not obj then return end -- cgit v1.2.3