From f52653209aecb2310c1fb9598391c86113296f27 Mon Sep 17 00:00:00 2001 From: orwell Date: Fri, 24 May 2024 00:00:12 +0200 Subject: Fix working of the legacy signals under new system --- advtrains/passive.lua | 6 +++ advtrains/signals.lua | 111 ++++++++++++++++++-------------------------------- 2 files changed, 45 insertions(+), 72 deletions(-) (limited to 'advtrains') diff --git a/advtrains/passive.lua b/advtrains/passive.lua index 37b79e4..aad309e 100644 --- a/advtrains/passive.lua +++ b/advtrains/passive.lua @@ -70,6 +70,12 @@ function advtrains.setstate(parpos, newstate, pnode) end -- invalidate paths (only relevant if this is a track) advtrains.invalidate_all_paths(pos) + -- hack for old signals. Compatibility only, DO NOT USE for new signals! + if advtrains.interlocking and ndef.advtrains._is_passivenode_signal then + -- forcefully clears any set aspect, so that aspect system doesnt override it again + -- implicitly does an signal.notify_trains(pos) + advtrains.interlocking.signal.clear_aspect(pos) + end return true end diff --git a/advtrains/signals.lua b/advtrains/signals.lua index 58d28a5..0b874bf 100644 --- a/advtrains/signals.lua +++ b/advtrains/signals.lua @@ -5,13 +5,13 @@ local mrules_wallsignal = advtrains.meseconrules local function can_dig_func(pos) if advtrains.interlocking then - return advtrains.interlocking.signal_can_dig(pos) + return advtrains.interlocking.signal.can_dig(pos) end return true end local function after_dig_func(pos) if advtrains.interlocking then - return advtrains.interlocking.signal_after_dig(pos) + return advtrains.interlocking.signal.after_dig(pos) end return true end @@ -26,18 +26,20 @@ return { } end -local suppasp = { - main = {0, -1}, - dst = {false}, - shunt = nil, - proceed_as_main = true, - info = { - call_on = false, - dead_end = false, - w_speed = nil, - } +local main_aspects = { + { name = "free", description = "Free" } } +local function simple_apply_aspect(offname, onname) + return function(pos, node, main_aspect, rem_aspect, rem_aspinfo) + if main_aspect.halt then + advtrains.ndb.swap_node(pos, {name = offname, param2 = node.param2}) + else + advtrains.ndb.swap_node(pos, {name = onname, param2 = node.param2}) + end + end +end + for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", als="green"}}) do for rotid, rotation in ipairs({"", "_30", "_45", "_60"}) do @@ -71,7 +73,9 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", ["action_"..f.as] = function (pos, node) advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true) if advtrains.interlocking then - advtrains.interlocking.signal_on_aspect_changed(pos) + -- forcefully clears any set aspect, so that aspect system doesnt override it again + -- implicitly does an signal.notify_trains(pos) + advtrains.interlocking.signal.clear_aspect(pos) end end }}, @@ -85,23 +89,17 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true) if advtrains.interlocking then - advtrains.interlocking.signal_on_aspect_changed(pos) + -- forcefully clears any set aspect, so that aspect system doesnt override it again + -- implicitly does an signal.notify_trains(pos) + advtrains.interlocking.signal.clear_aspect(pos) end end end, - -- new signal API + -- very new signal API advtrains = { - set_aspect = function(pos, node, asp) - if asp.main ~= 0 then - advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_on"..rotation, param2 = node.param2}, true) - else - advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_off"..rotation, param2 = node.param2}, true) - end - end, - get_aspect = function(pos, node) - return aspect(r=="on") - end, - supported_aspects = suppasp, + main_aspects = main_aspects, + apply_aspect = simple_apply_aspect("advtrains:retrosignal_off"..rotation, "advtrains:retrosignal_on"..rotation), + get_aspect_info = function() return aspect(r=="on") end, }, can_dig = can_dig_func, after_dig_node = after_dig_func, @@ -136,7 +134,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", ["action_"..f.as] = function (pos, node) advtrains.setstate(pos, f.als, node) if advtrains.interlocking then - advtrains.interlocking.signal_on_aspect_changed(pos) + advtrains.interlocking.signal.notify_on_aspect_changed(pos) end end }}, @@ -149,30 +147,16 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", advtrains.interlocking.show_ip_form(pos, pname) elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then advtrains.setstate(pos, f.als, node) - if advtrains.interlocking then - advtrains.interlocking.signal_on_aspect_changed(pos) - end end end, - -- new signal API + -- very new signal API advtrains = { - set_aspect = function(pos, node, asp) - if asp.main ~= 0 then - advtrains.ndb.swap_node(pos, {name = "advtrains:signal_on"..rotation, param2 = node.param2}, true) - else - advtrains.ndb.swap_node(pos, {name = "advtrains:signal_off"..rotation, param2 = node.param2}, true) - end - end, - get_aspect = function(pos, node) - return aspect(r=="on") - end, - supported_aspects = suppasp, - getstate = f.ls, - setstate = function(pos, node, newstate) - if newstate == f.als then - advtrains.ndb.swap_node(pos, {name = "advtrains:signal_"..f.as..rotation, param2 = node.param2}, true) - end - end, + main_aspects = main_aspects, + apply_aspect = simple_apply_aspect("advtrains:signal_off"..rotation, "advtrains:signal_on"..rotation), + get_aspect_info = function() return aspect(r=="on") end, + node_state = f.ls, + node_state_map = { red = "advtrains:signal_off"..rotation, green = "advtrains:signal_on"..rotation}, + _is_passivenode_signal = true }, can_dig = can_dig_func, after_dig_node = after_dig_func, @@ -211,9 +195,6 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", rules = mrules_wallsignal, ["action_"..f.as] = function (pos, node) advtrains.setstate(pos, f.als, node) - if advtrains.interlocking then - advtrains.interlocking.signal_on_aspect_changed(pos) - end end }}, on_rightclick=function(pos, node, player) @@ -225,30 +206,16 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", advtrains.interlocking.show_ip_form(pos, pname) elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then advtrains.setstate(pos, f.als, node) - if advtrains.interlocking then - advtrains.interlocking.signal_on_aspect_changed(pos) - end end end, - -- new signal API + -- very new signal API advtrains = { - set_aspect = function(pos, node, asp) - if asp.main ~= 0 then - advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_on", param2 = node.param2}, true) - else - advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_off", param2 = node.param2}, true) - end - end, - get_aspect = function(pos, node) - return aspect(r=="on") - end, - supported_aspects = suppasp, - getstate = f.ls, - setstate = function(pos, node, newstate) - if newstate == f.als then - advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_"..f.as, param2 = node.param2}, true) - end - end, + main_aspects = main_aspects, + apply_aspect = simple_apply_aspect("advtrains:signal_wall_"..loc.."_off", "advtrains:signal_wall_"..loc.."_on"), + get_aspect_info = function() return aspect(r=="on") end, + node_state = f.ls, + node_state_map = { red = "advtrains:signal_wall_"..loc.."_off", green = "advtrains:signal_wall_"..loc.."_on" }, + _is_passivenode_signal = true }, can_dig = can_dig_func, after_dig_node = after_dig_func, -- cgit v1.2.3