Bearbeiten von „Modul:GetRecipes“
Aus Eco - Deutsches Wiki
Deine Änderungen werden angezeigt, sobald ein dazu berechtigter Benutzer sie akzeptiert hat. (Hilfe)
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 1: | Zeile 1: | ||
local p = {} | 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 | |||
local | |||
end | end | ||
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 itemList = completeList.items | |||
local tableList = completeList.tables | |||
-- groups no longer exists. Need to check all dependencies on this throughout other modules. Expecting implication to be removal of 'used in' table in the wiki. | |||
--local groupList = completeList.groups | |||
-- initialize a table to store recipes | |||
local recipes = {} | |||
-- load CraftingParser | |||
local parser = require( "Module:CraftingParser" ) | |||
-- priority: item > table > group | |||
if item ~= nil then | |||
if itemList[item] == nil then | |||
-- | return '===Crafting Recipes===\n\'\'None\'\'\n===Used in Recipes (potentially deprecated due to removal of groups - clean this up)===\n\'\'None\'\'\n' | ||
end | end | ||
for num = 1, #itemList[item] do | |||
--nil entries in itemList are causing errors. Need to deal with exceptions where entry is '' | |||
if itemList[item][num] ~= '' then --skip blank entry in array. Applies to Bars (Iron Bars, Steel Bars, etc). | |||
if recipeList[itemList[item][num]] ~= nil then --skip missing recipes as those use variants | |||
recipes[num] = recipeList[itemList[item][num]] | |||
end | |||
end | |||
--Handle situations where itemList has a single, blank entry. Set value to item name provided by the calling page. Occurs for all tools. Could cause other issues for invalid item names. | |||
if #itemList[item] == 1 and itemList[item][num] == '' then | |||
recipes[num] = recipeList[item] | |||
end | |||
end | end | ||
return parser.formattedItem( recipes, item ) | |||
elseif table ~= nil then | |||
--GROUP deprecated | |||
--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 | |||
return parser.formattedTable( recipes, table ) | |||
--GROUP deprecated | |||
--elseif group ~= nil then | |||
--for num = 1, #groupList[group] do | |||
--recipes[num] = recipeList[groupList[group][num]] | |||
--end | |||
--return parser.formattedGroup( recipes, group ) | |||
else | |||
return 'Invalid use of parameters, please see [[Template:GetRecipes]].' | |||
end | end | ||
end | |||
return p | return p |