Fix more setstate stuff with new API (compat legacy)

This commit is contained in:
orwell 2024-06-11 22:30:40 +02:00
parent 44a8cef1d5
commit 72cae13275
5 changed files with 54 additions and 44 deletions

View File

@ -14,13 +14,11 @@ minetest.override_item("mesecons_switch:mesecon_switch_off", {
minetest.sound_play("mesecons_switch", {pos=pos})
end,
advtrains = {
getstate = "off",
setstate = function(pos, node, newstate)
if newstate=="on" then
advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_on", param2=node.param2})
if advtrains.is_node_loaded(pos) then
mesecon.receptor_on(pos)
end
node_state = "off",
node_state_map = { on = "mesecons_switch:mesecon_switch_on", off = "mesecons_switch:mesecon_switch_off" },
node_on_switch_state = function(pos, new_node, old_state, new_state)
if advtrains.is_node_loaded(pos) then
mesecon.receptor_on(pos)
end
end,
on_updated_from_nodedb = function(pos, node)
@ -41,13 +39,11 @@ minetest.override_item("mesecons_switch:mesecon_switch_on", {
minetest.sound_play("mesecons_switch", {pos=pos})
end,
advtrains = {
getstate = "on",
setstate = function(pos, node, newstate)
if newstate=="off" then
advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_off", param2=node.param2})
if advtrains.is_node_loaded(pos) then
mesecon.receptor_off(pos)
end
node_state = "on",
node_state_map = { on = "mesecons_switch:mesecon_switch_on", off = "mesecons_switch:mesecon_switch_off" },
node_on_switch_state = function(pos, new_node, old_state, new_state)
if advtrains.is_node_loaded(pos) then
mesecon.receptor_off(pos)
end
end,
fallback_state = "off",

View File

@ -70,12 +70,6 @@ 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

View File

@ -74,8 +74,9 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true)
if advtrains.interlocking 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)
advtrains.interlocking.signal.unregister_aspect(pos)
-- notify trains
advtrains.interlocking.signal.notify_trains(pos)
end
end
}},
@ -90,8 +91,9 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true)
if advtrains.interlocking 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)
advtrains.interlocking.signal.unregister_aspect(pos)
-- notify trains
advtrains.interlocking.signal.notify_trains(pos)
end
end
end,
@ -133,9 +135,6 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
rules=advtrains.meseconrules,
["action_"..f.as] = function (pos, node)
advtrains.setstate(pos, f.als, node)
if advtrains.interlocking then
advtrains.interlocking.signal.notify_on_aspect_changed(pos)
end
end
}},
on_rightclick=function(pos, node, player)
@ -156,7 +155,14 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
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
node_on_switch_state = function(pos, new_node, old_state, new_state)
if advtrains.interlocking then
-- forcefully clears any set aspect, so that aspect system doesnt override it again
advtrains.interlocking.signal.unregister_aspect(pos)
-- notify trains
advtrains.interlocking.signal.notify_trains(pos)
end
end,
},
can_dig = can_dig_func,
after_dig_node = after_dig_func,
@ -215,7 +221,14 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
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
node_on_switch_state = function(pos, new_node, old_state, new_state)
if advtrains.interlocking then
-- forcefully clears any set aspect, so that aspect system doesnt override it again
advtrains.interlocking.signal.unregister_aspect(pos)
-- notify trains
advtrains.interlocking.signal.notify_trains(pos)
end
end,
},
can_dig = can_dig_func,
after_dig_node = after_dig_func,
@ -253,12 +266,8 @@ minetest.register_node("advtrains:across_off", {
end
}},
advtrains = {
getstate = "off",
setstate = function(pos, node, newstate)
if newstate == "on" then
advtrains.ndb.swap_node(pos, {name = "advtrains:across_on", param2 = node.param2}, true)
end
end,
node_state = "off",
node_state_map = { on = "advtrains:across_on", off = "advtrains:across_off" },
},
on_rightclick=function(pos, node, player)
if advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
@ -294,12 +303,8 @@ minetest.register_node("advtrains:across_on", {
end
}},
advtrains = {
getstate = "on",
setstate = function(pos, node, newstate)
if newstate == "off" then
advtrains.ndb.swap_node(pos, {name = "advtrains:across_off", param2 = node.param2}, true)
end
end,
node_state = "on",
node_state_map = { on = "advtrains:across_on", off = "advtrains:across_off" },
fallback_state = "off",
},
on_rightclick=function(pos, node, player)

View File

@ -211,6 +211,21 @@ function signal.clear_aspect(pos, skip_dst_notify)
end
end
-- Clear any info about aspects from this signal, without resetting/reapplying the aspect.
-- Supposed to be used for legacy on-off signals when the on-off toggle is used
function signal.unregister_aspect(pos)
local main_pts = advtrains.encode_pos(pos)
local old_tbl = signal.aspects[main_pts]
local old_remote = old_tbl and old_tbl.remote
-- unregister from old remote
if old_remote then
signal.distant_refs[old_remote][main_pts] = nil
end
signal.aspects[main_pts] = nil
end
-- Notify distant signals of main_pts of a change in the aspect of this signal
--
function signal.notify_distants_of(main_pts, limit)

View File

@ -447,9 +447,9 @@ for _, rtab in ipairs {
end,
]]
},
on_rightclick = advtrains.interlocking.signal_rc_handler,
can_dig = advtrains.interlocking.signal_can_dig,
after_dig_node = advtrains.interlocking.signal_after_dig,
on_rightclick = advtrains.interlocking.signal.on_rightclick,
can_dig = advtrains.interlocking.signal.can_dig,
after_dig_node = advtrains.interlocking.signal.after_dig,
})
--advtrains.trackplacer.add_worked("advtrains_signals_japan:"..sigtype, asp, "_"..rot)
end