Module:Cenrail: Difference between revisions

From Nguhcraft Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:


local find_when = function (predicate, list)
local find_when = function (predicate, list)
for i, v in ipairs(list) do
for i, v in pairs(list) do
if predicate(i, v) then
if predicate(i, v) then
return i, v
return i, v
Line 17: Line 17:
local out = "{| class=\"wikitable\"\n"
local out = "{| class=\"wikitable\"\n"
out = out .. "|+ " .. line.name .. " [" .. line.code .. "]\n"
out = out .. "|+ " .. line.name .. " [" .. line.code .. "]\n"
out = out .. "|-"
out = out .. "|-\n"
out = out .. "! rowspan = " .. #line.stops + 1 + (line.loop and 1 or 0) .. " style=\"background-color:#000\" | \n"
out = out .. "! rowspan = " .. 2 .. " style=\"background-color:#000\" | \n"
out = out .. "! Stop \n! Code \n"
out = out .. "! Stop \n! Code \n"
out = out .. "|-"
out = out .. "|-\n"
for _, stop in ipairs(line.stops) do
local name = find_when(function(i, v)
return i == ((dim == "the_nether" and "N-" or "") .. stop.code)
end, data.stations)
if type(name) == "table" then name = name[1] end
out = out .. "| " .. name .. "\n"
out = out .. "| " .. stop.code .. "\n"
out = out .. "|-\n"
end
out = out .. "|}"
out = out .. "|}"
return out
return out

Revision as of 12:56, 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 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 dim = linecode:sub(1,2) == "N-" 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 = " .. 2 .. " style=\"background-color:#000\" | \n"
	out = out .. "! Stop \n! Code \n"
	out = out .. "|-\n"
	for _, stop in ipairs(line.stops) do
		local name = find_when(function(i, v)
			return i == ((dim == "the_nether" and "N-" or "") .. stop.code)
		end, data.stations)
		if type(name) == "table" then name = name[1] end
		out = out .. "| " .. name .. "\n"
		out = out .. "| " .. stop.code .. "\n" 
		out = out .. "|-\n"
	end
	out = out .. "|}"
	return out
end

return _m