Module:Crafting

From Tensura Wiki
Jump to navigation Jump to search

Template:Documentation header This module implements {{crafting}}.

Parent arguments are automatically merged with directly passed arguments (the latter overwriting the former).

Dependencies

See also


cs:Modul:Crafting de:Modul:Herstellen es:Módulo:Fabricación fr:Module:Fabrication it:Modulo:Fabbricazione ja:モジュール:Crafting ko:모듈:Crafting lzh:模組:Crafting nl:Module:Vervaardiging pl:Moduł:Crafting pt:Módulo:Crafting ru:Модуль:Крафт th:มอดูล:Crafting uk:Модуль:Майстрування zh:Module:Crafting



-- This module was adapted from:
-- [https://minecraft.wiki/wiki/Module:Crafting] on the Minecraft Wiki.
-- Credit goes to the original authors.

local p = {}

local i18n = {
	moduleArgs = [[Module:ProcessArgs]],
	moduleRecipe = [[Module:Recipe table]],
	moduleSlot = [[Module:Inventory slot]],
	moduleAliases = [[Module:Inventory slot/Aliases]],
	type = 'Crafting'
}
p.i18n = i18n

local slot = require( i18n.moduleSlot )
local recipeTable = require( i18n.moduleRecipe ).table
local aliases = mw.loadData( i18n.moduleAliases )
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.shapeless = 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
				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.shapeless = 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
				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
				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
	local out = recipeTable( args, {
		uiFunc = 'craftingTable',
		type = i18n.type,
		ingredientArgs = cArgVals,
		outputArgs = { 'Output' },
	} )
	
	local title = mw.title.getCurrentTitle()
	if args.ignoreusage or args.nocat == '1' or title.namespace ~= 0 or title.isSubpage then
		return out
	end
	
	return out, "[[Category:Has crafting]]"
end

return p