Editing Module:GetRecipes
From Eco - English Wiki
Your changes will be displayed to readers once an authorized user accepts them. (help)
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 10: | Line 10: | ||
-- get args from the Template | -- get args from the Template | ||
local args = Utils.normaliseArgs(frame) | local args = Utils.normaliseArgs(frame) | ||
-- assign variables for item, table, and group | |||
local item = args.item | |||
local tag = args.tag | |||
local craftTable = args.table | |||
local group = args.group | |||
-- load list of recipes | -- load list of recipes | ||
local completeList = require("Module:CraftingRecipes") | local completeList = require("Module:CraftingRecipes") | ||
Line 31: | Line 32: | ||
local parser = require("Module:CraftingParser") | local parser = require("Module:CraftingParser") | ||
-- priority: item | -- priority: item > table > group | ||
if item ~= nil then | if item ~= nil then | ||
local itemProducts | local itemProducts | ||
Line 44: | Line 45: | ||
if itemProducts ~= nil then | if itemProducts ~= nil then | ||
for _, itemProduct in pairs(itemProducts) do | for _, itemProduct in pairs(itemProducts) do | ||
if (itemProduct ~= '' and recipeList[itemProduct] ~= nil) then | |||
if | table.insert(products, recipeList[itemProduct]) | ||
end | end | ||
end | end | ||
Line 56: | Line 52: | ||
local itemIngredients | local itemIngredients | ||
if tag and (tag == 'true' or tag == true) then | |||
itemIngredients = {} | |||
if | |||
itemIngredients = { | -- Tags do not appear in the 'products' list, so have to process manually | ||
for recipeName, recipe in pairs(recipeList) do | |||
local foundIngredient = false | |||
for _, variant in pairs(recipe.variants) do | |||
for _, ingredient in pairs(variant.ingredients) do | |||
if ingredient[1] == 'TAG' and ingredient[2] == item then | |||
for | foundIngredient = true | ||
end | |||
end | end | ||
end | end | ||
if foundIngredient then | |||
table.insert(itemIngredients, recipeName) | |||
end | end | ||
end | end | ||
if | else | ||
-- HACK Attempt to handle issue with tool recipes | |||
if ingredientsList[item] and #ingredientsList[item] == 1 and ingredientsList[item][1] == '' then | |||
itemIngredients = {item} | |||
elseif ingredientsList[item] then | |||
itemIngredients = ingredientsList[item] | |||
end | end | ||
end | end | ||
if itemIngredients ~= nil then | if itemIngredients ~= nil then | ||
for _, itemIngredient in | for _, itemIngredient in ipairs(itemIngredients) do | ||
if itemIngredient ~= '' then | if itemIngredient ~= '' then | ||
if recipeList[itemIngredient] ~= nil then | |||
table.insert(ingredients, recipeList[itemIngredient]) | |||
-- HACK: Skill books don't show us as a product of research pages, only the skill name. | |||
elseif recipeList[itemIngredient .. ' Skill Book'] ~= nil then | |||
table.insert(ingredients, recipeList[itemIngredient .. ' Skill Book']) | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
return parser.formattedItem(products, ingredients, | mw.logObject(ingredients) | ||
return parser.formattedItem(products, ingredients, item) | |||
elseif craftTable ~= nil then | elseif craftTable ~= nil then | ||
for num = 1, #tableList[craftTable] do | |||
recipes[num] = recipeList[tableList[craftTable][num]] | |||
end | end | ||