Module:Sandbox/BrandonXLF/1: Difference between revisions

Content deleted Content added
No edit summary
Restored revision 1241724286 by BrandonXLF (Restorer)
 
(27 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',
buttombottom = '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 =~= 'left' and 'lefthidden' or 'left hidden') .. '">←</div>' ..
'<div>' .. service .. (dest and ' toward ' .. dest or '') .. (note and ' ' .. note or '') .. '</div>' ..
'<div class="' .. (dir == 'right' and 'right<div>→</div>' or 'right hidden') .. '">→</div>' ..
'</div>'
end
 
-- Generate the HTML to display a track (one or more services)
local function displayTrack(floorPart)
localif outnot = displayService(floorPart.service, floorPart.dest, floorPart.dir)then
return {''
end
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].service, floorPart.dest[i], floorPart.destnote[i], floorPart.dir)
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) .. '</div></div>'
end
Line 45 ⟶ 64:
return '<div class="platform ' .. floorPart.platform .. '">' ..
platformLabels[floorPart.platform] ..
(floorPart.acessibleaccessible and ' ' .. mw.getCurrentFrame():expandTemplate{ title = 'access icon' } or '') ..
(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
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 ⟶ 102:
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 nil1
addArg(out, level, createArgTable())
addArg(out[level], part, {})
if servicenumeredParams[param] then
addArg(if not out[level][part],[param] service)then
out[level][part][service][param] = valuecreateArgTable()
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
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 and part and param then
processArg(out, level, part, serviceparam, paramparamNum, v)
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