Warning.png

Поддержка Wiki прекращена, она доступна в режиме архива. Информация в ней устарела и может быть неактуальной.

Модуль:Обжиг

Материал из Hilarious Wiki
Перейти к: навигация, поиск
Документация

Этот модуль реализует {{обжиг}}.

Зависимости

Смотрите также

Расположенная выше документация включена из Модуль:Обжиг/док.

local p = {}
function p.table( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	local getParts = require( 'Модуль:Инвентарный слот' ).getParts
	
	-- Начинать таблицу при необходимости
	local multirow = f:callParserFunction( '#dplvar', 'multirow' )
	if multirow ~= '1' then
		multirow = nil
	end
	local head = args["глава"] or ''
	if multirow then
		head = ''
	elseif head ~= '' then
		multirow = 1
		f:callParserFunction( '#dplvar:set', 'multirow', '1' )
	else
		head = 1
	end
	
	-- Заканчивать таблицу при необходимости
	local foot = args["подвал"] or ''
	if multirow then
		if foot ~= '' then
			multirow = nil
			f:callParserFunction( '#dplvar:set', 'multirow', '0' )
		end
	else
		foot = 1
	end
	
	local header = ''
	if head ~= '' then
		local name = ''
		local description = ''
		if args["показатьимя"] == '1' or multirow and args["показатьимя"] ~= '0' then
			name = '!! Результат'
			f:callParserFunction( '#dplvar:set', 'smeltingname', '1' )
		end
		if args["показатьописание"] == '1' then
			description = ' !! class="unsortable" | Описание'
			f:callParserFunction( '#dplvar:set', 'smeltingdescription', '1' )
		end
		local class = args["класс"] or ''
		local recipeClass = ''
		if multirow then
			class = 'sortable collapsible ' .. class
			recipeClass = 'class="unsortable" |'
		end
        local process = ' [[Обжиг|Процесс]]'
        if args["Прогресс"] and args["Мод"] then
         process=' Процесс'
        end
		header = table.concat( {
			' {| style="text-align:center" class="wikitable ' .. class .. '" data-description="Процесс"',
			'! ' .. 'Ингредиенты !! ' .. recipeClass .. process  .. name .. description,
			'|-'
		}, '\n' )
	end
	
	local input = mw.text.trim( args[1] or args["Ресурс"] or '' )
	local output = mw.text.trim( args[2] or args["Выход"] or '' )
	local fuel = args["топливо"] or args["Топливо"] or ''
	if fuel == '' and (args["Мод"] == 'IndustrialCraft 2' or 'GregTech' and args['Расход'] == 'Электричество') then
		fuel = 'Энергия'
    elseif fuel == '' then
		fuel = 'v:Любое топливо,1'
	end
	
	-- Ячейка с названием
	local nameCell
	if args["название"] or '' ~= '' then
		nameCell = args["название"]
	elseif multirow or f:callParserFunction( '#dplvar', 'smeltingname' ) == '1' then
		local names = {}
		local links = {}
		for v in mw.text.gsplit( args[2] or args["Выход"] or '', '%s*;%s*' ) do
			parts = getParts( v, args["Мод"] )
			if not names[( parts.mod or '' ) .. parts.name] and output ~= '' then
				local link = ''
				if parts.mod then
					link = parts.mod .. '/' .. parts.name .. '|'
				end
               
				if parts.name:find( '^Люб' ) then
					if parts.mod then
						link = parts.mod .. '/' .. mw.ustring.gsub( mw.ustring.sub( parts.name, 7 ), "^%l", mw.ustring.upper ) .. '|'
					end
					table.insert( links, mw.ustring.sub( parts.name, 0, 6 ) .. '[[' .. link .. mw.ustring.sub( parts.name, 6 ) .. ']]' )
				else
					table.insert( links, '[[' .. link .. parts.name .. ']]' )
				end
				names[( parts.mod or '' ) .. parts.name] = 1
			end
		end
		
		nameCell = table.concat( links, '&nbsp;или<br>' )
	end
	
	if nameCell and args["запланированное"] then
		nameCell = nameCell .. '<br>([[' .. args["запланированное"] .. ']])'
	end
	
	-- Ячейка с ингредиентами
	local ingredientsCell
	if args["ингредиенты"] or '' ~= '' then
		ingredientsCell = args["ингредиенты"]
	else
		ingredientsCell = {}
		local ingredients = {}
		for k, v in ipairs{ input, fuel } do
			local separator = ''
			if k == 2 and next( ingredients ) then
				separator = '&nbsp;+<br>\n'
			end
			for item in mw.text.gsplit( v, '%s*;%s*' ) do
				local parts = getParts( item, args["Мод"] )
				if parts.name ~= '' and not ingredients[parts.name] and ( k == 2 or k == 1 and v ~= fuel ) then
					local link = ''
					if separator == '' and next( ingredients ) then
						separator = '&nbsp;или<br>\n'
					end
					
					if parts.mod then
						link = parts.mod .. '/' .. parts.name .. '|'
					end
					
					if parts.name:find( '^Люб' ) then
					    if parts.mod then
						 link = parts.mod .. '/' .. mw.ustring.gsub( mw.ustring.sub( parts.name, 7 ), "^%l", mw.ustring.upper ) .. '|'
					    end
						table.insert( ingredientsCell, separator .. mw.ustring.sub( parts.name, 0, 6 ) .. '[[' .. link .. mw.ustring.sub( parts.name, 6 ) .. ']]' )
					else
						table.insert( ingredientsCell, separator .. '[[' .. link .. parts.name .. ']]' )
					end
					separator = ''
					
					ingredients[parts.name] = 1
				end
			end
		end
		
		ingredientsCell = table.concat( ingredientsCell )
	end
	
	-- Остальные аргументы
	local newArgs = {
		["Ресурс"] = args[1] or args["Ресурс"],
		["Выход"] = args[2] or args["Выход"],
		["Топливо"] = fuel,
		["РНазв"] = args["рНазв"],
		["ВНазв"] = args["вНазв"],
		["ТНазв"] = args["тНазв"],
		["Мод"] = args["Мод"],
		["Прогресс"] = args["Прогресс"],
		["Расход"] = args["Расход"]
	}
	
	-- Ячейка с рецептом
	local recipeCell = require( 'Модуль:Интерфейс' ).furnace( newArgs )
	
	local row = {
		'|\n' .. ingredientsCell,
		'style="padding:1px" |\n' .. recipeCell
	}
	if nameCell then
		table.insert( row, 3, nameCell )
	end
	if f:callParserFunction( '#dplvar', 'smeltingdescription' ) == '1' then
		table.insert( row, args["описание"] or '' )
	end
	row = table.concat( row, '\n' )
	
	if nameCell then
		row = row .. '!\n'
	else
		row = row .. '|\n'
	end
	
	local footer = ''
	if foot ~= '' then
		footer = '|}'
		f:callParserFunction( '#dplvar:set', 'smeltingname', '0', 'smeltingdescription', '0' )
	end
	
	local title = mw.title.getCurrentTitle()
	local category = ''
	if args["запланированное"] and args["некат"] ~= '1' and title.namespace == 0 and not title.isSubpage then
		category = '[[Категория:Запланированное]]'
	end
	
	return header .. '\n' .. row .. '\n|-\n' .. footer .. category
end
return p