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 10: Line 10:
   -- get args from the Template
   -- get args from the Template
   local args = Utils.normaliseArgs(frame)
   local args = Utils.normaliseArgs(frame)
 
 
   return p.renderTable(args.item, args.tag, args.table, args.group)
   -- assign variables for item, table, and group
end
  local item = args.item
 
  local tag = args.tag
 
  local craftTable = args.table
function p.renderTable(item, tag, craftTable, group)
  local group = args.group
 
   -- load list of recipes
   -- load list of recipes
   local completeList = require("Module:CraftingRecipes")
   local completeList = require("Module:CraftingRecipes")
Line 31: Line 32:
   local parser = require("Module:CraftingParser")
   local parser = require("Module:CraftingParser")


   -- priority: item > tag > table > group
   -- priority: item > table > group
   if item ~= nil then
   if item ~= nil then
     local itemProducts
     local itemProducts
    -- HACK Attempt to handle issue with tool recipes


    -- HACK Attempt to handle issue with tool recipes
     if productsList[item] and #productsList[item] == 1 and productsList[item][1] == '' then
     if productsList[item] and #productsList[item] == 1 and productsList[item][1] == '' then
       itemProducts = {item}
       itemProducts = {item}
Line 43: Line 44:


     if itemProducts ~= nil then
     if itemProducts ~= nil then
       for _, itemProduct in pairs(itemProducts) do
      local built = 1
        -- HACK: Skill books don't show us as a product of research pages, only the skill name.
       for _, itemProduct in ipairs(itemProducts) do
         if string.sub(item, string.len(item) - 9) == 'Skill Book' then
         if (itemProduct ~= '' and recipeList[itemProduct] ~= nil) then
            if (itemProduct ~= '' and recipeList[itemProduct .. ' Skill Book'] ~= nil) then
          products[built] = recipeList[itemProduct]
                table.insert(products, recipeList[itemProduct .. ' Skill Book'])
          built = built + 1
            end
        elseif (itemProduct ~= '' and recipeList[itemProduct] ~= nil) then
            table.insert(products, recipeList[itemProduct])
         end
         end
       end
       end
Line 56: Line 54:


     local itemIngredients
     local itemIngredients
 
     if tag and (tag == 'true' or tag == true) then
    -- HACK Attempt to handle issue with tool recipes
       itemIngredients = {}  
     if ingredientsList[item] and #ingredientsList[item] == 1 and ingredientsList[item][1] == '' then
     
       itemIngredients = {item}
       -- Tags do not appear in the 'products' list, so have to process manually
    elseif ingredientsList[item] then
       for recipeName, recipe in pairs(recipeList) do
       itemIngredients = ingredientsList[item]
         local foundIngredient = false
    end
        for _, variant in pairs(recipe.variants) do
 
           for _, ingredient in pairs(variant.ingredients) do
    if itemIngredients ~= nil then
            if ingredient[1] == 'TAG' and ingredient[2] == item then
       for _, itemIngredient in pairs(itemIngredients) do
              foundIngredient = true
         if itemIngredient ~= '' then
            end
          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
      end
        if foundIngredient then
    end
          table.insert(itemIngredients, recipeName)
    return parser.formattedItem(products, ingredients, item)
 
  elseif tag ~= nil then
    itemIngredients = {}   
     
    -- Tags do not appear in the 'products' list, so have to process manually
    for recipeName, recipe in pairs(recipeList) do
      local foundIngredient = false
      for _, variant in pairs(recipe.variants) do
        for _, ingredient in pairs(variant.ingredients) do
          if ingredient[1] == 'TAG' and ingredient[2] == tag then
            foundIngredient = true
          end
         end
         end
       end
       end
       if foundIngredient then
    else
         table.insert(itemIngredients, recipeName)
       if ingredientsList[item] and #ingredientsList[item] == 1 and ingredientsList[item][1] == '' then
        itemIngredients = {item}
      elseif ingredientsList[item] then
         itemIngredients = ingredientsList[item]
       end
       end
     end
     end


     if itemIngredients ~= nil then
     if itemIngredients ~= nil then
       for _, itemIngredient in pairs(itemIngredients) do
       for _, itemIngredient in ipairs(itemIngredients) do
         if itemIngredient ~= '' then
         if itemIngredient ~= '' then
          if recipeList[itemIngredient] ~= nil then
        if recipeList[itemIngredient] ~= nil then
    table.insert(ingredients, recipeList[itemIngredient])
          table.insert(ingredients, recipeList[itemIngredient])
          end
        -- 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
       end
     end
     end
     return parser.formattedItem(products, ingredients, tag)
     mw.logObject(ingredients)
    --return parser.formattedItem(products, ingredients, item)
      
      
   elseif craftTable ~= nil then
   elseif craftTable ~= nil then
 
     for num = 1, #tableList[craftTable] do
     if tableList[craftTable] == nil then
       recipes[num] = recipeList[tableList[craftTable][num]]
        return 'This object is not a crafting table and cannot craft any objects.'
    end
 
    for _, tbl in pairs(tableList[craftTable]) do
       table.insert(recipes, recipeList[tbl])
     end
     end
      
      
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: