Minecraft Wiki
Нет описания правки
Нет описания правки
 
(не показана 21 промежуточная версия этого же участника)
Строка 14: Строка 14:
 
multirow = nil
 
multirow = nil
 
end
 
end
local head = args["глава"] or ''
+
local head = args["глава"] or '0'
  +
if tonumber(head) then
  +
head = tonumber(head)
 
else
  +
error("Параметр «глава» не является числом.")
 
end
 
if multirow then
 
if multirow then
head = ''
+
head = 0
elseif head ~= '' then
+
elseif head ~= 0 then
 
multirow = 1
 
multirow = 1
 
f:callParserFunction( '#dplvar:set', 'multirow', '1' )
 
f:callParserFunction( '#dplvar:set', 'multirow', '1' )
 
else
  +
head = 1
 
end
 
end
 
 
Строка 34: Строка 41:
 
 
 
local mod = args["Мод"]
 
local mod = args["Мод"]
local progress = args["Прогресс"]
+
if not mod and args["Прогресс"] then
  +
if args['Прогресс']:find('gt4') then
 
 
mod = 'GregTech 4'
-- Предопределение модификации
 
  +
elseif args['Прогресс']:find('gt') then
local version
 
 
mod = 'GregTech'
if progress or '' ~= '' then
 
  +
elseif args['Прогресс']:find('ic2') then
mod = mod or 'GregTech'
 
  +
mod = 'IndustrialCraft 2'
version = mw.ustring.match(progress or '', ':%s*([a-zA-Z 0-9]+)') or args["Версия"] or args["Мод"] or nil
 
 
end
 
end
 
end
 
args["Мод"] = mod
 
  +
progress = mw.ustring.match(progress or '', '([a-zA-Zа-яА-ЯёЁ 0-9]+):') or progress or nil
 
 
-- Сборка заголовка таблицы
 
if ( progress or '' ~= '' ) and ( version or '' ~= '' ) then
 
args["Машина"] = args["Машина"] or nil
 
mod = mod or nil
 
else
 
args["Машина"] = '21110000102'
 
mod = mod or ''
 
version = 'Оригинальная игра'
 
end
 
 
-- Конструктор заголовка таблицы
 
 
local header = ''
 
local header = ''
if head ~= '' then
+
if head ~= 0 then
 
local name = ''
 
local name = ''
 
local description = ''
 
local description = ''
Строка 68: Строка 66:
 
end
 
end
 
local class = args["класс"] or ''
 
local class = args["класс"] or ''
local recipeClass = ''
 
 
if multirow then
 
if multirow then
 
class = 'sortable collapsible ' .. class
 
class = 'sortable collapsible ' .. class
 
recipeClass = 'class="unsortable" |'
 
recipeClass = 'class="unsortable" |'
  +
else
 
recipeClass = ''
  +
end
 
if args["Прогресс"] then
 
process = ' Процесс'
  +
else
  +
process = ' [[Плавка|Процесс]]'
  +
end
  +
local table_head
  +
if head >= 2 then
  +
table_head = '|-'
  +
else
 
table_head = ' {| style="text-align:center" class="wikitable ' .. class .. '" data-description="Процесс"'
  +
end
  +
if head ~= 3 then
 
header = table.concat( {
  +
table_head,
 
'! ' .. 'Ингредиенты !! ' .. recipeClass .. process .. name .. description,
 
'|-'}, '\n' )
 
end
 
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
 
end
 
 
 
 
-- Конвертор аргументов
 
-- Конвертор аргументов
Строка 92: Строка 98:
 
args["ВыходЖ1"] = args["ВыходЖ1"] or args["ВыходЖ"]
 
args["ВыходЖ1"] = args["ВыходЖ1"] or args["ВыходЖ"]
 
 
local input = mw.text.trim( args["Ресурс1"] or '' )
+
local input = {}
  +
n = 1
local fuel = mw.text.trim( args["Ресурс2"] or '' )
 
  +
while args['Ресурс' .. n] do
local input3 = mw.text.trim( args["Ресурс3"] or '' )
 
local input4 = mw.text.trim( args["Ресурс4"] or '' )
+
table.insert( input , mw.text.trim( args['Ресурс' .. n] ))
 
n = n + 1
local input5 = mw.text.trim( args["Ресурс5"] or '' )
 
  +
end
local input6 = mw.text.trim( args["Ресурс6"] or '' )
 
  +
n = 1
local input7 = mw.text.trim( args["РесурсЖ1"] or '' )
 
  +
while args['РесурсЖ' .. n] do
local input8 = mw.text.trim( args["РесурсЖ2"] or '' )
 
local input9 = mw.text.trim( args["РесурсЖ3"] or '' )
+
table.insert( input , mw.text.trim( args['РесурсЖ' .. n] ))
  +
n = n + 1
local output = mw.text.trim( args["Выход1"] or '' )
 
  +
end
local output2 = mw.text.trim( args["Выход2"] or '' )
 
 
local output = {}
local output3 = mw.text.trim( args["Выход3"] or '' )
 
  +
n = 1
local output4 = mw.text.trim( args["Выход4"] or '' )
 
  +
while args['Выход' .. n] do
local output5 = mw.text.trim( args["Выход5"] or '' )
 
local output6 = mw.text.trim( args["Выход6"] or '' )
+
table.insert( output , mw.text.trim( args['Выход' .. n] ))
  +
n = n + 1
local output7 = mw.text.trim( args["Выход7"] or '' )
 
  +
end
local output8 = mw.text.trim( args["Выход8"] or '' )
 
  +
n = 1
local output9 = mw.text.trim( args["Выход9"] or '' )
 
  +
while args['ВыходЖ' .. n] do
local output10 = mw.text.trim( args["ВыходЖ1"] or '' )
 
local output11 = mw.text.trim( args["ВыходЖ2"] or '' )
+
table.insert( output , mw.text.trim( args['ВыходЖ' .. n] ))
  +
n = n + 1
local output12 = mw.text.trim( args["ВыходЖ3"] or '' )
 
if fuel == '' and (((mod == 'IndustrialCraft 2') or (mod == 'GregTech')) and args['Расход'] == 'Электричество') then
 
fuel = 'Энергия'
 
elseif fuel == '' and version == 'Оригинальная игра' then
 
fuel = 'v:Любое топливо,1'
 
 
end
 
end
 
 
-- Ячейка с продуктами
+
-- Ячейка с ингредиентами
local nameCell
+
local ingredientsCell
if args["название"] or '' ~= '' then
+
if args["ингредиенты"] or '' ~= '' then
nameCell = args["название"]
+
ingredientsCell = args["ингредиенты"]
  +
else
elseif f:callParserFunction( '#dplvar', 'resultname' ) == '1' then
 
nameCell = {}
+
ingredientsCell = {}
local names = {}
+
local ingredients = {}
 
local separator = ''
for k, v in ipairs{ output, output2, output3, output4, output5, output6, output7, output8, output9, output10, output11, output12 } do
 
  +
for k, v in ipairs ( input ) do
local separator = ''
 
if k > 1 and next( names ) then
+
if k > 1 and next( ingredients ) then
 
separator = '&nbsp;+<br>\n'
 
separator = '&nbsp;+<br>\n'
 
end
 
end
 
for item in mw.text.gsplit( v, '%s*;%s*' ) do
 
for item in mw.text.gsplit( v, '%s*;%s*' ) do
 
local parts = getParts( item, mod )
 
local parts = getParts( item, mod )
if parts.name ~= '' and not names[parts.name] and ( k >= 1 ) then
+
if parts.name ~= '' and not ingredients[parts.name] and ( k >= 1 and ( v ~= args['Топливо'] )) then
 
local link = ''
 
local link = ''
if separator == '' and next( names ) then
+
if separator == '' and next( ingredients ) then
 
separator = '&nbsp;или<br>\n'
 
separator = '&nbsp;или<br>\n'
 
end
 
end
  +
 
 
if parts.mod then
 
if parts.mod then
 
link = parts.mod .. '/' .. parts.name .. '|'
 
link = parts.mod .. '/' .. parts.name .. '|'
 
end
 
end
  +
 
 
if parts.name:find( '^Люб' ) then
 
if parts.name:find( '^Люб' ) then
if parts.mod then
+
if parts.mod then
link = parts.mod .. '/' .. mw.ustring.gsub( mw.ustring.sub( parts.name, 7 ), "^%l", mw.ustring.upper ) .. '|'
+
link = parts.mod .. '/' .. mw.ustring.gsub( mw.ustring.sub( parts.name, 7 ), "^%l", mw.ustring.upper ) .. '|'
end
+
end
table.insert( nameCell, separator .. mw.ustring.sub( parts.name, 0, 6 ) .. '[[' .. link .. mw.ustring.sub( parts.name, 6 ) .. ']]' )
+
table.insert( ingredientsCell, separator .. mw.ustring.sub( parts.name, 0, 6 ) .. '[[' .. link .. mw.ustring.sub( parts.name, 6 ) .. ']]' )
 
else
 
else
table.insert( nameCell, separator .. '[[' .. link .. parts.name .. ']]' )
+
table.insert( ingredientsCell, separator .. '[[' .. link .. parts.name .. ']]' )
 
end
 
end
 
separator = ''
 
separator = ''
  +
 
names[parts.name] = 1
+
ingredients[parts.name] = 1
 
end
 
end
 
end
 
end
end
+
end
 
ingredientsCell = table.concat( ingredientsCell )
 
nameCell = table.concat( nameCell )
 
 
end
 
end
 
 
 
-- Ячейка с рецептом
if nameCell and args["запланированное"] then
 
 
local recipeCell = require( 'Модуль:Обработка' ).interface( args )
nameCell = nameCell .. '<br>([[' .. args["запланированное"] .. ']])'
 
end
 
 
 
-- Ячейка с ингредиентами
+
-- Ячейка с продуктами
local ingredientsCell
+
local nameCell
if args["ингредиенты"] or '' ~= '' then
+
if args["название"] or '' ~= '' then
ingredientsCell = args["ингредиенты"]
+
nameCell = args["название"]
 
elseif f:callParserFunction( '#dplvar', 'resultname' ) == '1' then
else
 
ingredientsCell = {}
+
nameCell = {}
local ingredients = {}
+
local names = {}
  +
for k, v in ipairs ( output ) do
local separator = ''
 
 
local separator = ''
for k, v in ipairs{ input, fuel, input3, input4, input5, input6, input7, input8, input9 } do
 
if k > 1 and next( ingredients ) then
+
if k > 1 and next( names ) then
 
separator = '&nbsp;+<br>\n'
 
separator = '&nbsp;+<br>\n'
 
end
 
end
 
for item in mw.text.gsplit( v, '%s*;%s*' ) do
 
for item in mw.text.gsplit( v, '%s*;%s*' ) do
 
local parts = getParts( item, mod )
 
local parts = getParts( item, mod )
if parts.name ~= '' and not ingredients[parts.name] and ( k >= 1 and ( v ~= fuel or mod == 'GregTech' ) ) then
+
if parts.name ~= '' and not names[parts.name] and ( k >= 1 ) then
 
local link = ''
 
local link = ''
if separator == '' and next( ingredients ) then
+
if separator == '' and next( names ) then
 
separator = '&nbsp;или<br>\n'
 
separator = '&nbsp;или<br>\n'
 
end
 
end
  +
 
 
if parts.mod then
 
if parts.mod then
 
link = parts.mod .. '/' .. parts.name .. '|'
 
link = parts.mod .. '/' .. parts.name .. '|'
 
end
 
end
  +
 
 
if parts.name:find( '^Люб' ) then
 
if parts.name:find( '^Люб' ) then
if parts.mod then
+
if parts.mod then
link = parts.mod .. '/' .. mw.ustring.gsub( mw.ustring.sub( parts.name, 7 ), "^%l", mw.ustring.upper ) .. '|'
+
link = parts.mod .. '/' .. mw.ustring.gsub( mw.ustring.sub( parts.name, 7 ), "^%l", mw.ustring.upper ) .. '|'
end
+
end
table.insert( ingredientsCell, separator .. mw.ustring.sub( parts.name, 0, 6 ) .. '[[' .. link .. mw.ustring.sub( parts.name, 6 ) .. ']]' )
+
table.insert( nameCell, separator .. mw.ustring.sub( parts.name, 0, 6 ) .. '[[' .. link .. mw.ustring.sub( parts.name, 6 ) .. ']]' )
 
else
 
else
table.insert( ingredientsCell, separator .. '[[' .. link .. parts.name .. ']]' )
+
table.insert( nameCell, separator .. '[[' .. link .. parts.name .. ']]' )
 
end
 
end
 
separator = ''
 
separator = ''
  +
 
ingredients[parts.name] = 1
+
names[parts.name] = 1
 
end
 
end
 
end
 
end
 
end
 
end
 
 
ingredientsCell = table.concat( ingredientsCell )
+
nameCell = table.concat( nameCell )
 
end
 
end
  +
 
 
if nameCell and args["запланированное"] then
-- Остальные аргументы
 
 
nameCell = nameCell .. '<br>([[' .. args["запланированное"] .. ']])'
local newArgs = args
 
  +
end
newArgs["Ресурс"] = input
 
  +
newArgs["Выход"] = output
 
  +
-- Сборка строки таблицы с интерфейсом
newArgs["Опыт"] = args[3] or args["Опыт"]
 
newArgs["Топливо"] = fuel
 
newArgs["Мод"] = mod
 
newArgs["Прогресс"] = progress or 'Печь'
 
newArgs["Версия"] = version
 
 
-- Ячейка с рецептом
 
local recipeCell = require( 'Модуль:GregTechProc' ).craftingTable( newArgs )
 
 
 
local row = {
 
local row = {
'|\n' .. ingredientsCell,
+
'\n|' .. ingredientsCell,
'style="padding:1px" |\n' .. recipeCell
+
recipeCell
 
}
 
}
 
if nameCell then
 
if nameCell then
table.insert( row, 3, '<b>' .. nameCell .. '</b>' )
+
table.insert( row, nameCell )
 
end
 
end
 
if f:callParserFunction( '#dplvar', 'smeltingdescription' ) == '1' then
 
if f:callParserFunction( '#dplvar', 'smeltingdescription' ) == '1' then
 
table.insert( row, args["описание"] or '' )
 
table.insert( row, args["описание"] or '' )
 
end
 
end
row = table.concat( row, '\n|' )
+
row = table.concat( row, '\n|' ) .. '\n|-'
  +
 
  +
-- Закрытие таблицы
 
local footer = ''
 
local footer = ''
 
if foot ~= '' then
 
if foot ~= '' then
footer = '|}'
+
footer = '\n|}'
 
f:callParserFunction( '#dplvar:set', 'resultname', '0', 'smeltingdescription', '0' )
 
f:callParserFunction( '#dplvar:set', 'resultname', '0', 'smeltingdescription', '0' )
 
end
 
end
  +
 
 
local title = mw.title.getCurrentTitle()
 
local title = mw.title.getCurrentTitle()
 
local category = ''
 
local category = ''
Строка 243: Строка 236:
 
category = '[[Категория:Запланированные материалы]]'
 
category = '[[Категория:Запланированные материалы]]'
 
end
 
end
  +
 
return header .. '\n' .. row .. '\n|-\n' .. footer .. category
+
return header .. row .. footer .. category
 
end
 
end
 
return p
 
return p

Текущая версия от 15:42, 5 августа 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 '0'
	if tonumber(head) then
		head = tonumber(head)
	else
		error("Параметр «глава» не является числом.")
	end
	if multirow then
		head = 0
	elseif head ~= 0 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["Мод"]
	if not mod and args["Прогресс"] then
		if args['Прогресс']:find('gt4') then
			mod = 'GregTech 4'
		elseif args['Прогресс']:find('gt') then
			mod = 'GregTech'
		elseif args['Прогресс']:find('ic2') then
			mod = 'IndustrialCraft 2'
		end
	end
	args["Мод"] = mod

	-- Сборка заголовка таблицы
	local header = ''
	if head ~= 0 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 ''
		if multirow then
			class = 'sortable collapsible ' .. class
			recipeClass = 'class="unsortable" |'
		else
			recipeClass = ''
		end
		if args["Прогресс"] then
			process = ' Процесс'
		else
			process = ' [[Плавка|Процесс]]'
		end
		local table_head
		if head >= 2 then
			table_head = '|-'
		else
			table_head = ' {| style="text-align:center" class="wikitable ' .. class .. '" data-description="Процесс"'
		end
		if head ~= 3 then
			header = table.concat( {
				table_head,
				'! ' .. 'Ингредиенты !! ' .. recipeClass .. process .. name .. description,
				'|-'}, '\n' )
		end
	end
	
	-- Конвертор аргументов
	args["Ресурс1"] = args["Ресурс1"] or args["Ресурс"] or args[1]
	args["Ресурс2"] = args["Ресурс2"] or args["Топливо"] or args["топливо"]
	args["Выход1"] = args["Выход1"] or args["Выход"] or args[2]
	args["РесурсЖ1"] = args["РесурсЖ1"] or args["РесурсЖ"]
	args["ВыходЖ1"] = args["ВыходЖ1"] or args["ВыходЖ"]
	
	local input = {}
	n = 1
	while args['Ресурс' .. n] do
		table.insert( input , mw.text.trim( args['Ресурс' .. n] ))
		n = n + 1
	end
	n = 1
	while args['РесурсЖ' .. n] do
		table.insert( input , mw.text.trim( args['РесурсЖ' .. n] ))
		n = n + 1
	end
	local output = {}
	n = 1
	while args['Выход' .. n] do
		table.insert( output , mw.text.trim( args['Выход' .. n] ))
		n = n + 1
	end
	n = 1
	while args['ВыходЖ' .. n] do
		table.insert( output , mw.text.trim( args['ВыходЖ' .. n] ))
		n = n + 1
	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 recipeCell = require( 'Модуль:Обработка' ).interface( args )
	
	-- Ячейка с продуктами
	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