Minecraft Wiki
Регистрация
Advertisement

Этот модуль реализует общие шаблоны интерфейса, чтобы избежать чрезмерной нагрузки от #invoke вызовов.

Зависимости

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

----------------------------------------------------------------------------------------------------
-- Модуль для отображения окон интерфейса (крафта, обжига, варки...) на страницах Minecraft Wiki.
----------------------------------------------------------------------------------------------------


-- Внутренние функции
local slot = require('Модуль:Инвентарный слот').slot
local addSlot = function( args, item, prefix, class, default )
	local none, nostacksize
	prefix = prefix or ''
	if #prefix == 0 then
		none = 'нет'
		nostacksize = ((item == '' or nil) and '') or (args and args[item] and args[item]:gsub( '[,%d]', '' ) or '')
	end
	return slot{
		nostacksize or args[item], ["мод"] = args["Мод"], ["ссылка"] = none or args[prefix .. 'Ссылка'],
		["назв"] = none or args[prefix .. 'Назв'], ["класс"] = class, ["умолчание"] = default
	}
end

-- Экспортируемые функции
local p = {}

-- Верстак (крафт)
function p.craftingTable( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	
	local body = mw.html.create('div'):addClass('craft-gui gui')
	
	local input = body:tag('span'):addClass('mcui-input')
	for num = 1, 3 do
		local row = input:tag('span'):addClass('mcui-row')
		for _, letter in ipairs{'A', 'B', 'C'} do
			row:wikitext(addSlot(args, letter .. num, 'Р'))
		end
	end
	
	local arrow = body:tag('span'):addClass('mcui-arrow'):tag('br'):done()
	if args["Стрелка"] or '' ~= '' then
		arrow:cssText( 'background-image:{{FileUrl|Grid layout ' .. args["Стрелка"] .. ' (' .. args["Мод"] .. ').png}}'
		)
	end
	
	body
		:tag( 'span' )
			:addClass( 'mcui-output' )
			:wikitext( addSlot( args, 'Выход', 'В', 'invslot-large' ) )
	
	local shapeless = args["бесформенный"] or ''
	local fixed = args["фиксированный"] or ''
	if shapeless ~= '' or fixed ~= '' then
		local icon = body:tag( 'span' )
			:addClass( 'mcui-icons' )
			:tag( 'span' )
				:tag( 'br' )
			:done()
		if shapeless ~= '' then
			icon:addClass( 'mcui-shapeless' )
				:attr( 'title',
					'Этот рецепт бесформенный, ресурсы могут располагаться в сетке верстака в любом порядке.'
				)
		elseif fixed ~= '' then
			local notFixed = args["нефиксировано"] or '' -- указывайте в родительном падеже
			local exceptFixed = ''
			if notFixed ~= '' then
				exceptFixed = ', за исключением ' .. notFixed
			end
			
			icon:addClass( 'mcui-fixed' )
				:attr( 'title',
					'Этот рецепт фиксированный, его ингредиенты не могут быть перемещены или зеркально отражены' .. exceptFixed .. '.'
				)
		end
	end
	
	return tostring( mw.html.create( 'div' ):node( body ) )
end

-- Варочная стойка (варка)
function p.brewingStand( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	
	local body = mw.html.create( 'span' ):addClass( 'mcui mcui-Brewing_Stand' )
	local input = body:tag( 'span' ):addClass( 'mcui-input' )
	local inactive = ( args["Ресурс"] or '' ) == '' or
		( ( args["Выход1"] or '' ) == '' and ( args["Выход2"] or '' ) == '' and ( args["Выход3"] or '' ) == '' )

    if not inactive then
        local fuelslot = 'Огненный порошок'
        input:wikitext( slot{ fuelslot } )
    else
        input:wikitext( slot{ ["умолчание"] = 'Grid_layout_Brewing_Blaze_Empty' } )
    end

	input:tag( 'span' ):addClass( 'mcui-blaze' ):tag( 'br' )
	input:tag( 'span' ):addClass( 'mcui-bubbling' ):tag( 'br' )
	input:wikitext( addSlot( args, 'Ресурс', 'Р' ) )
	input:tag( 'span' ):addClass( 'mcui-arrow' ):tag( 'br' )
	if inactive
	then
		input:addClass( 'mcui-inactive' )
    end
	
	body:tag( 'span' ):addClass( 'mcui-paths' ):tag( 'br' )
	
	local output = body:tag( 'span' ):addClass( 'mcui-output' )
	for i = 1, 3 do
		output:wikitext( addSlot( args, 'Выход' .. i, 'В' .. i, 'mcui-output' .. i ) )
	end
	
	return tostring( mw.html.create( 'div' ):node( body ) )
end

return p
Advertisement