Minecraft Wiki
мНемає опису редагування
AttemptToCallNil (обговорення | внесок)
(trying to fix hyphenated prefixes)
Рядок 199: Рядок 199:
 
-- Remove prefixes
 
-- Remove prefixes
 
for _, prefix in pairs( slot.i18n.prefixes ) do
 
for _, prefix in pairs( slot.i18n.prefixes ) do
if name:find( '^' .. prefix .. ' ' ) then
+
if name:find( '^' .. slot.i18n.esc_prefix(prefix) .. ' ' ) then
name = name:gsub( '^' .. prefix .. ' ', '' )
+
name = name:gsub( '^' .. slot.i18n.esc_prefix(prefix) .. ' ', '' )
 
break
 
break
 
end
 
end

Версія за 17:25, 10 лютого 2020

[створити | історія | оновити]Документація
У цього модуля немає документації. Якщо ви знаєте, як використовувати цей модуль, будь ласка, додайте відповідну інформацію.
local p = {}

local i18n = {
	colored = 'кольорові',
	coloredDyes = {
		'Помаранчевий барвник', 'Пурпуровий барвник', 'Блакитний барвник', 'Жовтий барвник', 'Лаймовий барвник',
		'Рожевий барвник', 'Сірий барвник', 'Світло-сірий барвник', 'Бірюзовий барвник', 'Фіолетовий барвник',
		'Сіній барвник', 'Коричневий барвник', 'Зелений барвник', 'Червоний барвник', 'Чорний барвник'
	},
	categoryIngredientUsage = 'Категорія:$1 як інгредієнт для крафта',
	categoryRecipeType = 'Категорія:Рецепт «$1»',
	categoryUpcoming = 'Категорія:Заплановане',
	itemBlockOfQuartz = 'блок кварцу',
	itemBoneMeal = 'кісткове борошно',
	itemBrownMushroom = 'коричневий гриб',
	itemCharcoal = 'деревне вугілля',
	itemCoal = 'вугілля',
	itemColoredDye = 'кольоровий барвник',
	itemDye = 'барвник',
	itemMushroom = 'гриб',
	itemQuartzBlock = 'кварцовий блок',
	itemRedMushroom = 'червоний гриб',
	itemStone = 'камінь',
	moduleArgs = [[Модуль:ProcessArgs]],
	moduleRecipe = [[Модуль:Recipe table]],
	moduleSlot = [[Модуль:Інвентарний слот]],
	stoneVariants = { 'Камінь', 'Андезит', 'Граніт', 'Діорит' },
	type = 'Крафт',
	variantPages = {
		'Андезит', 'Стяг', 'Ліжко', 'Діорит', 'Зірка феєрверку', 'Граніт', 
		'Натискна плита', 'Пісок', 'Пісковик', 'Щит', 'Плита', 'Скляна панель', 
		'Скло', 'Сходи', "Кам'яна цегла", 'Дошки', 'Деревина', 'Вовна',
	},
}
p.i18n = i18n

local slot = require( i18n.moduleSlot )
local recipeTable = require( i18n.moduleRecipe ).table
local cArgVals = { 'A1', 'B1', 'C1', 'A2', 'B2', 'C2', 'A3', 'B3', 'C3' }
p.cArgVals = cArgVals

function p.table( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( i18n.moduleArgs ).merge( true )
	else
		f = mw.getCurrentFrame()
	end
	
	-- Automatic shapeless positioning
	if args[1] then
		args['безформний'] = 1
		if args[7] then
			args.A1 = args[1]
			args.B1 = args[2]
			args.C1 = args[3]
			args.A2 = args[4]
			args.B2 = args[5]
			args.C2 = args[6]
			if args[8] then
				-- ◼◼◼      ◼◼◼
				-- ◼◼◼  OR  ◼◼◼
				-- ◼◼◼      ◼◼◻
				args.A3 = args[7]
				args.B3 = args[8]
				args.C3 = args[9]
				if args[9] then
					local identical = true
					for i = 1, 8 do
						if args[i] ~= args[i + 1] then
							identical = false
							break
						end
					end
					if identical then
						args['безформний'] = nil
					end
				end
			else
				-- ◼◼◼
				-- ◼◼◼
				-- ◻◼◻
				args.B3 = args[7]
			end
		elseif args[2] then
			args.A2 = args[1]
			args.B2 = args[2]
			if args[5] then
				-- ◻◻◻      ◻◻◻
				-- ◼◼◼  OR  ◼◼◼
				-- ◼◼◼      ◼◼◻
				args.C2 = args[3]
				args.A3 = args[4]
				args.B3 = args[5]
				args.C3 = args[6]
			elseif args[4] then
				-- ◻◻◻
				-- ◼◼◻
				-- ◼◼◻
				args.A3 = args[3]
				args.B3 = args[4]
			else
				-- ◻◻◻      ◻◻◻
				-- ◼◼◻  OR  ◼◼◻
				-- ◻◼◻      ◻◻◻
				args.B3 = args[3]
			end
		else
			-- ◻◻◻
			-- ◻◼◻
			-- ◻◻◻
			args.B2 = args[1]
			args.shapeless = nil
		end
		
		for i = 1, 9 do
			args[i] = nil
		end
	end
	
	-- Create recipe table, and list of ingredients
	local out, ingredientSets = recipeTable( args, {
		uiFunc = 'craftingTable',
		type = i18n.type,
		ingredientArgs = cArgVals,
		outputArgs = { 'Вихід' },
	} )
	
	local title = mw.title.getCurrentTitle()
	if args['некат'] == '1' or title.namespace ~= 0 or title.isSubpage then
		return out
	end
	
	local categories = {}
	local cI = 1
	if args['заплановане'] then
		categories[cI] = '[[' .. i18n.categoryUpcoming .. ']]'
		cI = cI + 1
	end
	
	if args.type then
		categories[cI] = '[[' .. i18n.categoryRecipeType:gsub( '%$1', args['тип'] ) .. ']]'
		cI = cI + 1
	end
	
	if args['ігнорувати'] ~= '1' then
		-- Create ingredient categories for DPL
		local usedNames = {}
		for _, ingredientSet in pairs( ingredientSets ) do
			for _, ingredient in pairs( ingredientSet ) do
				local name = ingredient.name
				if not ingredient.mod and not usedNames[name] and name ~= title.text then
					-- List each dye individually as they have their own pages
					if
						name == slot.i18n.prefixes['Будь-який'] .. ' ' .. i18n.itemDye or
						name == slot.i18n.prefixes['Відповідний'] .. ' ' .. i18n.itemDye or
						name == slot.i18n.prefixes['Будь-який'] .. ' ' .. i18n.itemColoredDye or
						name == slot.i18n.prefixes['Відповідний'] .. ' ' .. i18n.itemColoredDye
					then
						if not name:find( i18n.colored ) then
							categories[cI] = '[[' .. i18n.categoryIngredientUsage:gsub( '%$1', i18n.itemBoneMeal ) .. ']]'
							cI = cI + 1
							usedNames[i18n.itemBoneMeal] = true
						end
						
						for _, dye in pairs( i18n.coloredDyes ) do
							categories[cI] = '[[' .. i18n.categoryIngredientUsage:gsub( '%$1', dye ) .. ']]'
							cI = cI + 1
							usedNames[dye] = true
						end
					-- List stone variants individually as they have their own pages
					elseif
						name == slot.i18n.prefixes['Будь-який'] .. ' ' .. i18n.itemStone or
						name == slot.i18n.prefixes['Відповідний'] .. ' ' .. i18n.itemStone
					then
						for _, stone in pairs( i18n.stoneVariants ) do
							categories[cI] = '[[' .. i18n.categoryIngredientUsage:gsub( '%$1', stone ) .. ']]'
							cI = cI + 1
							usedNames[stone] = true
						end
					else
						-- Merge item variants which use a single page
						if
							name == slot.i18n.prefixes['Будь-який'] .. ' ' .. i18n.itemMushroom or
							name == slot.i18n.prefixes['Відповідний'] .. ' ' .. i18n.itemMushroom or
							name == i18n.itemRedMushroom or
							name == i18n.itemBrownMushroom
						then name = i18n.itemMushroom
						elseif name == i18n.itemCharcoal then name = i18n.itemCoal
						elseif name:find( ' ' .. i18n.itemQuartzBlock .. '$' ) then name = i18n.itemBlockOfQuartz
						else
							for _, variant in pairs( i18n.variantPages ) do
								if name:find( ' ' .. variant .. '$' ) then
									name = variant
									break
								end
							end
							
							-- Remove prefixes
							for _, prefix in pairs( slot.i18n.prefixes ) do
								if name:find( '^' .. slot.i18n.esc_prefix(prefix) .. ' ' ) then
									name = name:gsub( '^' .. slot.i18n.esc_prefix(prefix) .. ' ', '' )
									break
								end
							end
						end
						
						if not usedNames[name] then
							categories[cI] = '[[' .. i18n.categoryIngredientUsage:gsub( '%$1', name ) .. ']]'
							cI = cI + 1
							usedNames[name] = true
						end
					end
				end
			end
		end
	end
	
	return out, table.concat( categories, '' )
end

return p