Module:Sandbox/BrandonXLF/1: Difference between revisions

Content deleted Content added
No edit summary
Restored revision 1241724286 by BrandonXLF (Restorer)
 
(579 intermediate revisions by the same user not shown)
Line 1:
-- Sandbox, do not delete
-- Keep Here
 
require('strict')
 
local p = {}
 
local args = {}
-- Parameters that can be numbered
local function is_set( var )
local numeredParams = {
return not (var == nil or var == '');
service = true,
dest = true,
note = true
}
 
-- Labels for platform types
local platformLabels = {
island = 'Island platform',
top = 'Side platform',
bottom = '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 'hidden' or '') .. '">←</div>' ..
'<div>' .. service .. (dest and ' toward ' .. dest or '') .. (note and ' ' .. note or '') .. '</div>' ..
(dir == 'right' and '<div>→</div>' or '') ..
'</div>'
end
 
function p.main()
-- Generate the HTML to display a track (one or more services)
local houoff;
local function displayTrack(floorPart)
local minoff;
if not floorPart.service then
local sign2;
return ''
local arger1;
end
local help;
floorPart.dest = floorPart.dest or {}
floorPart.note = floorPart.note or {}
local out = ''
for i = 1, floorPart.service.max do
args[1] = "-6.5"
out = out .. displayService(floorPart.service[i], floorPart.dest[i], floorPart.note[i], floorPart.dir)
if mw.ustring.match (args[1], '[%+%-±−]?%d%.%d+') == args[1] then -- eg: +5.5
houoff = mw.ustring.match (args[1], '%d')
arger1 = mw.ustring.match (args[1], '%d%.%d+')
minoff = args[1]*100
help = minoff
sign2 = mw.ustring.match (args[1],'[%+%-±−]?')
minoff = minoff-(houoff*100)
minoff = minoff*0.6
args[1] = table.concat ({sign2,houoff,':',minoff})
end
return out
if mw.ustring.match (args[1], '[%+%-±−]?%d%d%.%d+') == args[1] then -- eg: +5.5
end
houoff = mw.ustring.match (args[1], '%d%d')
 
arger1 = mw.ustring.match (args[1], '%d%d%.%d+')
-- Generate the HTML to generate a "row" of the floor
minoff = args[1]*100
local function displayFloorPart(floorPart, floorNum, partNum)
sign2 = mw.ustring.match (args[1],'[%+%-±−]?')
local out = ''
minoff = minoff-(houoff*100)
minoff = minoff*0.6
if floorPart.name then
args[1] = table.concat ({sign2,houoff,':',minoff})
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
if floorPart.platform then
if mw.ustring.match (args[1], '[%+%-±−]?%d') == args[1] then -- eg: +5
if not platformLabels[floorPart.platform] then
arg1 = mw.ustring.match (args[1], '[%+%-±−]?')
return '<div class="part-error">Invalid platform type!</div>'
args[1] = mw.ustring.match (args[1], '%d')
if is_set(arg1) == false then
arg1 = '+'
end
args[1] = table.concat ({'utc',arg1,0,args[1],':00'})
if is_set(args[2]) == false then
args[2] = 'dmy'
end
return '<div class="platform ' .. floorPart.platform .. '">' ..
platformLabels[floorPart.platform] ..
(floorPart.accessible and ' ' .. mw.getCurrentFrame():expandTemplate{ title = 'access icon' } or '') ..
(floorPart.note and ', ' .. floorPart.note or '') ..
'</div>'
end
 
local prefix = floorNum .. '_' .. partNum .. '_'
return '<div class="part-error">Invalid floor part! Must have either <code>' .. prefix .. 'name</code> or <code>' .. prefix .. 'platform</code></div>.'
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
out = out .. displayFloorPart(stationFloor[i], num, i)
end
return out
if mw.ustring.match (args[1], '[%+%-±−]?%d%d') == args[1] then -- eg: +05
end
arg1 = mw.ustring.match (args[1], '[%+%-±−]?')
 
args[1] = mw.ustring.match (args[1], '%d%d')
-- Create a table that can hold numbered arguments
if is_set(arg1) == false then
local function createArgTable(tbl)
arg1 = '+'
tbl = tbl or {}
end
args[1] = table.concat ({'utc',arg1,args[1],':00'})
tbl.max = 0
if is_set(args[2]) == false then
tbl.count = 0
args[2] = 'dmy'
end
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
end
if not tbl[num] then
if mw.ustring.match (args[1], '[%+%-±−]?%d:%d%d') == args[1] then -- eg: +5:30
tbl[num] = value
arg1 = mw.ustring.match (args[1], '[%+%-±−]?')
tbl.count = tbl.count + 1
args[1] = mw.ustring.match (args[1], '%d:%d%d')
end
if is_set(arg1) == false then
end
arg1 = '+'
end
-- Process an argument with the format level_part_param[paramNum]
args[1] = table.concat ({'utc',arg1,0,args[1]})
local function processArg(out, level, part, param, paramNum, value)
if is_set(args[2]) == false then
level = tonumber(level)
args[2] = 'dmy'
part = tonumber(part)
paramNum = paramNum and tonumber(paramNum) or 1
addArg(out, level, createArgTable())
addArg(out[level], part, {})
if numeredParams[param] then
if not out[level][part][param] then
out[level][part][param] = createArgTable()
end
addArg(out[level][part][param], paramNum, value)
else
out[level][part][param] = value
end
end
-- Process the argument table
local function processArgs(args)
local out = createArgTable()
for i, v in pairs(args) do
if mw.ustring.match (args[1], '[%+%-±−]?%d%d:%d%d') == args[1] then -- eg: +05:30
if type(i) == 'number' then
arg1 = mw.ustring.match (args[1], '[%+%-±−]?')
addArg(out, i, createArgTable({ letter = v }))
args[1] = mw.ustring.match (args[1], '%d%d:%d%d')
else
if is_set(arg1) == false then
local level, part, param, paramNum = i:match('(%d+)_(%d+)_([^%d]+)(%d*)')
arg1 = '+'
end
if level and part and param then
args[1] = table.concat ({'utc',arg1,args[1]})
processArg(out, level, part, param, paramNum, v)
if is_set(args[2]) == false then
end
args[2] = 'dmy'
end
end
return args[1],' ',minoff,' ',houoff*100,' ',help
return out
end
 
-- Main function, called by wikitext
function p.main(frame)
local sortedArgs = processArgs(frame.args)
local out = frame:extensionTag{
name = 'templatestyles',
args = { src = 'User:BrandonXLF/styles.css' }
}
out = out .. '<div class="station-layout">'
for i = 1, sortedArgs.max do
out = out .. displayFloor(sortedArgs[i], i, i == sortedArgs.max)
end
return out .. '</div>'
end
 
return p