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 = ''
        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 args["название"] or '' ~= '' then
		nameCell = args["название"]
	elseif multirow or f:callParserFunction( '#dplvar', 'brewingname' ) == '1' then
		local names = {}
		local links = {}
		for v in mw.text.gsplit( args[2] or '', '%s*;%s*' ) do
			parts = getParts( v )
			if not names[( parts.mod or '' ) .. parts.name] then
				local link = ''
				if parts.mod then
					link = '[[' .. parts.mod .. '/' .. parts.name .. '|' .. parts.name .. ']]'
				else
					link = parts.name
				end
				
				if parts.name:find( '^Люб' ) then
					table.insert( links, mw.ustring.sub( parts.name, 0, 6 ) .. link .. mw.ustring.sub( parts.name, 6 ))
				else
					table.insert( links, link )
				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 '' ~= '' 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
			for item in mw.text.gsplit( v, '%s*;%s*' ) do
				local parts = getParts( item )
				if parts.name ~= '' and not ingredients[parts.name] and ( k == 2 or k == 1 and v ~= base ) then
					local link = ''
					if separator == '' and next( ingredients ) then
						separator = '&nbsp;или<br>\n'
					end
					
				if parts.mod then
					link = '[[' .. parts.mod .. '/' .. parts.name .. '|' .. parts.name .. ']]'
				else
					link = parts.name
				end
				
				if parts.name:find( '^Люб' ) then
					table.insert( ingredientsCell, separator .. mw.ustring.sub( parts.name, 0, 6 ) .. link .. mw.ustring.sub( parts.name, 6 ))
				else
					table.insert( ingredientsCell, separator .. link )
				end
					separator = ''
					
					ingredients[parts.name] = 1
				end
			end
		end
        if fuelslot ~= '' then
		ingredientsCell = table.concat( ingredientsCell ) .. '&nbsp;+<br>\nОгненный порошок (топливо)'
        else
        ingredientsCell = table.concat( ingredientsCell )
        end
	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
	
	return header .. '\n' .. row .. '\n|-\n' .. footer .. category
end
return p