Module:RecipeUtils

From Eco - English Wiki
Revision as of 05:42, 18 August 2025 by StalEF (talk | contribs)

Documentation for this module may be created at Module:RecipeUtils/doc

local Utils = require('Module:Utils')
local RecipesData = require('Module:RecipeData')
local ItemsData = require('Module:ItemData')
local p = {}

function p.ItemCraft(ItemName)
    local Recipes = ""
    for RecipeName,RecipeData in pairs(RecipesData.recipes) do
        for ProductName,ProductData in pairs(RecipeData.Products) do
            if ProductName == ItemName and ProductData.Type == "ITEM" then
                if (Recipes == "") then Recipes = Recipes .. RecipeName else Recipes = Recipes .. ", " .. RecipeName end
            end
        end
    end
           
    return Recipes
end

function p.TagIngredients(TagName)
    local Recipes = ""
    for RecipeName,RecipeData in pairs(RecipesData.recipes) do
        for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do
            if IngredientName == TagName and IngredientData.Type == "TAG" then
                if (Recipes == "") then Recipes = Recipes .. RecipeName else Recipes = Recipes .. ", " .. RecipeName end
            end
        end
    end
    return Recipes
end

return p