Module:Recipe

local animatedFiles = mw.loadData('Module:AnimatedFileList') local ProcessArgs = require('Module:ProcessArgs') local Util = require('Module:Util') local p = {} local hasBrokenFilelink = false

-- display specified recipe template inside a wikitable function p.recipeTable(frame) local args = ProcessArgs.norm(frame:getParent.args) local type = frame.args.type -- gets the 'type=' argument specified in the #invoke call itself if not type or type == '' then type = 'crafting' else type = type:lower end local inputArgsList = { 'input', 'a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3' }	local ingredients = {} local output = {} for _, argName in ipairs(inputArgsList) do		if args[argName] then if not ingredients[args[argName]] then ingredients[args[argName]] = 1 else ingredients[args[argName]] = ingredients[args[argName]] + 1 end end end --local recipeOutput = p[type](frame) local recipeOutput = frame:expandTemplate{title=type, args=args} if args.head then table.insert(output, '{| class = "wikitable"\n|-\n! Name !! Ingredients !! Recipe\n|-\n') end table.insert(output, '|-\n') table.insert(output, '| ' .. args.output .. ' || ') local ingredientsOutput = {} for item in pairs(ingredients) do table.insert(ingredientsOutput, ingredients[item] .. ' ' .. Util.stripInterwiki(item) .. '') end table.insert(output, table.concat(ingredientsOutput, ' + ')) table.insert(output, ' || ' .. recipeOutput .. '\n') if args.foot then table.insert(output, '\n|}') end return table.concat(output) end

-- display item in inventory slot local function invslot(args) -- all arguments (name, image, size, left, top) are stored in a table called "arg" local filelink = {} table.insert(filelink, '[[File:')	local linkname = args.name	local name = Util.stripInterwiki(args.name)	-- use image argument if specified; otherwise show default image based on name	local image	if args.image then		image = args.image	elseif animatedFiles[name] then		image = name .. '.gif'	else		image = name .. '.png'	end	table.insert(filelink, image)	-- only link if it's not to the current page	local currentPage = mw.title.getCurrentTitle	local link = '|link='	if not mw.title.equals(currentPage, mw.title.new(linkname, 0)) then		link = link .. linkname	end	table.insert(filelink, link)	local size = '|32x32px'	if args.size then		size = '|' .. args.size	end

table.insert(filelink, size) table.insert(filelink, '|' .. name .. ']]') local output = mw.html.create('div') output:wikitext(table.concat(filelink)) output:css({left=args.left, top=args.top, position='absolute'}) return tostring(output) end

-- display crafting grid interface function p.crafting(frame) local args = frame if frame == mw.getCurrentFrame then args = ProcessArgs.merge(true) else frame = mw.getCurrentFrame end local output = {} table.insert(output, ' ') table.insert(output, ' ') if args.a1 then table.insert(output, invslot({name=args.a1, left='10px', top='10px', image=args.a1image})) end if args.a2 then table.insert(output, invslot({name=args.a2, left='46px', top='10px', image=args.a2image})) end if args.a3 then table.insert(output, invslot({name=args.a3, left='82px', top='10px', image=args.a3image})) end if args.b1 then table.insert(output, invslot({name=args.b1, left='10px', top='46px', image=args.b1image})) end if args.b2 then table.insert(output, invslot({name=args.b2, left='46px', top='46px', image=args.b2image})) end if args.b3 then table.insert(output, invslot({name=args.b3, left='82px', top='46px', image=args.b3image})) end if args.c1 then table.insert(output, invslot({name=args.c1, left='10px', top='82px', image=args.c1image})) end if args.c2 then table.insert(output, invslot({name=args.c2, left='46px', top='82px', image=args.c2image})) end if args.c3 then table.insert(output, invslot({name=args.c3, left='82px', top='82px', image=args.c3image})) end if args.output then table.insert(output, invslot({name=args.output, left='198px', top='46px', image=args.outputimage})) end if args.amount then local amount = tonumber(args.amount) if amount then if amount > 9 then table.insert(output, invslot({name=args.output, left='208px', top='60px', image='Grid '.. math.floor(amount / 10) ..'.png', size='12px'})) end table.insert(output, invslot({name=args.output, left='220px', top='60px', image='Grid '.. (amount % 10) ..'.png', size='12px'})) end end if args.shapeless then local shapelessMsg = ' ' .. ''		.. ' '

table.insert(output, shapelessMsg) end if hasBrokenFilelink then table.insert(output, ' ') else table.insert(output, ' ') end return table.concat(output, '\n') end

return p