Minecraft Wiki
Нет описания правки
м (Отмена правки, сделанной Gk 0)
Метка: отмена
 
(не показано 27 промежуточных версий 6 участников)
Строка 7: Строка 7:
 
local slot = require('Модуль:Инвентарный слот').slot
 
local slot = require('Модуль:Инвентарный слот').slot
 
local addSlot = function( args, item, prefix, class, default )
 
local addSlot = function( args, item, prefix, class, default )
  +
local none, nostacksize
prefix = prefix or item
+
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{
 
return slot{
args[item], ["мод"] = args["Мод"], ["ссылка"] = args[prefix .. 'Ссылка'],
+
nostacksize or args[item], ["мод"] = args["Мод"], ["ссылка"] = none or args[prefix .. 'Ссылка'],
["назв"] = args[prefix .. 'Назв'], ["класс"] = class, ["умолчание"] = default
+
["назв"] = none or args[prefix .. 'Назв'], ["класс"] = class, ["умолчание"] = default
 
}
 
}
 
end
 
end
Строка 26: Строка 31:
 
end
 
end
 
 
local body = mw.html.create('span'):addClass('mcui mcui-Crafting_Table')
+
local body = mw.html.create('div'):addClass('craft-gui gui')
 
 
 
local input = body:tag('span'):addClass('mcui-input')
 
local input = body:tag('span'):addClass('mcui-input')
Строка 32: Строка 37:
 
local row = input:tag('span'):addClass('mcui-row')
 
local row = input:tag('span'):addClass('mcui-row')
 
for _, letter in ipairs{'A', 'B', 'C'} do
 
for _, letter in ipairs{'A', 'B', 'C'} do
row:wikitext(addSlot(args, letter .. num))
+
row:wikitext(addSlot(args, letter .. num, 'Р'))
 
end
 
end
 
end
 
end
Строка 58: Строка 63:
 
icon:addClass( 'mcui-shapeless' )
 
icon:addClass( 'mcui-shapeless' )
 
:attr( 'title',
 
:attr( 'title',
'Этот рецепт — бесформенный; ресурсы могут располагаться в сетке верстака в любом порядке.'
+
'Этот рецепт бесформенный, ресурсы могут располагаться в сетке верстака в любом порядке.'
 
)
 
)
 
elseif fixed ~= '' then
 
elseif fixed ~= '' then
Строка 69: Строка 74:
 
icon:addClass( 'mcui-fixed' )
 
icon:addClass( 'mcui-fixed' )
 
:attr( 'title',
 
:attr( 'title',
'Этот рецепт — фиксированный, его ингредиенты не могут быть перемещены или зеркально отражены' .. exceptFixed .. '.'
+
'Этот рецепт фиксированный, его ингредиенты не могут быть перемещены или зеркально отражены' .. exceptFixed .. '.'
 
)
 
)
 
end
 
end
 
end
 
end
 
 
return tostring( mw.html.create( 'div' ):node( body ) )
 
end
 
 
-- Печка (обжиг)
 
function p.furnace( 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-Furnace' ):cssText( 'height:108px' )
 
 
local input = body:tag( 'span' ):addClass( 'mcui-input' )
 
input:wikitext( addSlot( args, 'Ресурс', 'Р' ) )
 
local fuel = input:tag( 'span' ):addClass( 'mcui-fuel' ):tag( 'br' ):done()
 
local fuelImg = args["Расход"] or ''
 
local burning = args["Ресурс"] or '' ~= '' and args["Топливо"] or '' ~= ''
 
if not burning then
 
fuel:addClass( 'mcui-inactive' )
 
if fuelImg ~= '' then
 
fuelImg = fuelImg .. ' (in-active)'
 
end
 
end
 
if fuelImg ~= '' and args["Мод"] then
 
fuel:cssText( 'background-image:{{FileUrl|Grid layout ' .. fuelImg .. ' (' .. args["Мод"] .. ').png}}'
 
)
 
end
 
input:wikitext( addSlot( args, 'Топливо', 'Т' ) )
 
 
local arrow = body:tag( 'span' ):addClass( 'mcui-arrow' ):tag( 'br' ):done()
 
local arrowImg = args["Прогресс"] or ''
 
if not burning or ( args["Выход"] or '' ) == '' then
 
arrow:addClass( 'mcui-inactive' )
 
if arrowImg ~= '' then
 
arrowImg = arrowImg .. ' (in-active)'
 
end
 
end
 
if arrowImg ~= '' and args["Мод"] then
 
arrow:cssText( 'height: 100%; vertical-align: middle; background:none; margin:0;width:0' )
 
body:wikitext( '[[File:Grid layout ' .. arrowImg .. ' Progress (' .. args["Мод"] .. ').png|link=|middle]]' )
 
input:cssText( 'margin-right:14px' )
 
end
 
 
local output = body:tag( 'span' )
 
:addClass( 'mcui-output' )
 
:wikitext( addSlot( args, 'Выход', 'В', 'invslot-large' ) )
 
 
if arrowImg ~= '' and args["Мод"] then
 
output:cssText( 'margin-left:18px' )
 
end
 
 
 
return tostring( mw.html.create( 'div' ):node( body ) )
 
return tostring( mw.html.create( 'div' ):node( body ) )
 
end
 
end
Строка 145: Строка 97:
   
 
if not inactive then
 
if not inactive then
input:wikitext( slot{ 'Огненный порошок' } )
+
local fuelslot = 'Огненный порошок'
  +
input:wikitext( slot{ fuelslot } )
 
else
 
else
 
input:wikitext( slot{ ["умолчание"] = 'Grid_layout_Brewing_Blaze_Empty' } )
 
input:wikitext( slot{ ["умолчание"] = 'Grid_layout_Brewing_Blaze_Empty' } )

Текущая версия от 09:02, 21 ноября 2021

Этот модуль реализует общие шаблоны интерфейса, чтобы избежать чрезмерной нагрузки от #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