aboutsummaryrefslogtreecommitdiff
path: root/advtrains/signals.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains/signals.lua')
-rw-r--r--advtrains/signals.lua143
1 files changed, 56 insertions, 87 deletions
diff --git a/advtrains/signals.lua b/advtrains/signals.lua
index c03afbf..4dec7f5 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,22 +26,21 @@ 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" }
}
-for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", als="green"}}) do
+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
- advtrains.trackplacer.register_tracktype("advtrains:retrosignal", "")
- advtrains.trackplacer.register_tracktype("advtrains:signal", "")
+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
local crea=1
@@ -74,7 +73,10 @@ 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
+ advtrains.interlocking.signal.unregister_aspect(pos)
+ -- notify trains
+ advtrains.interlocking.signal.notify_trains(pos)
end
end
}},
@@ -88,28 +90,23 @@ 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
+ advtrains.interlocking.signal.unregister_aspect(pos)
+ -- notify trains
+ advtrains.interlocking.signal.notify_trains(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,
+ --TODO add rotation using trackworker
})
- advtrains.trackplacer.add_worked("advtrains:retrosignal", r, rotation, nil)
minetest.register_node("advtrains:signal_"..r..rotation, {
drawtype = "mesh",
@@ -138,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_on_aspect_changed(pos)
- end
end
}},
on_rightclick=function(pos, node, player)
@@ -152,35 +146,28 @@ 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)
+ 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},
+ 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,
+ --TODO add rotation using trackworker
})
- advtrains.trackplacer.add_worked("advtrains:signal", r, rotation, nil)
end
local crea=1
@@ -219,9 +206,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)
@@ -233,28 +217,21 @@ 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)
+ 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" },
+ 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,
},
@@ -294,12 +271,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
@@ -335,12 +308,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)