Make using the default tracks optional, even in submods

If advtrains_train_track is disabled, don't register any tracks that use
its model like the LuaATC automation rail, point speed restriction rail,
station/stop rail.

For LuaATC, the definition for firing an event when a
train runs over the rail needs to be moved into the common defs so that
other mods like linetrack can use that as an interface.
This commit is contained in:
Blockhead 2020-07-07 18:19:56 +10:00 committed by Gabriel Pérez-Cerezo
parent 74bf177cc8
commit ad49854fed
6 changed files with 66 additions and 63 deletions

View File

@ -1 +1,2 @@
advtrains advtrains
advtrains_train_track?

View File

@ -42,14 +42,15 @@ local adefunc = function(def, preset, suffix, rotation)
end end
if minetest.get_modpath("advtrains_train_track") ~= nil then
advtrains.register_tracks("default", { advtrains.register_tracks("default", {
nodename_prefix="advtrains_interlocking:dtrack_npr", nodename_prefix="advtrains_interlocking:dtrack_npr",
texture_prefix="advtrains_dtrack_npr", texture_prefix="advtrains_dtrack_npr",
models_prefix="advtrains_dtrack", models_prefix="advtrains_dtrack",
models_suffix=".b3d", models_suffix=".b3d",
shared_texture="advtrains_dtrack_shared_npr.png", shared_texture="advtrains_dtrack_shared_npr.png",
description="Point Speed Restriction Rail", description="Point Speed Restriction Rail",
formats={}, formats={},
get_additional_definiton = adefunc, get_additional_definiton = adefunc,
}, advtrains.trackpresets.t_30deg_straightonly) }, advtrains.trackpresets.t_30deg_straightonly)
end

View File

@ -1,2 +1,2 @@
advtrains_interlocking advtrains_interlocking
advtrains_train_track advtrains_train_track?

View File

@ -204,14 +204,15 @@ local adefunc = function(def, preset, suffix, rotation)
} }
end end
if minetest.get_modpath("advtrains_train_track") ~= nil then
advtrains.register_tracks("default", { advtrains.register_tracks("default", {
nodename_prefix="advtrains_line_automation:dtrack_stop", nodename_prefix="advtrains_line_automation:dtrack_stop",
texture_prefix="advtrains_dtrack_stop", texture_prefix="advtrains_dtrack_stop",
models_prefix="advtrains_dtrack", models_prefix="advtrains_dtrack",
models_suffix=".b3d", models_suffix=".b3d",
shared_texture="advtrains_dtrack_shared_stop.png", shared_texture="advtrains_dtrack_shared_stop.png",
description="Station/Stop Rail", description="Station/Stop Rail",
formats={}, formats={},
get_additional_definiton = adefunc, get_additional_definiton = adefunc,
}, advtrains.trackpresets.t_30deg_straightonly) }, advtrains.trackpresets.t_30deg_straightonly)
end

View File

@ -165,4 +165,11 @@ if advtrains.lines and advtrains.lines.sched then
end) end)
end end
ac.trackdef_advtrains_defs = {
on_train_enter = function(pos, train_id)
--do async. Event is fired in train steps
atlatc.interrupt.add(0, pos, {type="train", train=true, id=train_id})
end,
}
atlatc.active=ac atlatc.active=ac

View File

@ -131,46 +131,39 @@ function r.fire_event(pos, evtdata)
end end
advtrains.register_tracks("default", { if minetest.get_modpath("advtrains_train_track") ~= nil then
nodename_prefix="advtrains_luaautomation:dtrack", advtrains.register_tracks("default", {
texture_prefix="advtrains_dtrack_atc", nodename_prefix="advtrains_luaautomation:dtrack",
models_prefix="advtrains_dtrack", texture_prefix="advtrains_dtrack_atc",
models_suffix=".b3d", models_prefix="advtrains_dtrack",
shared_texture="advtrains_dtrack_shared_atc.png", models_suffix=".b3d",
description=atltrans("LuaAutomation ATC Rail"), shared_texture="advtrains_dtrack_shared_atc.png",
formats={}, description=atltrans("LuaAutomation ATC Rail"),
get_additional_definiton = function(def, preset, suffix, rotation) formats={},
return { get_additional_definiton = function(def, preset, suffix, rotation)
after_place_node = atlatc.active.after_place_node, return {
after_dig_node = atlatc.active.after_dig_node, after_place_node = atlatc.active.after_place_node,
after_dig_node = atlatc.active.after_dig_node,
on_receive_fields = function(pos, ...) on_receive_fields = function(pos, ...)
atlatc.active.on_receive_fields(pos, ...) atlatc.active.on_receive_fields(pos, ...)
--set arrowconn (for ATC)
--set arrowconn (for ATC) local ph=minetest.pos_to_string(pos)
local ph=minetest.pos_to_string(pos) local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes)
local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes) atlatc.active.nodes[ph].arrowconn=conns[1].c
atlatc.active.nodes[ph].arrowconn=conns[1].c
end,
advtrains = {
on_train_enter = function(pos, train_id)
--do async. Event is fired in train steps
atlatc.interrupt.add(0, pos, {type="train", train=true, id=train_id})
end, end,
}, advtrains = atlatc.active.trackdef_advtrains_defs,
luaautomation = { luaautomation = {
fire_event=r.fire_event fire_event=r.fire_event
},
digiline = {
receptor = {},
effector = {
action = atlatc.active.on_digiline_receive
}, },
}, digiline = {
} receptor = {},
end, effector = {
}, advtrains.trackpresets.t_30deg_straightonly) action = atlatc.active.on_digiline_receive
},
},
}
end,
}, advtrains.trackpresets.t_30deg_straightonly)
end
atlatc.rail = r atlatc.rail = r