![]() | Please do not delete this module or its doc page. |
Parameters
(floor#)
- Sets the name of a floor
(floor#)_(part#)_(param)
- Sets a parameter for a row of a floor where (param)
is:
name
- The name of the row, e.g. "Westbound track"desc
- The description for the row- Services
dir
- The direction of the service(s) for the track (right
orleft
)service
- The service running on the trackservice(service#)
- Additional services running on the trackdest
- The destination for the servicedest(service#)
- Destinations for the additional servicesnote
- Note about the servicesnote(service#)
- Notes about the additional services
- Platform
platform
- The type of platformaccessible
- Set if the platform isaccessible
note
- Note about the platform
-- Sandbox, do not delete
require('strict')
local p = {}
local function displayService(service, dest, dir)
if not service then return '' end
return '<div>' .. (dir == 'left' and '←' or '→') .. ' ' .. service .. ' toward ' .. dest .. '</div>'
end
local function displayTrack(floorPart)
local out = displayService(floorPart.service, floorPart.dest, floorPart.dir)
for i = 1, floorPart.max do
out = out .. displayService(floorPart[i].service, floorPart[i].dest, floorPart.dir)
end
return out
end
local function displayFloorPart(floorPart, floorNum, partNum)
local out = '<div style="display: grid; grid-template-columns: max-content 1fr;">'
if floorPart.name then
out = out .. '<div>' .. floorPart.name .. '</div>'
out = out .. '<div>' .. displayTrack(floorPart) .. '</div>'
elseif floorPart.platform then
out = out .. '<div style="grid-column: span 2;">' .. floorPart.platform .. '</div>'
else
local prefix = floorNum .. '_' .. partNum .. '_'
out = out .. 'Invalid floor part! Must have either <code>' .. prefix .. 'name</code> or <code>' .. prefix .. 'platform</code>.'
end
return out .. '</div>'
end
local function displayFloor(stationFloor, num)
local out = '<div>' .. stationFloor.letter .. '</div>'
out = out .. '<div>'
for i = 1, stationFloor.max do
out = out .. displayFloorPart(stationFloor[i], num, i)
end
return out .. '</div>'
end
local function addArg(tbl, num)
if num > tbl.max then
tbl.max = num
end
if not tbl[num] then
tbl[num] = { max = 0 }
end
end
local function processArg(out, level, part, service, param, value)
level = tonumber(level)
part = tonumber(part)
service = service and tonumber(service) or nil
addArg(out, level)
addArg(out[level], part)
if service then
addArg(out[level][part], service)
out[level][part][service][param] = value
else
out[level][part][param] = value
end
end
local function processArgs(args)
local out = { max = 0 }
for i, v in pairs(args) do
if type(i) == 'number' then
local level = tonumber(i)
if not out[level] then
out[level] = { max = 0 }
end
out[level].letter = v
else
local level, part, service, param = i:match('(%d+)_(%d+)_?(%d*)_(.+)')
if level then
processArg(out, level, part, service, param, v)
end
end
end
return out
end
function p.main(frame)
local sortedArgs = processArgs(frame.args)
local out = '<div style="display: grid; grid-template-columns: max-content 1fr;">'
for i = 1, sortedArgs.max do
out = out .. displayFloor(sortedArgs[i], i)
end
return out .. '</div>'
end
return p