Minecraft Wiki
Регистрация
Advertisement

Этот модуль реализует шаблон {{Карточка}}. Его следует в общем случае вызывать напрямую в страницах шаблонов, а не использовать шаблон Карточка.

Аргументы, переданные странице, вызвавшей модуль, автоматически объединяются с аргументами, переданными модулю напрямую (последние перезаписывают первые). Также все аргументы нормализуются (при этом удаляются стоящие в начале и в конце пробелы, а пустые аргументы задаются как равные nil).

Зависит от

local p = {}
function p.infobox( f )
	local args = require( 'Модуль:ProcessArgs' ).merge( true )
	local titleObject = mw.title.getCurrentTitle()
	local title = args['название'] or titleObject.subpageText
	local pixelpar = args["пикселизировать"]
	if pixelpar then
		pixelpar = 'pixel-image'
		else pixelpar = ''
	end
	
	---Передача данных об используемом инструменте из шаблона Блок для модуля Таблица разрушаемости
	f:callParserFunction( '#dplvar:set', 'blocktool', args["инструмент"] )

	local imageArea = args["изображения"]
	if not imageArea and imageArea ~= 'none' then
		local images = {}
		local invImages = {}
		local defaultImageSize = args["умолчразмеризобр"] or '160px'
		args["изображение1"] = args["изображение1"] or args["изображение"] or 'title'
		args["изобр1разм"]  = args["изобр1разм"] or args["изобрразм"]
		args["инвизображение1"] = args["инвизображение1"] or args["инвизображение"] or 'title'
		
		local imgCount = {}
		local invImgCount = {}
		for k, v in pairs( args ) do
			if type( k ) == 'string' then
				local image, num = mw.ustring.match(k, '^(изображение)(%d+)$' )
				local invImage, invNum = mw.ustring.match(k, '^(инвизображение)(%d+)$' )
				if mw.ustring.lower(v) ~= 'нет' then
					if image then
						table.insert( imgCount, tonumber( num ) )
					elseif invImage then
						table.insert( invImgCount, tonumber( invNum ) )
					end
				end
			end
		end
		
		table.sort( imgCount )
		local animate
		for k, v in ipairs( imgCount ) do
			local image = args['изображение' .. v]
			local size = args['изобр' .. v .. 'разм'] or defaultImageSize
			
			if image == 'title' then
				local filename
				if titleObject.isSubpage then
					filename = title .. ' (' .. titleObject.baseText .. ').png'
				else
					filename = title .. '.png'
				end
				local imageTitle = mw.title.new( 'Файл:' .. filename )
				if imageTitle and imageTitle.exists then
					image = '[[Файл:' .. filename .. '|' .. size .. ']]'
				elseif titleObject.namespace == 0 then
					image = '[[Файл:No image.svg|' .. size .. '|link=Файл:' .. filename .. '|Загрузить ' .. filename .. ']]'
				else
					image = '[[Файл:No image.svg|' .. size .. '|link=]]'
				end
			elseif mw.ustring.match(image, ';' ) then
				if not animate then
					animate = require( 'Модуль:Анимация' ).animate
				end
				image = animate{ image, size }
			else
				image = '[[Файл:' .. image .. '|' .. size .. ']]'
			end
			
			table.insert( images, '<div>' .. image .. '</div>' )
		end
		images = table.concat( images, '\n' )
		
		if #invImgCount > 0 then
			table.sort( invImgCount )
			local grid
			local invIds = mw.loadData( [[Модуль:ИнвСпрайт]] )["IDы"]
			for k, v in ipairs( invImgCount ) do
				local image = args['инвизображение' .. v]
				if image == 'title' then
					local imageExists
					if invIds[title] then
						imageExists = true
					else
						local imageTitle = mw.title.new( 'Файл:Grid ' .. title .. '.png' )
						imageExists = imageTitle and imageTitle.exists
					end
					if imageExists then
						image = title
					else
						image = false
					end
				end
				
				if image == '----' then
					table.insert( invImages, '</div><div style="padding-top:.5em">' )
				elseif image then
					if not grid then
						grid = require( 'Модуль:Инвентарный слот' ).slot
					end
					table.insert( invImages, grid{ image, ['ссылка'] = 'нет' } )
				end
			end
			
			if grid 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 = images .. '\n' .. invImages
		else
			imageArea = 'нет'
		end
	end
	if imageArea and imageArea ~= 'нет' then
		imageArea = '<div class="infobox-imagearea ' .. pixelpar .. '">' .. imageArea .. '</div>'
	else
		imageArea = ''
	end
	
	local footer = args["подвал"]
	if footer then
		footer = '| class="infobox-footer" colspan="2" | ' .. footer
	end
	
	local bgcolor = args["цвет"]
	if bgcolor then
		bgcolor = ' style="background:#' .. bgcolor .. '"'
	end

	local s = ''
	if args["ширина"] then s = ' style="width:' .. args["ширина"] .. 'px"' end
	local html = {
		'<div class="notaninfobox"' .. s .. '>',
			'<div class="mcwiki-header infobox-title"', bgcolor or '', '>' .. title .. '</div>',
			imageArea,
			'{| class="infobox-rows" cellspacing="1" cellpadding="4"',
			'|-',
			args["ряды"] or '',
			footer or '',
			'|}',
		'</div>'
	}
	
	return table.concat( html, '\n' )
end

return p
Advertisement