Module:RecipeUtils: Difference between revisions
From Eco - English Wiki
| [checked revision] | [checked revision] |
No edit summary |
No edit summary |
||
| Line 9: | Line 9: | ||
for ProductName,ProductData in pairs(RecipeData.Products) do | for ProductName,ProductData in pairs(RecipeData.Products) do | ||
if ProductName == ItemName and ProductData.Type == "ITEM" then | if ProductName == ItemName and ProductData.Type == "ITEM" then | ||
if (Recipes == "") then Recipes = Recipes .. RecipeName else Recipes = Recipes .. ", " .. RecipeName end | if (Recipes == "") then Recipes = Recipes .. RecipeName else Recipes = Recipes .. "," .. RecipeName end | ||
end | end | ||
end | end | ||
| Line 17: | Line 17: | ||
end | end | ||
function p. | function p.TagIngredient(TagName) | ||
local Recipes = "" | local Recipes = "" | ||
for RecipeName,RecipeData in pairs(RecipesData.recipes) do | for RecipeName,RecipeData in pairs(RecipesData.recipes) do | ||
for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do | for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do | ||
if IngredientName == TagName and IngredientData.Type == "TAG" then | if IngredientName == TagName and IngredientData.Type == "TAG" then | ||
if (Recipes == "") then Recipes = Recipes .. RecipeName else Recipes = Recipes .. ", " .. RecipeName end | if (Recipes == "") then Recipes = Recipes .. RecipeName else Recipes = Recipes .. "," .. RecipeName end | ||
end | end | ||
end | end | ||
end | end | ||
return Recipes | return Recipes | ||
end | |||
function p.ItemIngredient(ItemName) | |||
local Recipes = "" | |||
for RecipeName,RecipeData in pairs(RecipesData.recipes) do | |||
for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do | |||
if IngredientName == ItemName and IngredientData.Type == "ITEM" then | |||
if (Recipes == "") then Recipes = Recipes .. RecipeName else Recipes = Recipes .. "," .. RecipeName end | |||
end | |||
end | |||
end | |||
return Recipes | |||
end | |||
function p.CraftTable(RecipeList) | |||
local CraftTable = "" | |||
if (RecipeList ~= "") then | |||
CraftTable = CraftTable .. '<table class="table table-striped table-bordered"><tr class="thead-dark"><th>Name</th><th>Products</th><th>Ingredients</th></tr>'; | |||
for RecipeName in string.gmatch(RecipeList, "([^,]+)") do | |||
local CraftTableRow = ""; | |||
local RecipeData = RecipesData.recipes[RecipeName]; | |||
CraftTableRow = "<td>" .. RecipeName .. "</td>"; | |||
local RecipeProducts = ""; | |||
for ProductName,ProductData in pairs(RecipeData.Products) do | |||
RecipeProducts = RecipeProducts .. ProductName .. ","; | |||
end | |||
CraftTableRow = CraftTableRow .. "<td>" .. RecipeProducts .. "</td>"; | |||
local RecipeIngredients = ""; | |||
for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do | |||
RecipeIngredients = RecipeIngredients .. IngredientName .. ","; | |||
end | |||
CraftTableRow = CraftTableRow .. "<td>" .. RecipeIngredients .. "</td>"; | |||
CraftTable = CraftTable .. "<tr>" ..CraftTableRow .. "</tr>"; | |||
end | |||
CraftTable = CraftTable .. "</table>"; | |||
end | |||
return CraftTable | |||
end | end | ||
return p | return p | ||
Revision as of 20:51, 24 August 2025
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.TagIngredient(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
function p.ItemIngredient(ItemName)
local Recipes = ""
for RecipeName,RecipeData in pairs(RecipesData.recipes) do
for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do
if IngredientName == ItemName and IngredientData.Type == "ITEM" then
if (Recipes == "") then Recipes = Recipes .. RecipeName else Recipes = Recipes .. "," .. RecipeName end
end
end
end
return Recipes
end
function p.CraftTable(RecipeList)
local CraftTable = ""
if (RecipeList ~= "") then
CraftTable = CraftTable .. '<table class="table table-striped table-bordered"><tr class="thead-dark"><th>Name</th><th>Products</th><th>Ingredients</th></tr>';
for RecipeName in string.gmatch(RecipeList, "([^,]+)") do
local CraftTableRow = "";
local RecipeData = RecipesData.recipes[RecipeName];
CraftTableRow = "<td>" .. RecipeName .. "</td>";
local RecipeProducts = "";
for ProductName,ProductData in pairs(RecipeData.Products) do
RecipeProducts = RecipeProducts .. ProductName .. ",";
end
CraftTableRow = CraftTableRow .. "<td>" .. RecipeProducts .. "</td>";
local RecipeIngredients = "";
for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do
RecipeIngredients = RecipeIngredients .. IngredientName .. ",";
end
CraftTableRow = CraftTableRow .. "<td>" .. RecipeIngredients .. "</td>";
CraftTable = CraftTable .. "<tr>" ..CraftTableRow .. "</tr>";
end
CraftTable = CraftTable .. "</table>";
end
return CraftTable
end
return p