Module:Cenrail: Difference between revisions

From Nguhcraft Wiki
Jump to navigation Jump to search
add date formating
Cleanup part 1
Line 1: Line 1:
local _m = {}
local _m = {}


local line_data = require( 'Module:Data/Cenrail/Lines' )
local data = mw.loadJsonData "Data:NguhRoutes/network.json"
local stop_data = require( 'Module:Data/Cenrail/Stops' )


local function formatDate (d)
local find_when = function (predicate, list)
tbl = {
for i, v in ipairs(list) do
year = tonumber(d:sub(1,4)),
if predicate(i, v) then
month = tonumber(d:sub(6,7)),
return i, v
day = tonumber(9,10)
end
}
end
return os.date("%d %B %Y", os.time(tbl))
end
end


_m.showline = function(frame)
_m.line_table = function (frame)
local line = frame.args[1] or "central"
local linecode = frame.args[1] or frame.args.code or "CE"
local data = line_data[line]
local dim = linecode:sub(1,2) == "N-" and "the_nether" or "overworld"
local text = "{| class=\"wikitable\"\n"
local _, line = find_when(function(_, v) return v.code == linecode end, data.lines[dim])
if not (data.is_local or data.is_minor) then
local out = "{|\n"
text = text .. "!"
out = out .. "|+ " .. line.name .. " [" .. line.code .. "]\n"
.. "rowspan=\"" .. tostring(#data.stops + 1 + (data.loop and 1 or 0)) .. "\""
out = out .. "|-"
.. "style=\"background-color:#" .. data.color .. "\""
.. "|\n"
return out
end
text = text .. "!Stop\n!Code\n!Date opened\n!Notes\n"
for _, stop in ipairs(data.stops) do
local sdata = stop_data[stop] or {name=stop}
text = text .. "|-\n"
text = text .. "|" .. sdata.name .. (sdata.country and ", " .. sdata.country or "") .. "\n"
text = text .. "|" .. stop .. "\n"
text = text .. "|" .. (sdata.date_opened and formatDate(sdata.date_opened) or "") .. "\n"
text = text .. "|" .. (sdata.notes or "") .. "\n"
end
if data.loop then
text = text .. "|-\n! colspan=\"4\"| ''Line loops back to first stop''\n"
end
text = text .. "|}\n"
return text
end
end


return _m
return _m

Revision as of 12:44, 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 ipairs(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 = "{|\n"
	out = out .. "|+ " .. line.name .. " [" .. line.code .. "]\n"
	out = out .. "|-"
	
	return out
end

return _m