Открыть меню
Открыть персональное меню
Вы не представились системе
Your IP address will be publicly visible if you make any edits.

Модуль:Карточка: различия между версиями

Материал из Create Wiki
Нет описания правки
(добавлена поддержка вкладок (паритет с англовики), русификация флага подстановки файла по названию страницы)
Строка 4: Строка 4:
local titleObject = mw.title.getCurrentTitle()
local titleObject = mw.title.getCurrentTitle()
local title = args['название'] or titleObject.subpageText
local title = args['название'] or titleObject.subpageText
local pixelpar = args["пикселизировать"]
local subtitle = args["подзаголовок"] or ""
if pixelpar then
pixelpar = 'pixel-image'
else pixelpar = ''
end
---Передача данных об используемом инструменте из шаблона Блок для модуля Таблица разрушаемости
---Передача данных об используемом инструменте из шаблона Блок для модуля Таблица разрушаемости
f:callParserFunction( '#dplvar:set', 'blocktool', args["инструмент"] )
f:callParserFunction( '#dplvar:set', 'blocktool', args["инструмент"] )
local titleArea = args["шапка"]
if not titleArea then
titleArea = title
if subtitle ~= '' then
titleArea = titleArea .. '<br><small class="infobox-subtitle">' .. subtitle .. '</small>'
end
end


local imageArea = args["изображения"]
local imageArea = args["изображения"]
if not imageArea and imageArea ~= 'none' then
if not imageArea and imageArea ~= 'нет' then
local images = {}
local images = {}
local invImages = {}
local invImages = {}
local defaultImageSize = args["умолчразмеризобр"] or '160px'
local defaultImageSize = args["умолчразмеризобр"] or '160px'
local defaultImageClass = args["умолчклассизобр"]
local defaultImageClass = args["умолчклассизобр"]
args["изображение1"] = args["изображение1"] or args["изображение"] or 'title'
args["изображение1"] = args["изображение1"] or args["изображение"] or 'назв'
args["изобр1описание"] = args["изобр1описание"] or args["изоброписание"]
args["изобр1описание"] = args["изобр1описание"] or args["изоброписание"]
args["изобр1разм"]  = args["изобр1разм"] or args["изобрразм"]
args["изобр1разм"]  = args["изобр1разм"] or args["изобрразм"]
args["изобр1класс"]  = args["изобр1класс"] or args["изобркласс"]
args["изобр1класс"]  = args["изобр1класс"] or args["изобркласс"]
args["инвизображение1"] = args["инвизображение1"] or args["инвизображение"] or 'title'
args["инвизображение1"] = args["инвизображение1"] or args["инвизображение"] or 'назв'
args['группа1'] = args['группа1'] or args['группа']
args['групп1разм'] = args['групп1разм'] or args['группразм']
args['групп1класс'] = args['групп1класс'] or args['группкласс']
args['групп1описание'] = args['групп1описание'] or args['группописание'] or ''
local imgCount = {}
local imgCount = {}
local invImgCount = {}
local invImgCount = {}
local groupCount = {}
local groupImgList = {}
for k, v in pairs( args ) do
for k, v in pairs( args ) do
if type( k ) == 'string' then
if type( k ) == 'string' then
local image, num = mw.ustring.match(k, '^(изображение)(%d+)$' )
local image, num = mw.ustring.match(k, '^(изображение)(%d+)$' )
local invImage, invNum = mw.ustring.match(k, '^(инвизображение)(%d+)$' )
local invImage, invNum = mw.ustring.match(k, '^(инвизображение)(%d+)$' )
local group, groupNum = mw.ustring.match(k, '^(группа)(%d+)$' )
local groupImg, groupImgNum = mw.ustring.match(k, '^(%d+)-(%d+)$' )
if mw.ustring.lower(v) ~= 'нет' then
if mw.ustring.lower(v) ~= 'нет' then
if image then
if image then
Строка 36: Строка 48:
elseif invImage then
elseif invImage then
table.insert( invImgCount, tonumber( invNum ) )
table.insert( invImgCount, tonumber( invNum ) )
elseif group then
table.insert( groupCount, tonumber( groupNum ) )
if not groupImgList['группа' .. groupNum] then
groupImgList['группа' .. groupNum] = {}
end
elseif groupImg then
if not groupImgList['группа' .. groupImg] then
groupImgList['группа' .. groupImg] = {}
end
table.insert( groupImgList['группа' .. groupImg], tonumber( groupImgNum ) )
end
end
end
end
local animate
if #groupCount > 0 then
table.sort( groupCount )
local tabber = {}
for k, v in ipairs( groupCount ) do
local group = args['группа' .. v]
local groupSize = args['групп' .. v .. 'разм'] or defaultImageSize
local groupClass = args['групп' .. v .. 'класс'] or defaultImageClass
local groupCaption = args['групп' .. v .. 'описание'] or ''
local groupImages = {}
table.sort( groupImgList['группа' .. v] )
for _, w in ipairs( groupImgList['группа' .. v] ) do
local image = args[v .. '-' .. w]
local size = args[v .. '-' .. w .. 'разм'] or groupSize
local class = args[v .. '-' .. w .. 'класс'] or groupClass
local caption = args[v .. '-' .. w .. 'описание'] or ''
if image:match( ';' ) then
if not animate then
animate = require( 'Модуль:Анимация' ).animate
end
image = animate{ image, size, nil, class }
else
image = '[[Файл:' .. image .. '|' .. size .. '|class=' .. ( class or '' ) .. ']]'
end
if caption ~= '' then
caption = '<div class="infobox-imagecaption">\n' .. caption .. '\n</div>'
end
end
table.insert( groupImages, '<div>' .. image .. caption .. '</div>' )
end
if groupCaption ~= '' then
groupCaption = '<div class="infobox-imagecaption">\n' .. groupCaption .. '\n</div>'
end
end
table.insert( tabber, '|-|' .. group .. '=\n' .. table.concat( groupImages, '\n' ) .. groupCaption )
end
end
table.insert( images, '<div>' .. f:extensionTag( 'tabber', table.concat( tabber, '\n' ) ) .. '</div>' )
end
end
Строка 49: Строка 114:
local caption = args['изобр' .. v .. 'описание']
local caption = args['изобр' .. v .. 'описание']
if image == 'title' then
if image == 'назв' or image == 'title' then
local filename
local filename
if titleObject.isSubpage then
if titleObject.isSubpage then
Строка 60: Строка 125:
image = '[[Файл:' .. filename .. '|' .. size .. '|class=' .. (class or '') .. ']]'
image = '[[Файл:' .. filename .. '|' .. size .. '|class=' .. (class or '') .. ']]'
elseif titleObject.namespace == 0 then
elseif titleObject.namespace == 0 then
image = '[[Файл:No images.svg|' .. size .. '|link=Файл:' .. filename .. '|Загрузить ' .. filename .. ']]'
image = '[[Файл:No image.svg|' .. size .. '|link=Файл:' .. filename .. '|Загрузить ' .. filename .. ']]'
else
else
image = '[[Файл:No images.svg|' .. size .. '|link=|Изображение отсутствует]]'
image = '[[Файл:No image.svg|' .. size .. '|link=|Изображение отсутствует]]'
end
end
elseif mw.ustring.match(image, ';' ) then
elseif image:match(';') then
if not animate then
if not animate then
animate = require( 'Модуль:Анимация' ).animate
animate = require( 'Модуль:Анимация' ).animate
Строка 89: Строка 154:
for k, v in ipairs( invImgCount ) do
for k, v in ipairs( invImgCount ) do
local image = args['инвизображение' .. v]
local image = args['инвизображение' .. v]
if image == 'title' then
if image == 'назв' or image == 'title' then
local imageExists
local imageExists
if invIds[title] then
if invIds[title] then
Строка 130: Строка 195:
end
end
if imageArea and imageArea ~= 'нет' then
if imageArea and imageArea ~= 'нет' then
imageArea = '<div class="infobox-imagearea ' .. pixelpar .. '">' .. imageArea .. '</div>'
imageArea = '<div class="infobox-imagearea">' .. imageArea .. '</div>'
else
else
imageArea = ''
imageArea = ''
Строка 148: Строка 213:
footer = '| class="infobox-footer" colspan="2" | ' .. footer
footer = '| class="infobox-footer" colspan="2" | ' .. footer
end
end
 
local styles = { args["стиль"] }
local width = args["ширина"]
if width then
if not width:match("px$") then
-- временно, для совместимости
width = width .. 'px'
end
styles[#styles+1] = "width:" .. width
end
local bgcolor = args["цвет"]
local bgcolor = args["цвет"]
if bgcolor then
if bgcolor then
bgcolor = ' style="background:#' .. bgcolor .. '"'
if not bgcolor:match("^#") then
-- временно, для совместимости
bgcolor = "#" .. bgcolor
end
styles[#styles+1] = "--infobox-header-background-color:" .. bgcolor
end
local style = ""
if #styles > 0 then
style = ' style="' .. table.concat(styles, ";") .. '"'
end
end
 
local s = ''
if args["ширина"] then s = ' style="width:' .. args["ширина"] .. 'px"' end
local html = {
local html = {
'<div class="notaninfobox"' .. s .. '>',
'<div class="notaninfobox"' .. style .. '>',
'<div class="cwwiki-header infobox-title"', bgcolor or '', '>' .. title .. '</div>',
'<div class="mcwiki-header infobox-title">' .. titleArea .. '</div>',
imageAreaExpanded,
imageAreaExpanded,
'{| class="infobox-rows" cellspacing="1" cellpadding="4"',
'{| class="infobox-rows" cellspacing="1" cellpadding="4"',

Версия от 09:28, 17 июля 2024

Для документации этого модуля может быть создана страница Модуль:Карточка/doc

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

	local imageArea = args["изображения"]
	if not imageArea and imageArea ~= 'нет' then
		local images = {}
		local invImages = {}
		local defaultImageSize = args["умолчразмеризобр"] or '160px'
		local defaultImageClass = args["умолчклассизобр"]
		args["изображение1"] = args["изображение1"] or args["изображение"] or 'назв'
		args["изобр1описание"] = args["изобр1описание"] or args["изоброписание"]
		args["изобр1разм"]  = args["изобр1разм"] or args["изобрразм"]
		args["изобр1класс"]  = args["изобр1класс"] or args["изобркласс"]
		args["инвизображение1"] = args["инвизображение1"] or args["инвизображение"] or 'назв'
		args['группа1'] = args['группа1'] or args['группа']
		args['групп1разм'] = args['групп1разм'] or args['группразм']
		args['групп1класс'] = args['групп1класс'] or args['группкласс']
		args['групп1описание'] = args['групп1описание'] or args['группописание'] or ''
		
		local imgCount = {}
		local invImgCount = {}
		local groupCount = {}
		local groupImgList = {}
		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+)$' )
				local group, groupNum = mw.ustring.match(k, '^(группа)(%d+)$' )
				local groupImg, groupImgNum = mw.ustring.match(k, '^(%d+)-(%d+)$' )
				if mw.ustring.lower(v) ~= 'нет' then
					if image then
						table.insert( imgCount, tonumber( num ) )
					elseif invImage then
						table.insert( invImgCount, tonumber( invNum ) )
					elseif group then
						table.insert( groupCount, tonumber( groupNum ) )
						if not groupImgList['группа' .. groupNum] then
							groupImgList['группа' .. groupNum] = {}
						end
					elseif groupImg then
						if not groupImgList['группа' .. groupImg] then
							groupImgList['группа' .. groupImg] = {}
						end
						table.insert( groupImgList['группа' .. groupImg], tonumber( groupImgNum ) )
					end
				end
			end
		end
		
		local animate
		if #groupCount > 0 then
			table.sort( groupCount )
			local tabber = {}
			for k, v in ipairs( groupCount ) do
				local group = args['группа' .. v]
				local groupSize = args['групп' .. v .. 'разм'] or defaultImageSize
				local groupClass = args['групп' .. v .. 'класс'] or defaultImageClass
				local groupCaption = args['групп' .. v .. 'описание'] or ''
				local groupImages = {}
				
				table.sort( groupImgList['группа' .. v] )
				for _, w in ipairs( groupImgList['группа' .. v] ) do
					local image = args[v .. '-' .. w]
					local size = args[v .. '-' .. w .. 'разм'] or groupSize
					local class = args[v .. '-' .. w .. 'класс'] or groupClass
					local caption = args[v .. '-' .. w .. 'описание'] or ''
					
					if image:match( ';' ) then
						if not animate then
							animate = require( 'Модуль:Анимация' ).animate
						end
						image = animate{ image, size, nil, class }
					else
						image = '[[Файл:' .. image .. '|' .. size .. '|class=' .. ( class or '' ) .. ']]'
					end
					
					if caption ~= '' then
						caption = '<div class="infobox-imagecaption">\n' .. caption .. '\n</div>'
					end
					
					table.insert( groupImages, '<div>' .. image .. caption .. '</div>' )
				end

				if groupCaption ~= '' then
					groupCaption = '<div class="infobox-imagecaption">\n' .. groupCaption .. '\n</div>'
				end
				
				table.insert( tabber, '|-|' .. group .. '=\n' .. table.concat( groupImages, '\n' ) .. groupCaption )
			end
			table.insert( images, '<div>' .. f:extensionTag( 'tabber', table.concat( tabber, '\n' ) ) .. '</div>' )
		end
		
		table.sort( imgCount )
		local animate
		for k, v in ipairs( imgCount ) do
			local image = args['изображение' .. v]
			local size = args['изобр' .. v .. 'разм'] or defaultImageSize
			local class = args['изобр' .. v .. 'класс'] or defaultImageClass
			local caption = args['изобр' .. v .. 'описание']
			
			if image == 'назв' or 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 .. '|class=' .. (class or '') .. ']]'
				elseif titleObject.namespace == 0 then
					image = '[[Файл:No image.svg|' .. size .. '|link=Файл:' .. filename .. '|Загрузить ' .. filename .. ']]'
				else
					image = '[[Файл:No image.svg|' .. size .. '|link=|Изображение отсутствует]]'
				end
			elseif image:match(';') then
				if not animate then
					animate = require( 'Модуль:Анимация' ).animate
				end
				image = animate{ image, size, nil, class }
			else
				image = '[[Файл:' .. image .. '|' .. size .. '|class=' .. (class or '') .. ']]'
			end
			
			if caption and mw.ustring.lower(caption) ~= 'нет' then
				caption = '<div class="infobox-imagecaption">' .. caption .. '</div>'
			else
				caption = ''
			end
			
			table.insert( images, '<div>' .. image .. caption .. '</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 == 'назв' or 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">' .. imageArea .. '</div>'
	else
		imageArea = ''
	end
	
	local extraText = args["доптекст"]
	if extraText and mw.ustring.lower(extraText) ~= 'нет' then
		extraText = '<div class="infobox-extratext">' .. extraText .. '</div>'
	else
		extraText = ''
	end
	
	local imageAreaExpanded = imageArea .. '' .. extraText
	
	local footer = args["подвал"]
	if footer then
		footer = '| class="infobox-footer" colspan="2" | ' .. footer
	end

	local styles = { args["стиль"] }
	local width = args["ширина"]
	if width then
		if not width:match("px$") then
			-- временно, для совместимости
			width = width .. 'px'
		end
		styles[#styles+1] = "width:" .. width
	end
	local bgcolor = args["цвет"]
	if bgcolor then
		if not bgcolor:match("^#") then
			-- временно, для совместимости
			bgcolor = "#" .. bgcolor
		end
		styles[#styles+1] = "--infobox-header-background-color:" .. bgcolor
	end
	local style = ""
	if #styles > 0 then
		style = ' style="' .. table.concat(styles, ";") .. '"'
	end
	
	local html = {
		'<div class="notaninfobox"' .. style .. '>',
			'<div class="mcwiki-header infobox-title">' .. titleArea .. '</div>',
			imageAreaExpanded,
			'{| class="infobox-rows" cellspacing="1" cellpadding="4"',
			'|-',
			args["ряды"] or '',
			footer or '',
			'|}',
		'</div>'
	}
	
	return table.concat( html, '\n' )
end

return p
Сайт использует Cookie для нормальной работы