aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--advtrains_interlocking/demosignals.lua106
-rw-r--r--advtrains_interlocking/signal_api.lua4
2 files changed, 63 insertions, 47 deletions
diff --git a/advtrains_interlocking/demosignals.lua b/advtrains_interlocking/demosignals.lua
index c19b578..ab7a8b6 100644
--- a/advtrains_interlocking/demosignals.lua
+++ b/advtrains_interlocking/demosignals.lua
@@ -5,6 +5,42 @@
-- 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", {
description = "Demo signal at Danger",
tiles = {"at_il_signal_asp_danger.png"},
@@ -15,21 +51,11 @@ minetest.register_node("advtrains_interlocking:ds_danger", {
},
sounds = default.node_sound_stone_defaults(),
advtrains = {
- set_aspect = function(pos, node, asp)
- if asp.main.free then
- if asp.dst.free and asp.main.speed > 50 then
- advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_free"})
- else
- 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
+ set_aspect = setaspect,
+ supported_aspects = suppasp,
+ get_aspect = function(pos, node)
+ return advtrains.interlocking.DANGER
+ end,
},
on_rightclick = advtrains.interlocking.signal_rc_handler,
can_dig = advtrains.interlocking.signal_can_dig,
@@ -44,21 +70,16 @@ minetest.register_node("advtrains_interlocking:ds_free", {
},
sounds = default.node_sound_stone_defaults(),
advtrains = {
- set_aspect = function(pos, node, asp)
- if asp.main.free then
- if asp.dst.free and asp.main.speed > 50 then
- advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_free"})
- else
- 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
+ set_aspect = setaspect,
+ supported_aspects = suppasp,
+ get_aspect = function(pos, node)
+ return {
+ main = {
+ free = true,
+ speed = -1,
+ }
+ }
+ end,
},
on_rightclick = advtrains.interlocking.signal_rc_handler,
can_dig = advtrains.interlocking.signal_can_dig,
@@ -73,21 +94,16 @@ minetest.register_node("advtrains_interlocking:ds_slow", {
},
sounds = default.node_sound_stone_defaults(),
advtrains = {
- set_aspect = function(pos, node, asp)
- if asp.main.free then
- if asp.dst.free and asp.main.speed > 50 then
- advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_free"})
- else
- 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
+ set_aspect = setaspect,
+ supported_aspects = suppasp,
+ get_aspect = function(pos, node)
+ return {
+ main = {
+ free = true,
+ speed = 6,
+ }
+ }
+ end,
},
on_rightclick = advtrains.interlocking.signal_rc_handler,
can_dig = advtrains.interlocking.signal_can_dig,
diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua
index 458fc70..9238587 100644
--- a/advtrains_interlocking/signal_api.lua
+++ b/advtrains_interlocking/signal_api.lua
@@ -238,7 +238,7 @@ function advtrains.interlocking.signal_rc_handler(pos, node, player, itemstack,
advtrains.interlocking.show_signalling_form(sigd, pname)
else
-- 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
@@ -252,7 +252,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
advtrains.interlocking.show_ip_form(pos, pname)
return
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 = {
main = {
free = mfs=="F",