Minecraft Wiki
Нет описания правки
Нет описания правки
Строка 166: Строка 166:
 
 
 
-- Ячейка с рецептом
 
-- Ячейка с рецептом
local recipeCell = require( 'Модуль:Обработка' ).interface( newArgs )
+
local recipeCell = require( 'Модуль:СтараяОбработка' ).interface( newArgs )
 
 
 
-- Ячейка с продуктами
 
-- Ячейка с продуктами

Версия от 10:32, 10 июля 2020

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

Зависимости

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

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 mod = args["Мод"] or ''
	local progress = args["Прогресс"] or ''
	
	-- Определение версии интерфейса
	local version
	if progress ~= '' then
		version = mw.ustring.match(progress or '', ':%s*([a-zA-Z 0-9]+)') or args["Версия"] or args["Мод"] or 'Оригинальная игра'
	end
	
	progress = mw.ustring.match(progress or '', '([a-zA-Zа-яА-ЯёЁ 0-9]+):') or progress
	
	-- Сборка заголовка таблицы
	local header = ''
	if head ~= '' then
		local name = ''
		local description = ''
		if args["показатьимя"] == '1' or multirow and args["показатьимя"] ~= '0' then
			name = '!! Результат'
			f:callParserFunction( '#dplvar:set', 'resultname', '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 progress and mod ~= '' then
         process=' Процесс'
        end
		header = table.concat( {
			' {| style="text-align:center" class="wikitable ' .. class .. '" data-description="Процесс"',
			'! ' .. 'Ингредиенты !! ' .. recipeClass .. process  .. name .. description,
			'|-'}, '\n' )
	end
	
	-- Конвертор аргументов
	args["Ресурс1"] = args["Ресурс1"] or args["Ресурс"] or args[1] or ''
	args["Ресурс2"] = args["Ресурс2"] or args["Топливо"] or args["топливо"] or ''
	args["Выход1"] = args["Выход1"] or args["Выход"] or args[2] or ''
	args["РесурсЖ1"] = args["РесурсЖ1"] or args["РесурсЖ"]
	args["ВыходЖ1"] = args["ВыходЖ1"] or args["ВыходЖ"]
	
	local input = {}
	local output = {}
	
	for i = 1,6 do
		if args['Ресурс' .. i] then
			table.insert( input , mw.text.trim( args['Ресурс' .. i] ))
		else
			break
		end
	end
	for i = 1,6 do
		if args['РесурсЖ' .. i] then
			table.insert( input , mw.text.trim( args['РесурсЖ' .. i] ))
		else
			break
		end
	end
	for i = 1,6 do
		if args['Выход' .. i] then
			table.insert( output , mw.text.trim( args['Выход' .. i] ))
		else
			break
		end
	end
	for i = 1,6 do
		if args['ВыходЖ' .. i] then
			table.insert( output , mw.text.trim( args['ВыходЖ' .. i] ))
		else
			break
		end
	end
	
	-- Ячейка с ингредиентами
	local ingredientsCell
	if args["ингредиенты"] or '' ~= '' then
		ingredientsCell = args["ингредиенты"]
	else
		ingredientsCell = {}
		local ingredients = {}
		local separator = ''
		for k, v in ipairs ( input ) do
			if k > 1 and next( ingredients ) then
				separator = '&nbsp;+<br>\n'
			end
			for item in mw.text.gsplit( v, '%s*;%s*' ) do
				local parts = getParts( item, mod )
				if parts.name ~= '' and not ingredients[parts.name] and ( k >= 1 and ( v ~= args['Топливо'] )) 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
		newArgs["Ресурс"] = input[1]
		newArgs["Топливо"] = input[2]
		newArgs["Выход"] = output[1]
		newArgs["Опыт"] = args[3] or args["Опыт"]
		newArgs["Мод"] = mod
		newArgs["Прогресс"] = progress
		newArgs["Версия"] = version
	
	-- Ячейка с рецептом
	local recipeCell = require( 'Модуль:СтараяОбработка' ).interface( newArgs )
	
	-- Ячейка с продуктами
	local nameCell
	if args["название"] or '' ~= '' then
		nameCell = args["название"]
	elseif f:callParserFunction( '#dplvar', 'resultname' ) == '1' then
		nameCell = {}
		local names = {}
		for k, v in ipairs ( output ) do
			local separator = ''
			if k > 1 and next( names ) then
				separator = '&nbsp;+<br>\n'
			end
			for item in mw.text.gsplit( v, '%s*;%s*' ) do
				local parts = getParts( item, mod )
				if parts.name ~= '' and not names[parts.name] and ( k >= 1 ) then
					local link = ''
					if separator == '' and next( names ) 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( nameCell, separator .. mw.ustring.sub( parts.name, 0, 6 ) .. '[[' .. link .. mw.ustring.sub( parts.name, 6 ) .. ']]' )
					else
						table.insert( nameCell, separator .. '[[' .. link .. parts.name .. ']]' )
					end
					separator = ''
					
					names[parts.name] = 1
				end
			end
		end
		
		nameCell = table.concat( nameCell )
	end
	
	if nameCell and args["запланированное"] then
		nameCell = nameCell .. '<br>([[' .. args["запланированное"] .. ']])'
	end
	
	-- Сборка строки таблицы с интерфейсом
	local row = {
		'\n|' .. ingredientsCell,
		recipeCell
	}
	if nameCell then
		table.insert( row, nameCell )
	end
	if f:callParserFunction( '#dplvar', 'smeltingdescription' ) == '1' then
		table.insert( row, args["описание"] or '' )
	end
	row = table.concat( row, '\n|' ) .. '\n|-'
	
	-- Закрытие таблицы
	local footer = ''
	if foot ~= '' then
		footer = '\n|}'
		f:callParserFunction( '#dplvar:set', 'resultname', '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 .. row .. footer .. category
end
return p