Module:RecipeUI

local p = {} local hasBrokenFilelink = false

-- if template argument is specified and not an empty string local function argSpecified(arg) return arg ~= nil and arg ~= '' end

-- display specified recipe template inside a wikitable function p.recipeTable(frame) local args = frame:getParent.args local type = frame.args.type -- this gets the 'type=' argument specified in the #invoke call itself if not argSpecified(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 argSpecified(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 argSpecified(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] .. ' ' .. item .. '') end table.insert(output, table.concat(ingredientsOutput, ' + ')) table.insert(output, ' || ' .. recipeOutput .. '\n') if argSpecified(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 = args.name	-- use image argument if specified; otherwise show default image based on name	local image	if argSpecified(args.image) then		image = args.image	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 argSpecified(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'}) output:addClass("invslot-item-image") return tostring(output) end

-- display crafting grid interface function p.crafting(frame) if not frame then frame = mw:getCurrentFrame end local args = frame:getParent.args local output = {} table.insert(output, ' ') table.insert(output, ' ') if argSpecified(args.a1) then table.insert(output, invslot({name=args.a1, left='10px', top='10px', image=args.a1image})) end if argSpecified(args.a2) then table.insert(output, invslot({name=args.a2, left='46px', top='10px', image=args.a2image})) end if argSpecified(args.a3) then table.insert(output, invslot({name=args.a3, left='82px', top='10px', image=args.a3image})) end if argSpecified(args.b1) then table.insert(output, invslot({name=args.b1, left='10px', top='46px', image=args.b1image})) end if argSpecified(args.b2) then table.insert(output, invslot({name=args.b2, left='46px', top='46px', image=args.b2image})) end if argSpecified(args.b3) then table.insert(output, invslot({name=args.b3, left='82px', top='46px', image=args.b3image})) end if argSpecified(args.c1) then table.insert(output, invslot({name=args.c1, left='10px', top='82px', image=args.c1image})) end if argSpecified(args.c2) then table.insert(output, invslot({name=args.c2, left='46px', top='82px', image=args.c2image})) end if argSpecified(args.c3) then table.insert(output, invslot({name=args.c3, left='82px', top='82px', image=args.c3image})) end if argSpecified(args.output) then table.insert(output, invslot({name=args.output, left='198px', top='46px', image=args.outputimage})) end if argSpecified(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 argSpecified(args.shapeless) then local shapelessMsg = ' ' .. ''		.. ' '

table.insert(output, shapelessMsg) end if hasBrokenFilelink then table.insert(output, ' ') else table.insert(output, ' ') end outputStr = table.concat(output, '\n') -- store the entire parsed template onto Cargo table if argSpecified(args.storecargo) then frame:callParserFunction{name="#cargo_store", args={'_table=CraftingRecipes', Output=args.output, Data=outputStr}} end frame:callParserFunction{name="#cargo_store:_table=CraftingRecipes", args={Output='Foo', Data='Foo2'}} return outputStr end

return p