aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/signal_api.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains_interlocking/signal_api.lua')
-rw-r--r--advtrains_interlocking/signal_api.lua125
1 files changed, 0 insertions, 125 deletions
diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua
index 6e862a8..78acc0a 100644
--- a/advtrains_interlocking/signal_api.lua
+++ b/advtrains_interlocking/signal_api.lua
@@ -411,128 +411,3 @@ minetest.register_on_punchnode(function(pos, node, player, pointed_thing)
players_assign_ip[pname] = nil
end
end)
-
-
---== aspect selector ==--
-
-local players_aspsel = {}
-
---[[
-suppasp: "supported_aspects" table
-purpose: form title string
-callback: func(pname, aspect) called on form submit
-isasp: aspect currently set
-]]
-local function make_signal_aspect_selector_t1(suppasp, purpose, isasp)
- local form = {"size[7,7]"}
- form[#form+1] = string.format("label[0.5,0.5;%s]", attrans_formspec("Select signal aspect"))
- form[#form+1] = string.format("label[0.5,1;%s]", minetest.formspec_escape(purpose))
-
- form[#form+1] = string.format("label[0.5,1.5;%s]", attrans_formspec("Main aspect"))
- local entries = {}
- local selid = 1
- for idx, spv in ipairs(suppasp.main) do
- local entry
- if isasp and spv == isasp.main then
- selid = idx
- end
- if spv == 0 then
- entry = attrans("Danger (halt)")
- elseif spv == -1 then
- entry = attrans("Continue at maximum speed")
- elseif not spv then
- entry = attrans("No info: continue with current speed limit")
- else
- entry = attrans("Continue with the speed limit of @1", spv)
- end
- entries[idx] = minetest.formspec_escape(entry)
- end
- form[#form+1] = string.format("dropdown[0.5,2;6;main;%s;%d;true]", table.concat(entries,","), selid)
-
- form[#form+1] = string.format("label[0.5,3;%s]", attrans_formspec("Shunt aspect"))
- if suppasp.shunt == nil then
- local st = 1
- if isasp and isasp.shunt then st = 2 end
- form[#form+1] = string.format("dropdown[0.5,3.5;6;shunt_free;%s,%s;%d;true]",
- attrans_formspec("No shunting"),
- attrans_formspec("Shunting allowed"),
- st)
- end
-
- form[#form+1] = string.format("label[0.5,4.5;%s]", attrans_formspec("Distant aspect"))
- local entries = {}
- local selid = 1
- for idx, spv in ipairs(suppasp.dst) do
- local entry
- if isasp and spv == isasp.dst then
- selid = idx
- end
- if spv == 0 then
- entry = attrans("Expect to stop at the next signal")
- elseif spv == -1 then
- entry = attrans("Expect to continue at maximum speed")
- elseif not spv then
- entry = attrans("No info")
- else
- entry = attrans("Expect to continue with a speed limit of @1", spv)
- end
- entries[idx] = minetest.formspec_escape(entry)
- end
- form[#form+1] = string.format("dropdown[0.5,5;6;dst;%s;%d;true]", table.concat(entries, ","), selid)
- form[#form+1] = string.format("button_exit[0.5,6;5,1;save;%s]", attrans_formspec("Save signal aspect"))
- return table.concat(form)
-end
-
-function advtrains.interlocking.show_signal_aspect_selector(pname, p_suppasp, p_purpose, callback, isasp)
- local suppasp = p_suppasp or {
- main = {0, -1}, dst = {false}, shunt = false, info = {},
- }
- local purpose = p_purpose or ""
-
- local form = make_signal_aspect_selector_t1(suppasp, purpose, isasp)
-
- local token = advtrains.random_id()
-
- minetest.show_formspec(pname, "at_il_sigaspdia_"..token, form)
-
- minetest.after(1, function()
- players_aspsel[pname] = {
- suppasp = suppasp,
- callback = callback,
- token = token,
- }
- end)
-end
-
-local function usebool(sup, val, free)
- if sup == nil then
- return val==free
- else
- return sup
- end
-end
-
-minetest.register_on_player_receive_fields(function(player, formname, fields)
- local pname = player:get_player_name()
- local psl = players_aspsel[pname]
- if psl then
- if formname == "at_il_sigaspdia_"..psl.token then
- if fields.save then
- local maini = tonumber(fields.main)
- if not maini then return end
- local dsti = tonumber(fields.dst)
- if not dsti then return end
- local asp = {
- main = psl.suppasp.main[maini],
- dst = psl.suppasp.dst[dsti],
- shunt = usebool(psl.suppasp.shunt, fields.shunt_free, "2"),
- info = {}
- }
- psl.callback(pname, asp)
- end
- else
- players_aspsel[pname] = nil
- end
- end
-
-end)