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

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

Материал из Eco - Русская Wiki
Перейти к:навигация, поиск
[непроверенная версия][досмотренная версия]
Новая страница: «local p = {} -- Grabs args from the parent frame -- Trims and parses the args into a table, then returns the table function norm() local origArgs = mw.getCu...»
 
Нет описания правки
Строка 1: Строка 1:
-- Module:GetRecipes (https://wiki.play.eco/en/Module:GetRecipes)
local p = {}
local p = {}


-- Grabs args from the parent frame
-- Grabs args from the parent frame
Строка 17: Строка 17:
     return args
     return args
end
end


-- Main entry point for the Module
-- Main entry point for the Module
function p.main()
function p.main()
     -- get args from the Template
     local test = ''
-- get args from the Template
     local args = norm()
     local args = norm()
      
      
Строка 32: Строка 33:
     local completeList = require( "Module:CraftingRecipes" )
     local completeList = require( "Module:CraftingRecipes" )
     local recipeList = completeList.recipes
     local recipeList = completeList.recipes
     local itemList = completeList.items
     local ingredientsList = completeList.ingredients
local productsList = completeList.products
     local tableList = completeList.tables
     local tableList = completeList.tables
   
    -- 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.
    --local groupList = completeList.groups
      
      
     -- initialize a table to store recipes
     -- initialize a table to store recipes
     local recipes = {}
     local recipes = {}
local products = {}
local ingredients = {}
      
      
     -- load CraftingParser
     -- load CraftingParser
     local parser = require( "Module:CraftingParser" )
     local parser = require( "Module:CraftingParser" )
 
     -- priority: item > table > group
     -- priority: item > table > group
     if item ~= nil then
     if item ~= nil then
        if itemList[item] == nil then
if productsList[item] ~= nil then
            return '===Crafting Recipes===\n\'\'None\'\'\n===Used in Recipes (potentially deprecated due to removal of groups - clean this up)===\n\'\'None\'\'\n'
for num = 1, #productsList[item] do
        end
if (productsList[item][num] ~= '' and recipeList[productsList[item][num]] ~= nil) then
        for num = 1, #itemList[item] do
products[num] = recipeList[productsList[item][num]]
            --nil entries in itemList are causing errors. Need to deal with exceptions where entry is ''
end
            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 ingredientsList[item] ~= nil then
            if #itemList[item] == 1 and itemList[item][num] == '' then
for num = 1, #ingredientsList[item] do
            recipes[num] = recipeList[item]
if (ingredientsList[item][num] ~= '' and recipeList[ingredientsList[item][num]] ~= nil) then
            end
ingredients[num] = recipeList[ingredientsList[item][num]]
        end
end
       
end
        return parser.formattedItem( recipes, item )
end
      return parser.formattedItem( products, ingredients, item )
          
          
     elseif table ~= nil then
     elseif table ~= nil then
--GROUP deprecated
         for num = 1, #tableList[table] do
         --if group ~= nil then
             recipes[num] = recipeList[tableList[table][num]]
            --local count = 1
        end
            --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 )
         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
     else
         return 'Invalid use of parameters, please see [[Template:GetRecipes]].'
         return 'Invalid use of parameters, please see [[Template:GetRecipes]].'
     end
     end
end
end


return p
return p

Версия от 20:14, 1 февраля 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 = {}

-- Grabs args from the parent frame
-- Trims and parses the args into a table, then returns the table
function norm()
    local origArgs = mw.getCurrentFrame():getParent().args
    local args = {}
    
    for k, v in pairs( origArgs ) do
        v = mw.text.trim( tostring( v ) )
        if v ~= '' then
            args[k] = v
        end
    end
    
    return args
end

-- Main entry point for the Module
function p.main()
    local test = ''
	
	-- get args from the Template
    local args = norm()
    
    -- 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
			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

        return parser.formattedTable( recipes, table )

    else
        return 'Invalid use of parameters, please see [[Template:GetRecipes]].'
    end
end

return p