Изменения

Модуль:Обжиг

3748 байтов добавлено, 14:36, 24 октября 2018
м
Тест
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 = frequire( 'Модуль:getParentProcessArgs' ).merge().args
else
f = mw.getCurrentFrame()
end
local getParts = require( 'Модуль:Инвентарный слот' ).getParts
-- Начинать таблицу при необходимости
head = ''
elseif head ~= '' then
multirow = 1 f:callParserFunction( '#dplvar:set', 'multirow', '1' ) else head = 1 end
-- Заканчивать таблицу при необходимости
local foot = args["подвал"] or ''
recipeClass = 'class="unsortable" |'
end
local process = ' Процесс' if args["Прогресс"] and args["Мод"] then process=' Процесс' end
header = table.concat( {
' {| style="text-align:center" class="wikitable ' .. class .. '" data-description="Процесс"',
'! ' .. 'Ингредиенты !! ' .. recipeClass .. process .. name .. description,
'|-'
}, '\n' )
end
local input = mw.text.trim( args[1] or args["Ресурс"] or '' )
local output = mw.text.trim( args[2] or args["Выход"] or '' )
local fuel = args["топливо"] or args["Топливо"] or ''
if fuel == '' and (args["Мод"] == 'IndustrialCraft 2' or 'GregTech' and args['Расход'] == 'Электричество') then
fuel = 'Энергия'
elseif fuel == '' then fuel = 'v:Любое топливо,1' end
-- Ячейка с названием
local nameCell
if f:callParserFunction( '#dplvar', 'smeltingname' ) == '1' then if args["название"] or '' ~= '' then nameCell = args["название"] elseif multirow or f:callParserFunction( '#dplvar', 'smeltingname' ) == '1' then else local names = {} local links = {} for v in mw.text.gsplit( args[2] or args["Выход"] or '', '%s*;%s*' ) do parts = getParts( v, args["Мод"] ) if not names[( parts.mod or '' ) .. parts.name] and output ~= '' then local link = '' if parts.mod then link = parts.mod .. '/' .. parts.name .. or '|' end if parts.name:find( '^Люб' ) then if parts.mod then link = not names[parts.mod .. '/:' .. mw.ustring.gsub( mw.ustring.sub( parts.name, 7 ), "^%l", mw.ustring.upper ) .. '|' end] then table.insert( links, mw.ustring.subprefixedLink( parts.name, 0, 6 parts.mod ) ) .. ' names[[' .. link .. mw.ustring.sub( parts.name, 6 ) mod .. ']]:' ) else table.insert( links, . parts.name )] = 1
end
names[( parts.mod or '' ) .. parts.name] = 1
end
 
nameCell = table.concat( links, '&nbsp;или<br>' )
end
nameCell = table.concat( links, '&nbsp;или<br>' )
end
if nameCell and args["запланированное"] then
nameCell = nameCell .. '<br>(' .. args["запланированное"] .. ')'
end
  -- Создать список ингредиентов local ingredients = {} local ingredientKeys = {} local animatedIngredients = {} local animatedKeys = {} for k, v in pairs( args ) do v = mw.text.trim( v ) if v ~= '' and mw.ustring.find(tostring( k ), '^%u?%d%d?$' ) then if mw.ustring.find(v, ';' ) then table.insert( animatedKeys, v ) else local parts = getParts( v, args["Мод"] ) parts.mod = parts.mod or '' local fullName = parts.mod .. ':' .. parts.name if not ingredients[fullName] then table.insert( ingredientKeys, fullName ) ingredients[fullName] = { mod = parts.mod, name = parts.name } end end end end for k, v in ipairs( animatedKeys ) do local frames = mw.text.split( v, '%s*;%s*' ) local length = #frames for k2, v2 in ipairs( frames ) do local parts = getParts( v2, args["Мод"] ) parts.mod = parts.mod or '' local fullName = parts.mod .. ':' .. parts.name if v2 ~= '' and not ingredients[fullName] and not animatedIngredients[fullName] then table.insert( ingredientKeys, fullName ) animatedIngredients[fullName] = { mod = parts.mod, name = parts.name, final = k2 == length } end end end 
-- Ячейка с ингредиентами
local vanilla = {v = 1, vanilla = 1, mc = 1, minecraft = 1}
local ingredientsCell
if args["ингредиенты"] or '' ~= '' then
else
ingredientsCell = {}
local ingredients = {} for k, v in ipairs{ input, fuel } ( ingredientKeys ) do local separator = '&nbsp;+' if k == 2 and next( ingredients ) #ingredientKeys then separator = '&nbsp;+<br>\n' end for item in mw.text.gsplit( elseif animatedIngredients[v, '%s*;%s*' ) do local parts = getParts( item, args["Мод"] ) if parts.name ~= '' and not ingredientsanimatedIngredients[partsv].name] and ( k == 2 or k == 1 and v ~= fuel ) final 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 if parts.mod then link = parts.mod .. '/' .. mw.ustring.gsub( mw.ustring.sub( parts.name, 7 ), "^%l", mw.ustring.upper ) .. '|' end table.insert( ingredientsCell, separator .. mw.ustring.sub( parts.name, 0, 6 ) .. '[[' .. link .. mw.ustring.sub( parts.name, 6 ) .. ']]' ) else table.insert( ingredientsCell, separator .. 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
ingredientsCell = table.concat( ingredientsCell , '<br>\n' )
end
-- Остальные аргументы
local newArgs = {}  newArgs["Ресурс"] = args[1] or args["Ресурс"], newArgs["Выход"] = args[2] or args["Выход"], newArgs["Топливо"] = fuel, newArgs["РНазв"] = args["рНазв"], newArgs["ВНазв"] = args["вНазв"], newArgs["ТНазв"] = args["тНазв"], newArgs["Мод"] = args["Мод"], newArgs["Прогресс"] = args["Прогресс"], newArgs["Расход"] = args["Расход"] }
-- Ячейка с рецептом
local recipeCell = require( 'Модуль:Интерфейс' ).furnace( newArgs )
local row = {
'|\n' .. ingredientsCell, 'style="padding:1px" |\n' .. recipeCell } if nameCell then table.insert( row, 3, '<b>' .. nameCell .. '</b>' ) end if f:callParserFunction( '#dplvar', 'smeltingdescription' ) == '1' then table.insert( row, args["описание"] or '' ) end row = table.concat( row, '\n|' ) local footer = '' if foot ~= '' then footer = '|}' f:callParserFunction( '#dplvar:set', 'smeltingname', '0', 'smeltingdescription', '0' ) end  -- Создание различных категорий для DPL
local title = mw.title.getCurrentTitle()
local category categories = '' if args["запланированное"] and args["некат"] ~= '1' and title.namespace == 0 and not title.isSubpage then category categories = {} if args["запланированное"] then table.insert( categories, '[[Категория:ЗапланированноеЗапланированные материалы]]') end if args["тип"] then table.insert( categories, '[[Категория:Рецепты/' .. args["тип"] .. ']]' ) end if args["игнорировать"] ~= '1' then local dyes = { 'Оранжевый краситель', 'Сиреневый краситель', 'Светло-синий краситель', 'Жёлтый краситель', 'Лаймовый краситель', 'Розовый краситель', 'Серый краситель', 'Светло-серый краситель', 'Бирюзовый краситель', 'Фиолетовый краситель', 'Лазурит', 'Какао-бобы', 'Кактусовая зелень', 'Красный краситель', 'Чернильный мешок' } -- Названия в следующем списке должны писаться ОБЯЗАТЕЛЬНО со строчной буквы, так как встречаются в середине названия: local variants = { 'древесина', 'доски', 'окрашенное стекло', 'окрашенная стеклянная панель', 'шерсть', 'песчаник', 'ступени', 'плита', 'нажимная пластина', 'звёздочка', 'каменный кирпич', 'андезит', 'диорит', 'гранит', 'щит' }  for k, v in ipairs( ingredientKeys ) do v = mw.ustring.sub(v, 2 ) if not mw.ustring.find(v, ':' ) then if v == 'Любой краситель' or v == 'Любой цветной краситель' then if v == 'Любой краситель' then table.insert( dyes, 1, 'Костная мука' ) end else if v == 'Липкий поршень' then v = 'Поршень' elseif v == 'Любой гриб' or v == 'Красный гриб' or v == 'Коричневый гриб' then v = 'Гриб' elseif v == 'Красный песок' then v = 'Песок' elseif v == 'Древесный уголь' then v = 'Уголь' elseif mw.ustring.find(v, 'красный песчаник$' ) then v = 'Песчаник' elseif mw.ustring.find(v, '^Флаг ') or mw.ustring.find(v, ' флаг$') then v = 'Флаг' elseif v == 'Кварцевый пилон' or v == 'Резной кварцевый блок' then v = 'Кварцевый блок' else -- Объединить категории вариантов, описываемых на единой странице for _, variant in pairs( variants ) do if mw.ustring.find(v, ' ' .. variant .. '$' ) then v = variant break end end -- Убрать приставки for _, prefix in pairs( prefixes ) do if mw.ustring.find(v, '^' .. prefix .. ' ' ) then v = mw.ustring.gsub(v, '^' .. prefix .. ' ', '' ) break end end end end end end end
end
return header .. '\n' .. row .. '\n|-\n' .. footer .. category
end
return p
1136
правок