Module:RecipeTable: Difference between revisions
From Eco - English Wiki
[unchecked revision] | [unchecked revision] |
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
-- Module: | -- Module:GetRecipes (https://wiki.play.eco/en/Module:GetRecipes) | ||
local p = {} | local p = {} | ||
-- | -- Grabs args from the parent frame | ||
function | -- Trims and parses the args into a table, then returns the table | ||
local | 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 | end | ||
return args | |||
end | end | ||
function | -- Main entry point for the Module | ||
local | 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 | local completeList = require( "Module:CraftingRecipes" ) | ||
local recipeList = completeList.recipes | |||
local ingredientsList = completeList.ingredients | |||
local productsList = completeList.products | |||
local tableList = completeList.tables | |||
-- initialize a table to store recipes | |||
local recipes = {} | |||
-- | local products = {} | ||
local ingredients = {} | |||
local | |||
-- load CraftingParser | |||
local parser = require( "Module:CraftingParser" ) | |||
-- | -- priority: item > table > group | ||
if item ~= nil then | |||
if productsList[item] ~= nil then | |||
for num = 1, #productsList do | |||
if (productsList[item][num] ~= '' and recipeList[productsList[item][num]] ~= nil) then | |||
products[num] = recipeList[productsList[item][num]] | |||
end | |||
end | |||
end | end | ||
if ingredientsList[item] ~= nil then | |||
for num = 1, #ingredientsList do | |||
if (ingredientsList[item][num] ~= '' and recipeList[ingredientsList[item][num]] ~= nil) then | |||
ingredients[num] = recipeList[ingredientsList[item][num]] | |||
end | |||
end | end | ||
end | end | ||
return parser.formattedItem( products, ingredients, item ) | |||
--elseif table ~= nil then | |||
--for num = 1, #tableList[table] do | |||
--recipes[num] = recipeList[tableList[table][num]] | |||
--end | |||
--return parser.formattedTable( recipes, table ) | |||
else | |||
return 'Invalid use of parameters, please see [[Template:GetRecipes]].' | |||
end | |||
end | end | ||
return p | return p |
Revision as of 07:12, 31 January 2021
Documentation
This module is a part of the Template:GetRecipes, and is used to generate a wikitable of recipes. It returns a wikitable as a string. The wikitable contains all of the recipes that were passed into the module.
If the template is passed, this module is used with the following Modules:
-- Module:GetRecipes (https://wiki.play.eco/en/Module:GetRecipes)
local p = {}
-- Grabs args from the parent frame
-- 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
-- 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:CraftingRecipes" )
local recipeList = completeList.recipes
local ingredientsList = completeList.ingredients
local productsList = completeList.products
local tableList = completeList.tables
-- initialize a table to store recipes
local recipes = {}
local products = {}
local ingredients = {}
-- load CraftingParser
local parser = require( "Module:CraftingParser" )
-- priority: item > table > group
if item ~= nil then
if productsList[item] ~= nil then
for num = 1, #productsList do
if (productsList[item][num] ~= '' and recipeList[productsList[item][num]] ~= nil) then
products[num] = recipeList[productsList[item][num]]
end
end
end
if ingredientsList[item] ~= nil then
for num = 1, #ingredientsList do
if (ingredientsList[item][num] ~= '' and recipeList[ingredientsList[item][num]] ~= nil) then
ingredients[num] = recipeList[ingredientsList[item][num]]
end
end
end
return parser.formattedItem( products, ingredients, item )
--elseif table ~= nil then
--for num = 1, #tableList[table] do
--recipes[num] = recipeList[tableList[table][num]]
--end
--return parser.formattedTable( recipes, table )
else
return 'Invalid use of parameters, please see [[Template:GetRecipes]].'
end
end
return p