Editing Module:GetRecipes

From Eco - English Wiki

Your changes will be displayed to readers once an authorized user accepts them. (help)

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

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:
-- Module:GetRecipes (https://wiki.play.eco/en/Module:GetRecipes)
local p = {}
local p = {}


local Utils = require('Module:Utils')


-- Main entry point for the Module
-- Grabs args from the parent frame
function p.main(frame)
-- Trims and parses the args into a table, then returns the table
  local test = ''
function norm()
 
    local origArgs = mw.getCurrentFrame():getParent().args
  -- get args from the Template
    local args = {}
  local args = Utils.normaliseArgs(frame)
   
 
    for k, v in pairs( origArgs ) do
  return p.renderTable(args.item, args.tag, args.table, args.group)
        v = mw.text.trim( tostring( v ) )
        if v ~= '' then
            args[k] = v
        end
    end
   
    return args
end
end




function p.renderTable(item, tag, craftTable, group)
-- Main entry point for the Module
  -- load list of recipes
function p.main()
  local completeList = require("Module:CraftingRecipes")
    -- get args from the Template
  local recipeList = completeList.recipes
    local args = norm()
  local ingredientsList = completeList.ingredients
   
  local productsList = completeList.products
    -- assign variables for item, table, and group
  local tableList = completeList.tables
    local item = args.item
 
    local table = args.table
  -- initialize a table to store recipes
    local group = args.group
  local recipes = {}
  local products = {}
  local ingredients = {}
 
  -- load CraftingParser
  local parser = require("Module:CraftingParser")


  -- priority: item > tag > table > group
    -- load list of recipes
  if item ~= nil then
    local completeList = require( "Module:TestCraftingRecipes" )
     local itemProducts
    local recipeList = completeList.recipes
 
    local itemList = completeList.items
     -- HACK Attempt to handle issue with tool recipes
    local tableList = completeList.tables
     if productsList[item] and #productsList[item] == 1 and productsList[item][1] == '' then
     local groupList = completeList.groups
      itemProducts = {item}
   
     elseif productsList[item] then
     -- initialize a table to store recipes
      itemProducts = productsList[item]
     local recipes = {}
     end
      
 
    -- load CraftingParser
     if itemProducts ~= nil then
    local parser = require( "Module:TestCraftingParser" )
      for _, itemProduct in pairs(itemProducts) do
      
        -- HACK: Skill books don't show us as a product of research pages, only the skill name.
    -- priority: item > table > group
         if string.sub(item, string.len(item) - 9) == 'Skill Book' then
     if item ~= nil then
             if (itemProduct ~= '' and recipeList[itemProduct .. ' Skill Book'] ~= nil) then
         if itemList[item] == nil then
                table.insert(products, recipeList[itemProduct .. ' Skill Book'])
             return '===Crafting Recipes===\n\'\'None\'\'\n===Used in Recipes===\n\'\'None\'\'\n'
            end
        elseif (itemProduct ~= '' and recipeList[itemProduct] ~= nil) then
            table.insert(products, recipeList[itemProduct])
         end
         end
      end
        for num = 1, #itemList[item] do
    end
            recipes[num] = recipeList[itemList[item][num]]
 
    local itemIngredients
 
    -- 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
 
    if itemIngredients ~= nil then
      for _, itemIngredient in pairs(itemIngredients) do
        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
        return parser.formattedItem( recipes, item )
    end
    elseif table ~= nil then
    return parser.formattedItem(products, ingredients, item)
        if group ~= nil then
 
            local count = 1
  elseif tag ~= nil then
            for num = 1, #tableList[table] do
    itemIngredients = {}   
                for gnum = 1, #groupList[group] do
     
                    if tableList[table][num] == groupList[group][gnum] then
    -- Tags do not appear in the 'products' list, so have to process manually
                        recipes[count] = recipeList[tableList[table][num]]
    for recipeName, recipe in pairs(recipeList) do
                        count = count + 1
      local foundIngredient = false
                    end
      for _, variant in pairs(recipe.variants) do
                end
        for _, ingredient in pairs(variant.ingredients) do
            end
          if ingredient[1] == 'TAG' and ingredient[2] == tag then
        else
            foundIngredient = true
            for num = 1, #tableList[table] do
          end
                recipes[num] = recipeList[tableList[table][num]]
            end
         end
         end
      end
         return parser.formattedTable( recipes, table )
      if foundIngredient then
     elseif group ~= nil then
         table.insert(itemIngredients, recipeName)
        for num = 1, #groupList[group] do
      end
            recipes[num] = recipeList[groupList[group][num]]
    end
 
     if itemIngredients ~= nil then
      for _, itemIngredient in pairs(itemIngredients) do
        if itemIngredient ~= '' then
          if recipeList[itemIngredient] ~= nil then
    table.insert(ingredients, recipeList[itemIngredient])
          end
         end
         end
      end
        return parser.formattedGroup( recipes, group )
    end
     else
    return parser.formattedItem(products, ingredients, tag)
         return 'Invalid use of parameters, please see [[Template:GetRecipes]].'
      
  elseif craftTable ~= nil then
 
    if tableList[craftTable] == nil then
         return 'This object is not a crafting table and cannot craft any objects.'
     end
     end
end


    for _, tbl in pairs(tableList[craftTable]) do
      table.insert(recipes, recipeList[tbl])
    end
   
    return parser.formattedTable(recipes, craftTable)
   
  else
    return 'Invalid use of parameters, please see [[Template:GetRecipes]].'
  end
end


return p
return p
Please note that all contributions to Eco - English Wiki are considered to be released under the CC BY-NC-SA 4.0 (see Eco:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following hCaptcha:

Cancel Editing help (opens in new window)

Template used on this page: