Content deleted Content added
BrandonXLF (talk | contribs) No edit summary |
BrandonXLF (talk | contribs) Restored revision 1241724286 by BrandonXLF (Restorer) |
||
(28 intermediate revisions by the same user not shown) | |||
Line 5:
local p = {}
-- Parameters that can be numbered
local numeredParams = {
service = true,
dest = true,
note = true
-- Labels for platform types
local platformLabels = {
island = 'Island platform',
top = 'Side platform',
}
-- Generate the HTML to display a service
local function displayService(service, dest, note, dir)
if not service then return '' end
return '<div class="service">' ..
'<div class="' .. (dir
'<div>' .. service .. (dest and ' toward ' .. dest or '') .. (note and ' ' .. note or '') .. '</div>' ..
'</div>'
end
-- Generate the HTML to display a track (one or more services)
local function displayTrack(floorPart)
floorPart.dest = floorPart.dest or {}
floorPart.note = floorPart.note or {}
local out = ''
for i = 1, floorPart.service.max do
out = out .. displayService(floorPart.service[i]
end
Line 31 ⟶ 48:
end
-- Generate the HTML to generate a "row" of the floor
local function displayFloorPart(floorPart, floorNum, partNum)
local out = ''
if floorPart.name then
return '<div class="track"><div>' .. floorPart.name .. '</div></div>' ..
'<div class="track"><div class="desc"><div>' .. (floorPart.desc or '') .. '</div>' .. displayTrack(floorPart) end
Line 45 ⟶ 64:
return '<div class="platform ' .. floorPart.platform .. '">' ..
platformLabels[floorPart.platform] ..
(floorPart.
(floorPart.note and ', ' .. floorPart.note or '') ..
'</div>'
end
Line 54 ⟶ 74:
end
-- Generate the HTML to display a floor
local function displayFloor(stationFloor, num, last)
local out = '<div class="floor' .. (last and ' last' or '') .. '" style="grid-row: span ' .. stationFloor.count .. ';">' .. stationFloor.letter .. '</div>'
for i = 1, stationFloor.max do
Line 64 ⟶ 85:
end
-- Create a table that can hold numbered arguments
local function createArgTable(tbl)
▲ return {
tbl = tbl or {}
max = 0,▼
count = 0▼
▲ }
return tbl
end
-- Add an argument number to a table of numbered arguments
local function addArg(tbl, num, value)
if num > tbl.max then
tbl.max = num
Line 77 ⟶ 102:
if not tbl[num] then
tbl[num] =
tbl.count = tbl.count + 1
end
end
-- Process an argument with the format level_part_param[paramNum]
local function processArg(out, level, part,
level = tonumber(level)
part = tonumber(part)
addArg(out, level, createArgTable())
addArg(out[level], part, {})
if
out[level][part
end
addArg(out[level][part][param], paramNum, value)
else
out[level][part][param] = value
Line 98 ⟶ 127:
end
-- Process the argument table
local function processArgs(args)
local out = createArgTable()
Line 103 ⟶ 133:
for i, v in pairs(args) do
if type(i) == 'number' then
▲ out[level] = createArgTable()
▲ end
else
local level, part,
if level and part and param then
processArg(out, level, part,
end
end
Line 122 ⟶ 146:
end
-- Main function, called by wikitext
function p.main(frame)
local sortedArgs = processArgs(frame.args)
Line 133 ⟶ 157:
for i = 1, sortedArgs.max do
out = out .. displayFloor(sortedArgs[i], i, i == sortedArgs.max)
end
|