Module:GetRecipes: Difference between revisions

From Eco - English Wiki
[unchecked revision][unchecked revision]
No edit summary
Drgooo (talk | contribs)
Commented out code relating to use of 'group' - as no longer supported in v0.9 data file.
Line 34: Line 34:
     local itemList = completeList.items
     local itemList = completeList.items
     local tableList = completeList.tables
     local tableList = completeList.tables
     local groupList = completeList.groups
      
    -- 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
     -- initialize a table to store recipes
Line 45: Line 47:
     if item ~= nil then
     if item ~= nil then
         if itemList[item] == nil then
         if itemList[item] == nil then
             return '===Crafting Recipes===\n\'\'None\'\'\n===Used in Recipes===\n\'\'None\'\'\n'
             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
         for num = 1, #itemList[item] do
Line 52: Line 54:
         return parser.formattedItem( recipes, item )
         return parser.formattedItem( recipes, item )
     elseif table ~= nil then
     elseif table ~= nil then
         if group ~= nil then
--GROUP deprecated
             local count = 1
         --if group ~= nil then
             for num = 1, #tableList[table] do
             --local count = 1
                 for gnum = 1, #groupList[group] do
             --for num = 1, #tableList[table] do
                     if tableList[table][num] == groupList[group][gnum] then
                 --for gnum = 1, #groupList[group] do
                         recipes[count] = recipeList[tableList[table][num]]
                     --if tableList[table][num] == groupList[group][gnum] then
                         count = count + 1
                         --recipes[count] = recipeList[tableList[table][num]]
                     end
                         --count = count + 1
                 end
                     --end
             end
                 --end
         else
             --end
         --else
             for num = 1, #tableList[table] do
             for num = 1, #tableList[table] do
                 recipes[num] = recipeList[tableList[table][num]]
                 recipes[num] = recipeList[tableList[table][num]]
             end
             end
         end
         --end
         return parser.formattedTable( recipes, table )
         return parser.formattedTable( recipes, table )
     elseif group ~= nil then
     --GROUP deprecated
         for num = 1, #groupList[group] do
    --elseif group ~= nil then
             recipes[num] = recipeList[groupList[group][num]]
         --for num = 1, #groupList[group] do
         end
             --recipes[num] = recipeList[groupList[group][num]]
         return parser.formattedGroup( recipes, group )
         --end
         --return parser.formattedGroup( recipes, group )
     else
     else
         return 'Invalid use of parameters, please see [[Template:TestGetRecipes]].'
         return 'Invalid use of parameters, please see [[Template:TestGetRecipes]].'

Revision as of 09:48, 18 August 2020

Documentation

This module is called by Template:GetRecipes, and is the entry point for modules in the system that displays crafting recipes. It takes the item passed to the template, and uses Module:RecipeData to get every recipe related to the item. The resulting list of recipes is then passed to Module:CraftingParser, and the results from CraftingParser are returned to the template.

If the template is passed, this module creates a table using details from the following Modules:


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:TestCraftingRecipes" )
    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:TestCraftingParser" )
    
    -- 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
        for num = 1, #itemList[item] do
            recipes[num] = recipeList[itemList[item][num]]
        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:TestGetRecipes]].'
    end
end


return p