Module:Item usage

local p = {} local processArgs = require('Module:ArgsUtil')

local argTbl = processArgs.merge(mw.getCurrentFrame) local cargo = mw.ext.cargo local title = mw.title.getCurrentTitle.text

p.argList = { '_pageName', 'productCount', 'source', 'value', 'product', 'craftedIn', 'ingredient1', 'quantity1', 'ingredient2', 'quantity2', 'ingredient3', 'quantity3' }

--Sorts the crafting ingredients so the ingredient on the current page is always first -- local function sortIngredients(recipe) for i = 0, 3, 1 do local ingredientString = 'ingredient' .. tostring(i) local quantityString = 'quantity' .. tostring(i) if recipe[ingredientString] == title then local tempIngredient = recipe.ingredient1 local tempQuantity = recipe.quantity1 recipe.ingredient1 = recipe[ingredientString] recipe.quantity1 = recipe[quantityString] recipe[ingredientString] = tempIngredient recipe[quantityString] = tempQuantity return end end end --Creates recipe table for given recipes -- local function createTable(recipes) local tbl = {} for i, recipe in ipairs(recipes) do		sortIngredients(recipe) if i == #recipes then recipe.tableEnd = 1 end recipe.structure = 'hidden' recipe.collapsible = argTbl.collapsible tbl[i] = mw.getCurrentFrame:expandTemplate{title='Crafting table', args=recipe} end local returnString = table.concat(tbl) if returnString == '' then returnString = '' end return returnString end

p.table = function(frame) local fields = table.concat(p.argList, ',')

local languageCheck = '' if string.match(mw.title.getCurrentTitle:fullUrl, "littlewood.gamepedia") then local pageContent = mw.title.getCurrentTitle:getContent local languageCategory = string.match(pageContent, "%[%[Category:([%w%s%-]-) -translation%]%]") if languageCategory == nil then languageCategory = "" end if mw.language.isKnownLanguageTag(string.lower(languageCategory)) then languageCheck = '(_pageName like "%/' .. string.lower(languageCategory) .. '" OR _pageName not like "%/%") AND ' if mw.title.getCurrentTitle.isSubpage and mw.language.isKnownLanguageTag(mw.title.getCurrentTitle.subpageText) then title = string.match(pageContent, "{{Infobox .-= ?(.-)\n") end else languageCheck = '_pageName not like "%/%" AND ' end end

local args = { where = languageCheck .. 'product IS NOT NULL AND (ingredient1="' .. title .. '" OR ingredient2="' .. title .. '" OR ingredient3="' .. title .. '")', orderBy = 'craftedIn, source, product ASC' }

local recipes = cargo.query('crafting_recipes', fields, args)

return createTable(recipes) end

return p