Warning.png

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

Модуль:Варка — различия между версиями

Материал из Hilarious Wiki
Перейти к: навигация, поиск
м (Удаление ссылок на ванильные предметы и блоки)
м (Отмена правки 6253, сделанной участником Popstop (обс.))
Строка 1: Строка 1:
 
local p = {}
 
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 )
 
function p.table( f )
 
local args = f
 
local args = f
 
if f == mw.getCurrentFrame() then
 
if f == mw.getCurrentFrame() then
args = require( 'Модуль:ProcessArgs' ).merge()
+
args = f:getParent().args
 
else
 
else
 
f = mw.getCurrentFrame()
 
f = mw.getCurrentFrame()
 
end
 
end
 +
local getParts = require( 'Модуль:Инвентарный слот' ).getParts
 
 
 
-- Начинать таблицу при необходимости
 
-- Начинать таблицу при необходимости
Строка 42: Строка 17:
 
if multirow then
 
if multirow then
 
head = ''
 
head = ''
elseif head ~= '' then
+
elseif head ~= '' then
multirow = 1
+
multirow = 1
f:callParserFunction( '#dplvar:set', 'multirow', '1' )
+
f:callParserFunction( '#dplvar:set', 'multirow', '1' )
else
+
else
head = 1
+
head = 1
end
+
end
 
+
 
-- Заканчивать таблицу при необходимости
 
-- Заканчивать таблицу при необходимости
 
local foot = args["подвал"] or ''
 
local foot = args["подвал"] or ''
Строка 64: Строка 39:
 
local name = ''
 
local name = ''
 
local description = ''
 
local description = ''
local effect = ''
+
        local effect = ''
local duration = ''
+
        local duration = ''
if args["название"] or args["показатьимя"] == '1' or multirow and args["показатьимя"] ~= '0' then
+
        if args["название"] or args["показатьимя"] == '1' or multirow and args["показатьимя"] ~= '0' then
 
name = 'Название !! '
 
name = 'Название !! '
 
f:callParserFunction( '#dplvar:set', 'brewingname', '1' )
 
f:callParserFunction( '#dplvar:set', 'brewingname', '1' )
Строка 92: Строка 67:
 
'! ' .. name .. 'width="150" | Ингредиенты !! ' .. recipeClass .. ' Схема [[Зельеварение|варки]]' .. effect .. duration .. description,
 
'! ' .. name .. 'width="150" | Ингредиенты !! ' .. recipeClass .. ' Схема [[Зельеварение|варки]]' .. effect .. duration .. description,
 
'|-'
 
'|-'
}, '\n' )
+
}, '\n' )
 
end
 
end
 
 
 
local input = mw.text.trim( args[1] or '' )
 
local input = mw.text.trim( args[1] or '' )
 
local output2 = mw.text.trim( args[2] or '' )
 
local output2 = mw.text.trim( args[2] or '' )
local base = args['Ресурс'] or ''
+
    local base = args['Ресурс'] or ''
 
if base == '' then
 
if base == '' then
 
base = 'Грубое зелье'
 
base = 'Грубое зелье'
Строка 104: Строка 79:
 
-- Ячейка с названием
 
-- Ячейка с названием
 
local nameCell
 
local nameCell
if  f:callParserFunction( '#dplvar', 'brewingname' ) == '1' then
+
if args["название"] or '' ~= '' then
if args["название"] or '' ~= '' then
+
nameCell = args["название"]
nameCell = args["название"]
+
elseif multirow or f:callParserFunction( '#dplvar', 'brewingname' ) == '1' then
else
+
local names = {}
local names = {}
+
local links = {}
local links = {}
+
for v in mw.text.gsplit( args[2] or '', '%s*;%s*' ) do
for v in mw.text.gsplit( args[2] or '', '%s*;%s*' ) do
+
parts = getParts( v )
parts = getParts( v, args["Мод"] )
+
if not names[( parts.mod or '' ) .. parts.name] then
parts.mod = parts.mod or ''
+
local link = ''
if not names[( parts.mod or '' ) .. parts.name] then
+
if parts.mod then
table.insert( links, prefixedLink( parts.name, parts.mod) )
+
link = parts.mod .. '/' .. parts.name .. '|'
names[parts.mod .. ':' .. parts.name] = 1
+
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 .. parts.name .. ']]' )
 
end
 
end
 +
names[( parts.mod or '' ) .. parts.name] = 1
 
end
 
end
 
nameCell = table.concat( links, '&nbsp;или<br>')
 
 
end
 
end
 +
 +
nameCell = table.concat( links, '&nbsp;или<br>' )
 
end
 
end
 
 
Строка 131: Строка 112:
 
if args["ингредиенты"] or '' ~= '' and fuelslot ~= '' then
 
if args["ингредиенты"] or '' ~= '' and fuelslot ~= '' then
 
ingredientsCell = args["ингредиенты"] .. ' +<br>[[Огненный порошок]] (топливо)'
 
ingredientsCell = args["ингредиенты"] .. ' +<br>[[Огненный порошок]] (топливо)'
elseif args["ингредиенты"] or '' ~= '' then
+
elseif args["ингредиенты"] or '' ~= '' then
ingredientsCell = args["ингредиенты"]
+
ingredientsCell = args["ингредиенты"]
else
+
else
ingredientsCell = {}
+
ingredientsCell = {}
local ingredients = {}
+
local ingredients = {}
for k, v in ipairs{ input, base } do
+
for k, v in ipairs{ input, base } do
local separator = ''
+
local separator = ''
if k == 2 and next( ingredients ) then
+
if k == 2 and next( ingredients ) then
separator = '&nbsp;+<br>\n'
+
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 .. '|'
 +
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 .. parts.name .. ']]' )
 +
end
 +
separator = ''
 +
 +
ingredients[parts.name] = 1
 
end
 
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
 
end
 
ingredientsCell = table.concat( ingredientsCell, '<br>\n' )
 
 
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
 
-- Whether to show base or output
 
local newArgs = {}
 
local newArgs = {}
if args["показатьресурс"] == '1' then
+
if args["показатьресурс"] == '1' then
newArgs["Выход2"] = base
+
      newArgs["Выход2"] = base
newArgs["Выход1"] = args["Ресурс2"]
+
newArgs["Выход1"] = args["Ресурс2"]
newArgs["Выход3"] = args["Ресурс3"]
+
newArgs["Выход3"] = args["Ресурс3"]
else
+
else
newArgs["Выход2"] = args[2]
+
      newArgs["Выход2"] = args[2]
newArgs["Выход1"] = args[3]
+
newArgs["Выход1"] = args[3]
newArgs["Выход3"] = args[4]
+
newArgs["Выход3"] = args[4]
end
+
end
  
 
     -- Any other args we want to pass along
 
     -- Any other args we want to pass along
    newArgs["Ресурс"] = args[1]
+
newArgs["Ресурс"] = args[1]
    newArgs["Рназв"] = args["Рназв"]
+
newArgs["Рназв"] = args["Рназв"]
    newArgs["В2назв"] = args["Вназв"]
+
newArgs["В2назв"] = args["Вназв"]
    newArgs["В1назв"] = args["В2назв"]
+
newArgs["В1назв"] = args["В2назв"]
    newArgs["В3назв"] = args["В3назв"]
+
newArgs["В3назв"] = args["В3назв"]
    newArgs.fuelslot = fuelslot
+
newArgs.fuelslot = fuelslot
 
+
 
-- Ячейка с рецептом
 
-- Ячейка с рецептом
 
local recipeCell = require( 'Модуль:Интерфейс' ).brewingStand( newArgs )
 
local recipeCell = require( 'Модуль:Интерфейс' ).brewingStand( newArgs )
 
 
 
local row = {
 
local row = {
'\n' .. ingredientsCell,
+
'\n' .. ingredientsCell,
'style="padding:1px" |\n' .. recipeCell
+
'style="padding:1px" |\n' .. recipeCell
}
+
}
if nameCell then
+
if nameCell then
table.insert( row, 1, nameCell )
+
table.insert( row, 1, nameCell )
end
+
end
  
 
-- Ячейка с эффектом
 
-- Ячейка с эффектом
Строка 186: Строка 189:
 
end
 
end
  
-- Ячейка с продолжительностью
+
-- Ячейка с продолжительностьительностью
 
local durationCell = args["продолжительность"] or ''
 
local durationCell = args["продолжительность"] or ''
 
if f:callParserFunction( '#dplvar', 'brewingduration' ) == '1' then
 
if f:callParserFunction( '#dplvar', 'brewingduration' ) == '1' then
Строка 217: Строка 220:
 
end
 
end
 
 
if args["отладка"] == '1' then
+
return header .. '\n' .. row .. '\n|-\n' .. footer .. category
return '<pre>' .. header .. '\n' .. row .. '\n|-\n' .. footer .. categories .. '</pre>'
 
else
 
return header .. '\n' .. row .. '\n|-\n' .. footer .. category
 
end
 
 
end
 
end
return p
+
return p

Версия 18:41, 15 октября 2018

Документация

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

Зависимости

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

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

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 .. '|'
				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 .. parts.name .. ']]' )
				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 .. '|'
					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 .. parts.name .. ']]' )
					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