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

Редактирование: Модуль:GetRecipes

Материал из Eco - Русская Wiki
Перейти к:навигация, поиск

Сделанные вами изменения будут показаны читателям после того, как их утвердит уполномоченный участник (подробнее).

Внимание: Вы не вошли в систему. Ваш IP-адрес будет общедоступен, если вы запишете какие-либо изменения. Если вы войдёте или создадите учётную запись, её имя будет использоваться вместо IP-адреса, наряду с другими преимуществами.

Правка может быть отменена. Пожалуйста, просмотрите сравнение версий ниже, чтобы убедиться, что это нужная вам правка, и запишите страницу ниже, чтобы отменить правку.

Текущая версия Ваш текст
Строка 1: Строка 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
  -- assign variables for item, table, and group
        v = mw.text.trim( tostring( v ) )
  local item = args.item
        if v ~= '' then
  local tag = args.tag
             args[k] = v
  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
     end
   
    return args
end


    local itemIngredients


     -- HACK Attempt to handle issue with tool recipes
-- Main entry point for the Module
     if ingredientsList[item] and #ingredientsList[item] == 1 and ingredientsList[item][1] == '' then
function p.main()
      itemIngredients = {item}
     -- get args from the Template
     elseif ingredientsList[item] then
    local args = norm()
      itemIngredients = ingredientsList[item]
   
    end
     -- assign variables for item, table, and group
    local item = args.item
    local table = args.table
     local group = args.group


     if itemIngredients ~= nil then
     -- load list of recipes
      for _, itemIngredient in pairs(itemIngredients) do
    local completeList = require( "Module:CraftingRecipes" )
        if itemIngredient ~= '' then
    local recipeList = completeList.recipes
          if recipeList[itemIngredient] ~= nil then
    local itemList = completeList.items
            table.insert(ingredients, recipeList[itemIngredient])
    local tableList = completeList.tables
          -- HACK: Skill books don't show us as a product of research pages, only the skill name.
   
          elseif recipeList[itemIngredient .. ' Skill Book'] ~= nil then
    -- 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.
            table.insert(ingredients, recipeList[itemIngredient .. ' Skill Book'])
    --local groupList = completeList.groups
          end
   
        end
    -- initialize a table to store recipes
      end
    local recipes = {}
     end
   
     return parser.formattedItem(products, ingredients, item)
     -- load CraftingParser
     local parser = require( "Module:CraftingParser" )


  elseif tag ~= nil then
     -- priority: item > table > group
    itemIngredients = {}   
     if item ~= nil then
     
         if itemList[item] == nil then
     -- Tags do not appear in the 'products' list, so have to process manually
            return '===Crafting Recipes===\n\'\'None\'\'\n===Used in Recipes (potentially deprecated due to removal of groups - clean this up)===\n\'\'None\'\'\n'
     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
        for num = 1, #itemList[item] do
      if foundIngredient then
            --nil entries in itemList are causing errors. Need to deal with exceptions where entry is ''
        table.insert(itemIngredients, recipeName)
            if itemList[item][num] ~= '' then --skip blank entry in array. Applies to Bars (Iron Bars, Steel Bars, etc).
      end
            recipes[num] = recipeList[itemList[item][num]]
    end
            end
 
            --Handle situations where itemList has a single, blank entry. Set value to item name provided by the calling page. Occurs for all tools. Could cause other issues for invalid item names.
    if itemIngredients ~= nil then
            if #itemList[item] == 1 and itemList[item][num] == '' then
      for _, itemIngredient in pairs(itemIngredients) do
            recipes[num] = recipeList[item]
        if itemIngredient ~= '' then
            end
          if recipeList[itemIngredient] ~= nil then
    table.insert(ingredients, recipeList[itemIngredient])
          end
         end
         end
      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:GetRecipes]].'
     end
     end
    return parser.formattedItem(products, ingredients, tag)
end
   
  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
return p
Обратите внимание, что все изменения в Eco - Русская Wiki рассматриваются как выпущенные на условиях лицензии CC BY-NC-SA 4.0 (см. Eco:Авторские права). Если вы не хотите, чтобы ваши тексты свободно распространялись и редактировались любым желающим, не помещайте их сюда.
Вы также подтверждаете, что являетесь автором вносимых дополнений или скопировали их из источника в общественном достоянии или под совместимой лицензией. Не размещайте без разрешения материалы, защищённые авторским правом!

В целях защиты вики от автоматического спама мы просим вас решить следующую капчу:

Отменить Справка по редактированию (в новом окне)

Шаблон, используемый на этой странице: