Module:RecipeUsage

local p = {} local cargo = mw.ext.cargo

p.types = { crafting = { tableName = 'crafting_recipes', argList = { 'product_count', 'product_name', 'base_energy', 'base_time', 'ingredient1_name', 'ingredient1_count', 'ingredient2_name', 'ingredient2_count', 'ingredient3_name', 'ingredient3_count', 'ingredient4_name', 'ingredient4_count' },   cargoArgs = function(ingredient) return { where = 'ingredient1_name="' .. ingredient .. '" OR ingredient2_name="' .. ingredient .. '" OR ingredient3_name="' .. ingredient .. '" OR ingredient4_name="' .. ingredient .. '"', orderBy = 'product_name ASC' }   end, template = 'CraftingTable' }, smelting = { tableName = 'smelting_recipes', argList = { 'product_count', 'product_name', 'base_energy', 'base_time', 'ingredient1_name', 'ingredient1_count' },   cargoArgs = function(ingredient) return { where = 'ingredient1_name="' .. ingredient .. '"', orderBy = 'product_name ASC' }   end, template = 'SmeltingTable' } }

--Creates recipe table for given recipes -- function createTable(recipes, template) local table = "" for i=1,#recipes do   if i == #recipes then recipes[i].foot = 1 end recipes[i].structure = 'hidden' table = table .. mw.getCurrentFrame:expandTemplate{title=template, args=recipes[i]} end return table end

p.table = function(frame) local ingredient = mw.title.getCurrentTitle.text

local type = frame.args.type

local tableName = p.types[type].tableName local fields = table.concat(p.types[type].argList, ',') local args = p.types[type].cargoArgs(ingredient)

local recipes = cargo.query(tableName, fields, args)

return createTable(recipes, p.types[type].template) end

return p