Module:Infobox

来自Minecraft基岩版开发Wiki
[创建 | 历史 | 清除缓存]文档页面
此模块没有文档页面。如果你知道如何使用模块,请创建它。
local p = {}
function p.infobox(f)
	local args = f
	if f == mw.getCurrentFrame() then
		args = require('Module:ProcessArgs').merge(true)
	end
	f = mw.getCurrentFrame()

	local isSubBox = args.subbox
	local title
	local imageArea = args.imagearea
	local subHeader = args.subheader
	local footer = args.footer
	if not isSubBox then
		if args.title and args.title ~= 'none' then
			title = args.title
			local titleNode = mw.html.create('div')
				:addClass('infobox-title')
				:cssText(args.titlestyle)
				:wikitext(title)
			title = tostring(titleNode)
		end
		if imageArea == 'none' then
			imageArea = nil
		end
		if not imageArea then
			local images = {}
			local invImages = {}
			local defaultImageSize = args.defaultimagesize or '160px'
			args.image1 = args.image1 or args.image
			args.image1size = args.image1size or args.imagesize or defaultImageSize
			args.invimage1 = args.invimage1 or args.invimage
			local imgCount = {}
			local invImgCount = {}
			for k, v in pairs(args) do
				if type(k) == 'string' then
					local name, num = mw.ustring.match(k, '^(.*image)(%d+)$')
					if mw.ustring.lower(v) ~= 'none' then
						if name == 'image' then
							table.insert(imgCount, tonumber(num))
						elseif name == 'invimage' then
							table.insert(invImgCount, tonumber(num))
						end
					end
				end
			end
			table.sort(imgCount)
			local animate = require('Module:Animate').animate
			for _, v in ipairs(imgCount) do
				local image = args['image' .. v]
				local size = args['image' .. v .. 'size'] or defaultImageSize
				if mw.ustring.match(image, ';') then
					image = animate {image, size}
				else
					image = '[[File:' .. image .. '|' .. size .. ']]'
				end
				table.insert(images, '<div>' .. image .. '</div>')
			end
			images = table.concat(images, '\n')
			if #invImgCount > 0 then
				table.sort(invImgCount)
				local slot = require('Module:Inventory slot').slot
				for _, v in ipairs(invImgCount) do
					local image = args['invimage' .. v]
					if image == '----' then
						table.insert(invImages, '</div><div style="padding-top:.5em">')
					elseif image then
						table.insert(invImages, slot {image, link = 'none', mod = args.mod})
					end
				end
				if slot and #invImages > 0 then
					invImages = '<div class="infobox-invimages"><div>' .. table.concat(invImages, '') .. '</div></div>'
				else
					invImages = ''
				end
			else
				invImages = ''
			end
			if images ~= '' or invImages ~= '' then
				imageArea = '<div class="infobox-imagearea">' .. images .. '\n' .. invImages .. '</div>'
			else
				imageArea = nil
			end
		else
			imageArea = '<div class="infobox-imagearea">' .. imageArea .. '</div>'
		end
		if subHeader then
			local subHeaderNode = mw.html.create('div')
				:addClass('infobox-subheader')
				:cssText(args.subheaderstyle)
				:wikitext(subHeader)
			subHeader = tostring(subHeaderNode)
		end
		if footer then
			footer = '<div class="infobox-footer">' .. footer .. '</div>'
		end
	end
	local rows = args.rows
	if rows then
		if isSubBox then
			rows = '<div class="infobox-rows subinfobox">' .. rows .. '</div>'
		else
			rows = '<div class="infobox-rows">' .. rows .. '</div>'
		end
	end
	if not (title or imageArea or subHeader or rows or footer) then
		return ''
	end
	local styles = f:extensionTag {name = 'templatestyles', args = {src = 'Infobox/styles.css'}}
	local html = {}
	if not isSubBox then
		html = {
			'<div class="notaninfobox">',
			title or '',
			imageArea or '',
			subHeader or '',
			rows or '',
			footer or '',
			'</div>'
		}
	else
		html = {rows}
	end
	return styles .. table.concat(html)
end
return p