мНемає опису редагування Мітка: Скасування |
м (MakandIv перейменував сторінку з Модуль:Крафт3 на Модуль:Крафт2 без створення перенаправлення) |
||
(Не показано 7 проміжних версій цього користувача) | |||
Рядок 2: | Рядок 2: | ||
local p = {} |
local p = {} |
||
− | local slot = require( [[Модуль:Інвентарний |
+ | local slot = require( [[Модуль:Інвентарний слот2]] ) |
local getParts = slot.getParts |
local getParts = slot.getParts |
||
local prefixes = slot.prefixes |
local prefixes = slot.prefixes |
Поточна версія на 18:30, 5 січня 2020
-- Модуль для створення таблиць з рецептами для крафта.
local p = {}
local slot = require( [[Модуль:Інвентарний слот2]] )
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
local ucfirstName = mw.ustring.upper(mw.ustring.sub(name, 1, 1)) .. mw.ustring.sub(name, 2)
return prefix .. '[[' .. mod .. '/' .. ucfirstName .. '|' .. name .. ']]'
else
return prefix .. '[[' .. name .. ']]'
end
end
-- Будівництво таблиці
function p.table( f )
local args = f
if f == mw.getCurrentFrame() then
args = require( 'Модуль:ProcessArgs' ).merge()
else
f = mw.getCurrentFrame()
end
-- Починати таблицю при необхідності
local multirow = f:callParserFunction( '#dplvar', 'multirow' )
if multirow ~= '1' then
multirow = nil
end
local head = args["глава"] or '0'
if tonumber(head) then
head = tonumber(head)
else
error("Параметр «глава» не є числом.")
end
if multirow then
head = 0
elseif head ~= 0 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 ~= 0 then
local name = ''
local description = ''
if args["показатиім'я"] == '1' or multirow and args["показатиім'я"] ~= '0' then
name = '!! Результат'
f:callParserFunction( '#dplvar:set', 'resultname', '1' )
end
if args["показатиопис"] == '1' then
description = ' !! class="unsortable" | Опис'
f:callParserFunction( '#dplvar:set', 'craftingdescription', '1' )
end
local class = args["клас"] or ''
local recipeClass = ''
if multirow then
class = 'sortable collapsible ' .. class
recipeClass = 'class="unsortable" |'
end
local table_head
if head >= 2 then
table_head = '|-'
else
table_head = ' {| style="text-align:center" class="wikitable ' .. class .. '" data-description="Рецепти крафта"'
end
if head ~= 3 then
if args["Мод"] then
header = table.concat( {
table_head,
'! ' .. 'Інгредієнти !! ' .. recipeClass .. ' Процес' .. name .. description,
'|-'
}, '\n' )
else
header = table.concat( {
table_head,
'! ' .. 'Інгредієнти !! ' .. recipeClass .. ' Рецепти [[крафт]]а' .. name .. description,
'|-'
}, '\n' )
end
end
end
-- Осередок з назвою
local nameCell
if f:callParserFunction( '#dplvar', 'resultname' ) == '1' then
if args["назва"] or '' ~= '' then
nameCell = args["назва"]
else
local names = {}
local links = {}
for v in mw.text.gsplit( args["Вихід"] or '', '%s*;%s*' ) do
parts = getParts( v, args["Мод"] )
parts.mod = parts.mod or ''
if not names[parts.mod .. ':' .. parts.name] then
table.insert( links, prefixedLink( parts.name, parts.mod ) )
names[parts.mod .. ':' .. parts.name] = 1
end
end
nameCell = table.concat( links, ' або<br>' )
end
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 ingredientsCell
if args["інгредієнти"] or '' ~= '' then
ingredientsCell = args["інгредієнти"]
else
ingredientsCell = {}
for k, v in ipairs( ingredientKeys ) do
local separator = ' +'
if k == #ingredientKeys then
separator = ''
elseif animatedIngredients[v] and not animatedIngredients[v].final then
separator = ' або'
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 = {}
if args[1] then
newArgs["безформний"] = 1
if args[7] then
newArgs.A1 = args[1]
newArgs.B1 = args[2]
newArgs.C1 = args[3]
newArgs.A2 = args[4]
newArgs.B2 = args[5]
newArgs.C2 = args[6]
if args[8] then
-- ◼◼◼ ◼◼◼
-- ◼◼◼ OR ◼◼◼
-- ◼◼◼ ◼◼◻
newArgs.A3 = args[7]
newArgs.B3 = args[8]
newArgs.C3 = args[9]
if args[9] then
local identical = true
for i = 1, 8 do
if args[i] ~= args[i + 1] then
identical = false
end
end
if identical then
newArgs["безформний"] = nil
end
end
else
-- ◼◼◼
-- ◼◼◼
-- ◻◼◻
newArgs.B3 = args[7]
end
elseif args[2] then
newArgs.A2 = args[1]
newArgs.B2 = args[2]
if args[5] then
-- ◻◻◻ ◻◻◻
-- ◼◼◼ OR ◼◼◼
-- ◼◼◼ ◼◼◻
newArgs.C2 = args[3]
newArgs.A3 = args[4]
newArgs.B3 = args[5]
newArgs.C3 = args[6]
elseif args[4] then
-- ◻◻◻
-- ◼◼◻
-- ◼◼◻
newArgs.A3 = args[3]
newArgs.B3 = args[4]
else
-- ◻◻◻ ◻◻◻
-- ◼◼◻ OR ◼◼◻
-- ◻◼◻ ◻◻◻
newArgs.B3 = args[3]
end
else
-- ◻◻◻
-- ◻◼◻
-- ◻◻◻
newArgs.B2 = args[1]
newArgs["безформний"] = nil
end
else
newArgs.A1 = args.A1
newArgs.B1 = args.B1
newArgs.C1 = args.C1
newArgs.A2 = args.A2
newArgs.B2 = args.B2
newArgs.C2 = args.C2
newArgs.A3 = args.A3
newArgs.B3 = args.B3
newArgs.C3 = args.C3
newArgs["фіксований"] = args["фіксований"]
newArgs["нефіксований"] = args["нефіксований"]
end
-- Остальные аргументы
newArgs["Мод"] = args["Мод"]
newArgs["Вихід"] = args["Вихід"]
newArgs["ВНазва"] = args["ВНазва"]
newArgs["ВПосилання"] = args["ВПосилання"]
-- Осередок з рецептом
local recipeCell = require( 'Модуль:UI' ).craftingTable( 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', 'craftingdescription' ) == '1' then
table.insert( row, args["опис"] or '' )
end
row = table.concat( row, '\n|' )
local footer = ''
if foot ~= '' then
footer = '|}'
f:callParserFunction( '#dplvar:set', 'resultname', '0', 'craftingdescription', '0' )
end
-- Створення різних категорій для DPL
local title = mw.title.getCurrentTitle()
local categories = ''
local makecat = true
if args["некат"] == '1' then
makecat = false
end
if title.namespace ~= 0 then
makecat = false
end
if title.isSubpage then
if title.subpageText ~= "крафт" then
makecat = false
end
else
if mw.title.new(title.fullText ..'/крафт').exists then
makecat = false
end
end
if makecat then
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
for _, dye in ipairs( dyes ) do
-- В оригіналі назва категорії має формат «Recipe using <предмет>». Прямо перекладається
-- ця конструкція як «Рецепт, який використовує <предмет>». При цьому назва предмета повинно
-- було бути в знахідному відмінку, але на даний момент швидко схиляти назви предметів
-- в називному відмінку за допомогою модулів не представляється можливим. Тому в якості
-- перекладу використовується близька за змістом конструкція, яка не потребує відміни.
table.insert( categories, '[[Категорія:' .. dye .. ' як інгредієнт для крафта]]' )
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
table.insert( categories, '[[Категорія:' .. v .. ' як інгредієнт для крафта]]' )
end
end
end
end
categories = table.concat( categories, '' )
end
return header .. '\n' .. row .. '\n|-\n' .. footer .. categories
end
return p