ATTENTION! The process of updating WiKi to version Eco 10.x has begun. Those wishing to participate can find out more Information on our ECO Contribution Wiki Discord.

Module:GetRecipes: Difference between revisions

From Eco - English Wiki
[checked revision][unchecked revision]
(HACK: Until Skill Books/Research Pages work correctly)
(HACK: Handle issue with Tools data)
Line 34: Line 34:
   if item ~= nil then
   if item ~= nil then
     if productsList[item] ~= nil then
     if productsList[item] ~= nil then
      -- HACK Attempt to handle issue with tool recipes
      if #productsList[item] == 1 and productsList[item][1] == '' then
        productsList[item] = {item}
      end
       local built = 1
       local built = 1
       for _, itemProduct in ipairs(productsList[item]) do
       for _, itemProduct in ipairs(productsList[item]) do
Line 44: Line 48:


     if ingredientsList[item] ~= nil then
     if ingredientsList[item] ~= nil then
      -- HACK Attempt to handle issue with tool recipes
      if #ingredientsList[item] == 1 and ingredientsList[item][1] == '' then
        ingredientsList[item] = {item}
      end
       local built = 1
       local built = 1
       for _, itemIngredient in ipairs(ingredientsList[item]) do
       for _, itemIngredient in ipairs(ingredientsList[item]) do

Revision as of 13:53, 27 February 2021

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:CraftingRecipes 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:


-- Module:GetRecipes (https://wiki.play.eco/en/Module:GetRecipes)
local p = {}

local Utils = require('Module:Utils')

-- Main entry point for the Module
function p.main(frame)
  local test = ''

  -- get args from the Template
  local args = Utils.normaliseArgs(frame)
  
  -- 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
      -- HACK Attempt to handle issue with tool recipes
      if #productsList[item] == 1 and productsList[item][1] == '' then
        productsList[item] = {item}
      end
      local built = 1
      for _, itemProduct in ipairs(productsList[item]) do
        if (itemProduct ~= '' and recipeList[itemProduct] ~= nil) then
          products[built] = recipeList[itemProduct]
          built = built + 1
        end
      end
    end

    if ingredientsList[item] ~= nil then
      -- HACK Attempt to handle issue with tool recipes
      if #ingredientsList[item] == 1 and ingredientsList[item][1] == '' then
        ingredientsList[item] = {item}
      end
      local built = 1
      for _, itemIngredient in ipairs(ingredientsList[item]) do
        if itemIngredient ~= '' then
        	if recipeList[itemIngredient] ~= nil then
	          ingredients[built] = recipeList[itemIngredient]
	          built = built + 1
	        -- HACK: Skill books don't show us as a product of research pages, only the skill name.
	        elseif recipeList[itemIngredient .. ' Skill Book'] ~= nil then
	        	ingredients[built] = recipeList[itemIngredient .. ' Skill Book']
	          built = built + 1
	        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

return p