Signalling form auto-update

This commit is contained in:
orwell96 2019-02-05 11:40:24 +01:00
parent e7dcee1127
commit 7891c7c342
2 changed files with 13 additions and 0 deletions

View File

@ -320,6 +320,7 @@ function ilrs.update_route(sigd, tcbs, newrte, cancel)
end
end
advtrains.interlocking.update_signal_aspect(tcbs)
advtrains.interlocking.update_player_forms(sigd)
end
-- Try to re-set routes that conflicted with this point

View File

@ -539,6 +539,8 @@ end
-- textlist selection temporary storage
local sig_pselidx = {}
-- Players having a signalling form open
local p_open_sig_form = {}
function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte)
if not minetest.check_player_privs(pname, "train_operator") then
@ -621,11 +623,20 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte)
end
sig_pselidx[pname] = sel_rte
minetest.show_formspec(pname, "at_il_signalling_"..minetest.pos_to_string(sigd.p).."_"..sigd.s, form)
p_open_sig_form[pname] = sigd
-- always a good idea to update the signal aspect
advtrains.interlocking.update_signal_aspect(tcbs)
end
function advtrains.interlocking.update_player_forms(sigd)
for pname, tsigd in pairs(p_open_sig_form) do
if advtrains.interlocking.sigd_equal(sigd, tsigd) then
advtrains.interlocking.show_signalling_form(sigd, pname, nil)
end
end
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
local pname = player:get_player_name()
@ -637,6 +648,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- independent of the formspec, clear this whenever some formspec event happens
local tpsi = sig_pselidx[pname]
sig_pselidx[pname] = nil
p_open_sig_form[pname] = nil
local pts, connids = string.match(formname, "^at_il_signalling_([^_]+)_(%d)$")
local pos, connid