Fix demo signals

master
orwell96 2018-10-25 22:49:30 +02:00
parent f007017aa4
commit 6bb6c7d345
2 changed files with 63 additions and 47 deletions

View File

@ -5,6 +5,42 @@
-- advtrains_signal=1 is meant for signals that do not implement set_aspect. -- advtrains_signal=1 is meant for signals that do not implement set_aspect.
local setaspect = function(pos, node, asp)
if not asp.main.free then
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_danger"})
else
if asp.dst.free and asp.main.speed == -1 then
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_free"})
else
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_slow"})
end
end
local meta = minetest.get_meta(pos)
if meta then
meta:set_string("infotext", minetest.serialize(asp))
end
end
local suppasp = {
main = {
free = nil,
speed = {6, -1},
},
dst = {
free = nil,
speed = nil,
},
shunt = {
free = false,
proceed_as_main = true,
},
info = {
call_on = false,
dead_end = false,
w_speed = nil,
}
}
minetest.register_node("advtrains_interlocking:ds_danger", { minetest.register_node("advtrains_interlocking:ds_danger", {
description = "Demo signal at Danger", description = "Demo signal at Danger",
tiles = {"at_il_signal_asp_danger.png"}, tiles = {"at_il_signal_asp_danger.png"},
@ -15,21 +51,11 @@ minetest.register_node("advtrains_interlocking:ds_danger", {
}, },
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
advtrains = { advtrains = {
set_aspect = function(pos, node, asp) set_aspect = setaspect,
if asp.main.free then supported_aspects = suppasp,
if asp.dst.free and asp.main.speed > 50 then get_aspect = function(pos, node)
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_free"}) return advtrains.interlocking.DANGER
else end,
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_slow"})
end
else
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_danger"})
end
local meta = minetest.get_meta(pos)
if meta then
meta:set_string("infotext", minetest.serialize(asp))
end
end
}, },
on_rightclick = advtrains.interlocking.signal_rc_handler, on_rightclick = advtrains.interlocking.signal_rc_handler,
can_dig = advtrains.interlocking.signal_can_dig, can_dig = advtrains.interlocking.signal_can_dig,
@ -44,21 +70,16 @@ minetest.register_node("advtrains_interlocking:ds_free", {
}, },
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
advtrains = { advtrains = {
set_aspect = function(pos, node, asp) set_aspect = setaspect,
if asp.main.free then supported_aspects = suppasp,
if asp.dst.free and asp.main.speed > 50 then get_aspect = function(pos, node)
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_free"}) return {
else main = {
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_slow"}) free = true,
end speed = -1,
else }
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_danger"}) }
end end,
local meta = minetest.get_meta(pos)
if meta then
meta:set_string("infotext", minetest.serialize(asp))
end
end
}, },
on_rightclick = advtrains.interlocking.signal_rc_handler, on_rightclick = advtrains.interlocking.signal_rc_handler,
can_dig = advtrains.interlocking.signal_can_dig, can_dig = advtrains.interlocking.signal_can_dig,
@ -73,21 +94,16 @@ minetest.register_node("advtrains_interlocking:ds_slow", {
}, },
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
advtrains = { advtrains = {
set_aspect = function(pos, node, asp) set_aspect = setaspect,
if asp.main.free then supported_aspects = suppasp,
if asp.dst.free and asp.main.speed > 50 then get_aspect = function(pos, node)
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_free"}) return {
else main = {
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_slow"}) free = true,
end speed = 6,
else }
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_danger"}) }
end end,
local meta = minetest.get_meta(pos)
if meta then
meta:set_string("infotext", minetest.serialize(asp))
end
end
}, },
on_rightclick = advtrains.interlocking.signal_rc_handler, on_rightclick = advtrains.interlocking.signal_rc_handler,
can_dig = advtrains.interlocking.signal_can_dig, can_dig = advtrains.interlocking.signal_can_dig,

View File

@ -238,7 +238,7 @@ function advtrains.interlocking.signal_rc_handler(pos, node, player, itemstack,
advtrains.interlocking.show_signalling_form(sigd, pname) advtrains.interlocking.show_signalling_form(sigd, pname)
else else
-- permit to set aspect manually -- permit to set aspect manually
minetest.show_formspec(pname, "at_il_sigasp_"..minetest.pos_to_string(pos), "field[aspect;Set Aspect (F/D)Speed(F/D)Speed(F/D) %['A' to assign IP%];D0D0D]") minetest.show_formspec(pname, "at_il_sigasp_"..minetest.pos_to_string(pos), "field[aspect;Set Aspect ('A' to assign IP);D0D0D]")
end end
end end
@ -252,7 +252,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
advtrains.interlocking.show_ip_form(pos, pname) advtrains.interlocking.show_ip_form(pos, pname)
return return
end end
local mfs, msps, dfs, dsps, shs = string.match(fields.aspect, "^([FD])([0-9]+)([FD])([0-9]+)([FD])$") local mfs, msps, dfs, dsps, shs = string.match(fields.aspect, "^([FD])([-0-9]+)([FD])([-0-9]+)([FD])$")
local asp = { local asp = {
main = { main = {
free = mfs=="F", free = mfs=="F",