Module:Cenrail: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 14: | Line 14: | ||
_m.line_table = function (frame) | _m.line_table = function (frame) | ||
local linecode = frame.args[1] or frame.args.code or "CE" | local linecode = frame.args[1] or frame.args.code or "CE" | ||
local | local nether = linecode:sub(1,2) == "N-" | ||
local dim = nether and "the_nether" or "overworld" | |||
local _, line = find_when(function(_, v) return v.code == linecode end, data.lines[dim]) | local _, line = find_when(function(_, v) return v.code == linecode end, data.lines[dim]) | ||
local out = "{| class=\"wikitable\"\n" | local out = "{| class=\"wikitable\"\n" | ||
| Line 23: | Line 24: | ||
out = out .. "|-\n" | out = out .. "|-\n" | ||
for _, stop in ipairs(line.stops) do | for _, stop in ipairs(line.stops) do | ||
local code = (( | local code = ((nether and "N-" or "") .. stop.code) | ||
local _, name = find_when(function(i, v) | local _, name = find_when(function(i, v) | ||
return i == code | return i == code | ||
| Line 32: | Line 33: | ||
countries.get_country_code2(stop.code:sub(1,2)) or {common_name = "??"} | countries.get_country_code2(stop.code:sub(1,2)) or {common_name = "??"} | ||
).common_name .. "]]" | ).common_name .. "]]" | ||
end | |||
local usage_notes = stop.usage_notes or "" | |||
for _, s in ipairs(data.connections) do | |||
local self = nether and 2 or 1 | |||
local other = nether and 1 or 2 | |||
if s[self] == stop.code then | |||
usage_notes = usage_notes .. "<br /> Leshrail connection with " .. s[other].code .. ".<br />" | |||
end | |||
end | end | ||
if type(name) == "table" then name = name[1] end | if type(name) == "table" then name = name[1] end | ||
| Line 37: | Line 46: | ||
out = out .. "| " .. code .. "\n" | out = out .. "| " .. code .. "\n" | ||
out = out .. "| " .. (stop.date_opened or "") .. "\n" | out = out .. "| " .. (stop.date_opened or "") .. "\n" | ||
out = out .. "| " . | out = out .. "| " .. usage_notes .. "\n" | ||
out = out .. "|-\n" | out = out .. "|-\n" | ||
end | end | ||
Revision as of 13:19, 19 October 2025
Documentation for this module may be created at Module:Cenrail/doc
local _m = {}
local data = mw.loadJsonData "Data:NguhRoutes/network.json"
local countries = require "Module:Data/UŊCDSO/Countries"
local find_when = function (predicate, list)
for i, v in pairs(list) do
if predicate(i, v) then
return i, v
end
end
end
_m.line_table = function (frame)
local linecode = frame.args[1] or frame.args.code or "CE"
local nether = linecode:sub(1,2) == "N-"
local dim = nether and "the_nether" or "overworld"
local _, line = find_when(function(_, v) return v.code == linecode end, data.lines[dim])
local out = "{| class=\"wikitable\"\n"
out = out .. "|+ " .. line.name .. " [" .. line.code .. "]\n"
out = out .. "|-\n"
out = out .. "! rowspan = " .. #line.stops .. " style=\"background-color:" .. ( line.color or "#000" ) .. "\" | \n"
out = out .. "! Stop \n! Code \n! Date opened\n! Usage notes\n"
out = out .. "|-\n"
for _, stop in ipairs(line.stops) do
local code = ((nether and "N-" or "") .. stop.code)
local _, name = find_when(function(i, v)
return i == code
end, data.stations)
local country = ""
if stop.code:sub(1,1) ~= "X" then
country = ", [[" .. (
countries.get_country_code2(stop.code:sub(1,2)) or {common_name = "??"}
).common_name .. "]]"
end
local usage_notes = stop.usage_notes or ""
for _, s in ipairs(data.connections) do
local self = nether and 2 or 1
local other = nether and 1 or 2
if s[self] == stop.code then
usage_notes = usage_notes .. "<br /> Leshrail connection with " .. s[other].code .. ".<br />"
end
end
if type(name) == "table" then name = name[1] end
out = out .. "| " .. name .. country .. "\n"
out = out .. "| " .. code .. "\n"
out = out .. "| " .. (stop.date_opened or "") .. "\n"
out = out .. "| " .. usage_notes .. "\n"
out = out .. "|-\n"
end
out = out .. "|}"
return out
end
return _m