Файл:Imbox deletion.png Внимание! Начат процесс обновления Wiki до версии игры 10.x. Если у Вас есть желание принять участие, то Вы можете найти больше информации в нашем ECO Contribution Wiki Discord.

Модуль:GetRecipes: различия между версиями

Материал из Eco - Русская Wiki
Перейти к:навигация, поиск
[досмотренная версия][досмотренная версия]
Нет описания правки
Match EN Version
 
(не показаны 2 промежуточные версии 2 участников)
Строка 2: Строка 2:
local p = {}
local p = {}


-- Grabs args from the parent frame
local Utils = require('Module:Utils')
-- Trims and parses the args into a table, then returns the table
 
function norm()
-- Main entry point for the Module
    local origArgs = mw.getCurrentFrame():getParent().args
function p.main(frame)
     local args = {}
  local test = ''
      
 
     for k, v in pairs( origArgs ) do
  -- get args from the Template
         v = mw.text.trim( tostring( v ) )
  local args = Utils.normaliseArgs(frame)
         if v ~= '' then
 
             args[k] = v
  -- assign variables for item, table, and group
  local item = args.item
  local tag = args.tag
  local craftTable = args.table -- Don't override 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 > tag > table > group
  if item ~= nil then
     local itemProducts
 
    -- HACK Attempt to handle issue with tool recipes
    if productsList[item] and #productsList[item] == 1 and productsList[item][1] == '' then
      itemProducts = {item}
     elseif productsList[item] then
      itemProducts = productsList[item]
     end
 
    if itemProducts ~= nil then
      for _, itemProduct in pairs(itemProducts) do
        -- HACK: Skill books don't show us as a product of research pages, only the skill name.
         if string.sub(item, string.len(item) - 9) == 'Skill Book' then
            if (itemProduct ~= '' and recipeList[itemProduct .. ' Skill Book'] ~= nil) then
                table.insert(products, recipeList[itemProduct .. ' Skill Book'])
            end
         elseif (itemProduct ~= '' and recipeList[itemProduct] ~= nil) then
             table.insert(products, recipeList[itemProduct])
         end
         end
      end
    end
    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
     end
   
    return args
end


-- Main entry point for the Module
    if itemIngredients ~= nil then
function p.main()
      for _, itemIngredient in pairs(itemIngredients) do
    local test = ''
        if itemIngredient ~= '' then
          if recipeList[itemIngredient] ~= nil then
-- get args from the Template
            table.insert(ingredients, recipeList[itemIngredient])
    local args = norm()
          -- HACK: Skill books don't show us as a product of research pages, only the skill name.
   
          elseif recipeList[itemIngredient .. ' Skill Book'] ~= nil then
    -- assign variables for item, table, and group
            table.insert(ingredients, recipeList[itemIngredient .. ' Skill Book'])
    local item = args.item
          end
     local table = args.table
        end
     local group = args.group
      end
     end
     return parser.formattedItem(products, ingredients, item)


    -- load list of recipes
  elseif tag ~= nil then
    local completeList = require( "Module:CraftingRecipes" )
     itemIngredients = {}  
    local recipeList = completeList.recipes
     
     local ingredientsList = completeList.ingredients
     -- Tags do not appear in the 'products' list, so have to process manually
local productsList = completeList.products
     for recipeName, recipe in pairs(recipeList) do
    local tableList = completeList.tables
      local foundIngredient = false
   
      for _, variant in pairs(recipe.variants) do
    -- initialize a table to store recipes
        for _, ingredient in pairs(variant.ingredients) do
    local recipes = {}
          if ingredient[1] == 'TAG' and ingredient[2] == tag then
local products = {}
            foundIngredient = true
local ingredients = {}
          end
   
     -- load CraftingParser
     local parser = require( "Module:CraftingParser" )
    -- priority: item > table > group
    if item ~= nil then
if productsList[item] ~= nil then
for num = 1, #productsList[item] do
if (productsList[item][num] ~= '' and recipeList[productsList[item][num]] ~= nil) then
products[num] = recipeList[productsList[item][num]]
end
end
end
if ingredientsList[item] ~= nil then
for num = 1, #ingredientsList[item] do
if (ingredientsList[item][num] ~= '' and recipeList[ingredientsList[item][num]] ~= nil) then
ingredients[num] = recipeList[ingredientsList[item][num]]
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
         end
      end
      if foundIngredient then
        table.insert(itemIngredients, recipeName)
      end
    end


         return parser.formattedTable( recipes, table )
    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.formattedItem(products, ingredients, tag)
   
  elseif craftTable ~= nil then


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


return p
return p

Текущая версия от 05:25, 23 августа 2021

Documentation[править код]

This module is called by Шаблон: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 Модуль:CraftingRecipes to get every recipe related to the item. The resulting list of recipes is then passed to Модуль: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 tag = args.tag
  local craftTable = args.table -- Don't override 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 > tag > table > group
  if item ~= nil then
    local itemProducts

    -- HACK Attempt to handle issue with tool recipes
    if productsList[item] and #productsList[item] == 1 and productsList[item][1] == '' then
      itemProducts = {item}
    elseif productsList[item] then
      itemProducts = productsList[item]
    end

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

    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(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
      if foundIngredient then
        table.insert(itemIngredients, recipeName)
      end
    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.formattedItem(products, ingredients, tag)
    
  elseif craftTable ~= nil then

    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