Warning.png

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

Модуль:Варка

Материал из Hilarious Wiki
Версия от 18:39, 15 октября 2018; Popstop (обсуждение | вклад) (Удаление ссылок на ванильные предметы и блоки)

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

Этот модуль реализует {{варка}}.

Зависимости

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

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

local p = {}
local slot = require( [[Модуль:Инвентарный слот]] )
local getParts = slot.getParts
local prefixes = slot.prefixes

local function prefixedLink( name, mod )
	local prefix = ''
	for _, thisPrefix in pairs( prefixes ) do
		if mw.ustring.find(name, '^' .. thisPrefix .. ' ' ) then
			prefix = thisPrefix .. ' '
			name = mw.ustring.gsub(name, '^' .. prefix, '' )
			break
		end
	end
	
	local page = ''
	if mod and mod ~= '' then
		page = mod .. '/'
	end

	local vanilla = {v = 1, vanilla = 1, mc = 1, minecraft = 1}
	if mod == '' or vanilla[mw.ustring.lower(parts.mod)] then
		return prefix .. name
	else
		return prefix .. '[[' .. page .. name .. '|' .. name .. ']]'
	end
end
function p.table( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( 'Модуль:ProcessArgs' ).merge()
	else
		f = mw.getCurrentFrame()
	end
	
	-- Начинать таблицу при необходимости
	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 = ''
		local effect = ''
		local duration = ''
		if args["название"] or args["показатьимя"] == '1' or multirow and args["показатьимя"] ~= '0' then
			name = 'Название !! '
			f:callParserFunction( '#dplvar:set', 'brewingname', '1' )
		end
		if args["показатьописание"] == '1' then
			description = ' !! class="unsortable" | Описание'
			f:callParserFunction( '#dplvar:set', 'brewingdescription', '1' )
		end
		if args["эффект"] then
			effect = ' !! class="unsortable" | Эффект'
			f:callParserFunction( '#dplvar:set', 'brewingeffect', '1' )
		end
		if args["продолжительность"] then
			duration = ' !! class="unsortable" | Продолжительность<br />(минуты : секунды)'
			f:callParserFunction( '#dplvar:set', 'brewingduration', '1' )
		end
		local class = args["класс"] or ''
		local recipeClass = ''
		if multirow then
			class = 'sortable collapsible ' .. class
			recipeClass = 'class="unsortable" |'
		end
		header = table.concat( {
			' {| class="wikitable ' .. class .. '" style="text-align:center" data-description="Схема варки"',
			'! ' .. name .. 'width="150" | Ингредиенты !! ' .. recipeClass .. ' Схема [[Зельеварение|варки]]' .. effect .. duration .. description,
			'|-'
			}, '\n' )
	end
	
	local input = mw.text.trim( args[1] or '' )
	local output2 = mw.text.trim( args[2] or '' )
	local base = args['Ресурс'] or ''
	if base == '' then
		base = 'Грубое зелье'
	end
	
	-- Ячейка с названием
	local nameCell
	if  f:callParserFunction( '#dplvar', 'brewingname' ) == '1' then
		if args["название"] or '' ~= '' then
			nameCell = args["название"]
		else
			local names = {}
			local links = {}
			for v in mw.text.gsplit( args[2] or '', '%s*;%s*' ) do
				parts = getParts( v, args["Мод"] )
				parts.mod = parts.mod or ''
				if not names[( parts.mod or '' ) .. parts.name] then
					table.insert( links, prefixedLink( parts.name, parts.mod) )
					names[parts.mod .. ':' .. parts.name] = 1
				end
			end

			nameCell = table.concat( links, '&nbsp;или<br>')
		end
	end
	
	if nameCell and args["запланированное"] then
		nameCell = nameCell .. '<br>(' .. args["запланированное"] .. ')'
	end

	-- Ячейка с ингредиентами
	local ingredientsCell
	if args["ингредиенты"] or '' ~= '' and fuelslot ~= '' then
		ingredientsCell = args["ингредиенты"] .. ' +<br>[[Огненный порошок]] (топливо)'
		elseif args["ингредиенты"] or '' ~= '' then
			ingredientsCell = args["ингредиенты"]
		else
			ingredientsCell = {}
			local ingredients = {}
			for k, v in ipairs{ input, base } do
				local separator = ''
				if k == 2 and next( ingredients ) then
					separator = '&nbsp;+<br>\n'
				end
				local mod = ( ingredients[v] or animatedIngredients[v] ).mod
				local name = ( ingredients[v] or animatedIngredients[v] ).name
				table.insert( ingredientsCell, prefixedLink( name, mod ) .. separator )
			end

			ingredientsCell = table.concat( ingredientsCell, '<br>\n' )
		end

	-- Whether to show base or output
	local newArgs = {}
	if args["показатьресурс"] == '1' then
		newArgs["Выход2"] = base
		newArgs["Выход1"] = args["Ресурс2"]
		newArgs["Выход3"] = args["Ресурс3"]
	else
		newArgs["Выход2"] = args[2]
		newArgs["Выход1"] = args[3]
		newArgs["Выход3"] = args[4]
	end

    -- Any other args we want to pass along
    newArgs["Ресурс"] = args[1]
    newArgs["Рназв"] = args["Рназв"]
    newArgs["В2назв"] = args["Вназв"]
    newArgs["В1назв"] = args["В2назв"]
    newArgs["В3назв"] = args["В3назв"]
    newArgs.fuelslot = fuelslot

	-- Ячейка с рецептом
	local recipeCell = require( 'Модуль:Интерфейс' ).brewingStand( newArgs )
	
	local row = {
	'\n' .. ingredientsCell,
	'style="padding:1px" |\n' .. recipeCell
}
if nameCell then
	table.insert( row, 1, nameCell )
end

	-- Ячейка с эффектом
	local effectCell = args["эффект"] or ''
	if f:callParserFunction( '#dplvar', 'brewingeffect' ) == '1' then
		table.insert( row, effectCell )
	end

	-- Ячейка с продолжительностью
	local durationCell = args["продолжительность"] or ''
	if f:callParserFunction( '#dplvar', 'brewingduration' ) == '1' then
		table.insert( row, durationCell )
	end

	local descriptionCell = args["описание"] or ''
	if f:callParserFunction( '#dplvar', 'brewingdescription' ) == '1' then
		table.insert( row, descriptionCell )
	end

	row = table.concat( row, '\n|' )
	
	if nameCell then
		row = '!\n' .. row
	else
		row = '|\n' .. row
	end
	
	local footer = ''
	if foot ~= '' then
		footer = '|}'
		f:callParserFunction( '#dplvar:set', 'brewingname', '0', 'brewingeffect', '0', 'brewingduration', '0', 'brewingdescription', '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
	
	if args["отладка"] == '1' then
		return '<pre>' .. header .. '\n' .. row .. '\n|-\n' .. footer .. categories .. '</pre>'
	else
		return header .. '\n' .. row .. '\n|-\n' .. footer .. category
	end
end
	return p