Module:Cooking usage

local p = {} local cargo = mw.ext.cargo local title = mw.title.getCurrentTitle.text

p.argList = { '_pageName', 'product', 'productImage', 'cookedIn', 'ingredient1', 'ingredient2', 'value', 'otherEffect' }

--Sorts the crafting ingredients so the ingredient on the current page is always first. -- local function sortIngredients(recipe) if recipe.ingredient1 ~= title then recipe.ingredient2 = recipe.ingredient1 recipe.ingredient1 = title end return 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' tbl[i] = mw.getCurrentFrame:expandTemplate{title='Cooking table', args=recipe} end 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 .. '")', orderBy = 'cookedIn, value ASC' }

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

return createTable(recipes) end

return p