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 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- | -- Grabs args from the parent frame | ||
function | -- Trims and parses the args into a table, then returns the table | ||
function norm() | |||
local origArgs = mw.getCurrentFrame():getParent().args | |||
local args = {} | |||
for k, v in pairs( origArgs ) do | |||
v = mw.text.trim( tostring( v ) ) | |||
if v ~= '' then | |||
args[k] = v | |||
end | |||
end | |||
return args | |||
end | end | ||
function p. | -- Main entry point for the Module | ||
function p.main() | |||
-- get args from the Template | |||
local args = norm() | |||
-- assign variables for item, table, and group | |||
local item = args.item | |||
local table = args.table | |||
local group = args.group | |||
-- load list of recipes | |||
local completeList = require( "Module:TestCraftingRecipes" ) | |||
local | local recipeList = completeList.recipes | ||
local itemList = completeList.items | |||
-- | local tableList = completeList.tables | ||
local groupList = completeList.groups | |||
-- initialize a table to store recipes | |||
local recipes = {} | |||
-- load CraftingParser | |||
if | local parser = require( "Module:TestCraftingParser" ) | ||
-- priority: item > table > group | |||
if | if item ~= nil then | ||
if itemList[item] == nil then | |||
return '===Crafting Recipes===\n\'\'None\'\'\n===Used in Recipes===\n\'\'None\'\'\n' | |||
end | end | ||
for num = 1, #itemList[item] do | |||
recipes[num] = recipeList[itemList[item][num]] | |||
end | end | ||
return parser.formattedItem( recipes, item ) | |||
elseif table ~= nil then | |||
if group ~= nil then | |||
local count = 1 | |||
for num = 1, #tableList[table] do | |||
for gnum = 1, #groupList[group] do | |||
if tableList[table][num] == groupList[group][gnum] then | |||
recipes[count] = recipeList[tableList[table][num]] | |||
count = count + 1 | |||
end | |||
end | |||
end | |||
else | |||
for num = 1, #tableList[table] do | |||
recipes[num] = recipeList[tableList[table][num]] | |||
end | |||
end | end | ||
return parser.formattedTable( recipes, table ) | |||
elseif group ~= nil then | |||
for num = 1, #groupList[group] do | |||
recipes[num] = recipeList[groupList[group][num]] | |||
end | end | ||
return parser.formattedGroup( recipes, group ) | |||
else | |||
return 'Invalid use of parameters, please see [[Template:TestGetRecipes]].' | |||
return ' | |||
end | end | ||
end | |||
return p | return p |