跳转到内容

模組:城轨车站结构

本页使用了标题或全文手工转换
维基百科,自由的百科全书

local p = {}
local alphabet = 'ABCDEFGHIJKL'

local args

local function getFloorName(floor)
	if floor == 0 then
		return '地面层'
	else
		return floor .. '层'
	end
end

local function getFloor(frame, floor)
	local zone = 1
	local c = alphabet:sub(zone, zone)
	local row = 0
	local s = {}

	while args['label' .. floor .. c] do
		if zone ~= 1 then
			table.insert(s, '<tr>')
		end
		table.insert(s,
			'<td style="vertical-align: top; min-width: 4em; border-top: 1px solid #a2a9b1">' ..
			args['label' .. floor .. c] ..
			'</td><td style="vertical-align: top; min-width: 12em; max-width: 40em; border-top: 1px solid #a2a9b1">' ..
			(args['text' .. floor .. c] or '') .. '</td></tr>')
		row = row + 1
		if args['map' .. floor .. c] then
			table.insert(s,
				'<tr><td colspan=2>' ..
				frame:expandTemplate { title = 'Routemap', args = {
					args['map' .. floor .. c],
					inline = '1',
					legend = 'no'
				} } .. '</td></tr>')
			row = row + 1
		end
		zone = zone + 1
		c = alphabet:sub(zone, zone)
	end
	return '<tr><th rowspan=' ..
		row ..
		' style="vertical-align: top; text-align: left; min-width: 4em; border-top: 1px solid #a2a9b1">' ..
		getFloorName(floor) .. '</th>' .. table.concat(s)
end

local function getSubFloor(floor)
	return
		'<tr><th colspan=2 style="vertical-align: top; text-align: left; border-top: 1px solid #a2a9b1">设备层</th><td style="vertical-align: top; min-width: 12em; max-width: 40em; border-top: 1px solid #a2a9b1">' ..
		args['text' .. floor .. 'S'] .. '</td></tr>'
end

function p.main(frame)
	args = frame:getParent().args
	local floor = 9
	local s = {}
	while floor > 0 do
		if args['label' .. floor .. 'A'] or args['text' .. floor .. 'A'] then
			table.insert(s, getFloor(frame, floor))
		end
		if args['text' .. floor .. 'S'] then
			table.insert(s, getSubFloor(floor))
		end
		floor = floor - 1
	end
	if args['label0A'] then
		table.insert(s, getFloor(frame, 0))
	end
	while floor < 9 do
		floor = floor + 1
		if args['textB' .. floor .. 'S'] then
			table.insert(s, getSubFloor('B' .. floor))
		end
		if args['labelB' .. floor .. 'A'] or args['textB' .. floor .. 'A'] then
			table.insert(s, getFloor(frame, 'B' .. floor))
		end
	end

	return '<table style="border-spacing:0; border-bottom: 1px solid #a2a9b1" cellpadding=4>' ..
		table.concat(s) .. '</table>'
end

return p