Module:Sandbox/BrandonXLF/1: Difference between revisions

Content deleted Content added
No edit summary
Support new format, added comments
Line 1:
-- Sandbox, do not delete
 
require('strict')
 
local p = {}
 
-- Labels for platform types
local platformLabels = {
island = 'Island platform',
Line 11 ⟶ 10:
}
 
-- Generate the HTML to display a service
local function displayService(service, dest, dir)
if not service then return '' end
Line 21:
end
 
-- Generate the HTML to display a track (one or more services)
local function displayTrack(floorPart)
local out = displayService(floorPart.service, floorPart.dest, floorPart.dir)
-- Add extra (numbered) services
for i = 1, floorPart.max do
if floorPart.extraservice then
out = out .. displayService(floorPart[i].service, floorPart[i].dest, floorPart.dir)
for i = 1, floorPart.extraservice.max do
out = out .. displayService(floorPart.extraservice[i].service, floorPart.extradest[i].dest, floorPart.dir)
end
end
Line 31 ⟶ 35:
end
 
-- Generate the HTML to generate a "row" of the floor
local function displayFloorPart(floorPart, floorNum, partNum)
local out = ''
Line 54 ⟶ 59:
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>'
Line 64 ⟶ 70:
end
 
-- Create a table that can hold numbered arguments
local function createArgTable(tbl)
return {
tbl = tbl or {}
max = 0,
}
count = 0
tbl.max = 0,
}
tbl.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 ⟶ 87:
if not tbl[num] then
tbl[num] = createArgTable()value
tbl.count = tbl.count + 1
end
end
-- Process an argument with the format level_part_param[paramNum]
local function processArg(out, level, part, serviceparam, paramparamNum, value)
level = tonumber(level)
part = tonumber(part)
serviceparamNum = serviceparamNum and tonumber(serviceparamNum) or nil
addArg(out, level, createArgTable())
addArg(out[level], part, {})
if serviceparamNum then
addArg(out[level][part],['extra' service.. param] = createArgTable()
addArg(out[level][part][service]['extra' .. param], =paramNum, value)
else
out[level][part][param] = value
Line 98 ⟶ 109:
end
-- Process the argument table
local function processArgs(args)
local out = createArgTable()
Line 103 ⟶ 115:
for i, v in pairs(args) do
if type(i) == 'number' then
addArg(out[level], =i, createArgTable({ letter = v }))
local level = tonumber(i)
if not out[level] then
out[level] = createArgTable()
end
out[level].letter = v
else
local level, part, serviceparam, paramparamNum = i:match('(%d+)_(%d+)_?([^%d*]+)_(.+%d*)')
if level then
processArg(out, level, part, serviceparam, paramparamNum, v)
end
end
Line 122 ⟶ 128:
end
 
-- Main function, called by wikitext
 
function p.main(frame)
local sortedArgs = processArgs(frame.args)