Module:RecipeUtils: Difference between revisions
From Eco - English Wiki
| [checked revision] | [checked revision] |
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local Utils = require('Module:Utils') | local Utils = require('Module:Utils') | ||
local IconUtils = require('Module:IconUtils') | |||
local RecipesData = require('Module:RecipeData') | local RecipesData = require('Module:RecipeData') | ||
local ItemsData = require('Module:ItemData') | local ItemsData = require('Module:ItemData') | ||
local TagsData = require('Module:TagData') | local TagsData = require('Module:TagData') | ||
local Lang = Utils.getLanguageName() | |||
local p = {} | local p = {} | ||
| Line 52: | Line 54: | ||
local CraftTableRow = ""; | local CraftTableRow = ""; | ||
local RecipeData = RecipesData.recipes[RecipeName]; | local RecipeData = RecipesData.recipes[RecipeName]; | ||
local CraftTableData = ItemsData.items[RecipeData.CraftingTables] | |||
CraftTableRow = "<td>" .. | CraftTableRow = "<td>" .. IconUtils.main{ name = CraftTableData.Name[Lang], id = CraftTableData.ID, size = 64, style = 3, } .. "</td>"; | ||
local RecipeProducts = ""; | local RecipeProducts = ""; | ||
Revision as of 14:34, 29 August 2025
Documentation for this module may be created at Module:RecipeUtils/doc
local Utils = require('Module:Utils')
local IconUtils = require('Module:IconUtils')
local RecipesData = require('Module:RecipeData')
local ItemsData = require('Module:ItemData')
local TagsData = require('Module:TagData')
local Lang = Utils.getLanguageName()
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 sortable"><tr class="thead-dark">';
CraftTable = CraftTable .. '<th>Crafting Station</th><th>Products</th><th>Ingredients</th><th data-sort-type="time">Time</th><th>Labor</th><th>Skill</th><th>Experience</th></tr>';
for RecipeName in string.gmatch(RecipeList, "([^,]+)") do
local CraftTableRow = "";
local RecipeData = RecipesData.recipes[RecipeName];
local CraftTableData = ItemsData.items[RecipeData.CraftingTables]
CraftTableRow = "<td>" .. IconUtils.main{ name = CraftTableData.Name[Lang], id = CraftTableData.ID, size = 64, style = 3, } .. "</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>";
local CraftTime = tonumber(RecipeData.CraftTime)
CraftTableRow = CraftTableRow .. "<td>" .. p.CraftTime(CraftTime) .. "</td>";
CraftTableRow = CraftTableRow .. "<td>" .. RecipeData.LaborInCalories .. "</td>";
CraftTableRow = CraftTableRow .. "<td>" .. "Skill" .. "</td>";
CraftTableRow = CraftTableRow .. "<td>" .. RecipeData.ExperienceOnCraft .. "</td>";
CraftTable = CraftTable .. "<tr>" ..CraftTableRow .. "</tr>";
end
CraftTable = CraftTable .. "</table>";
end
return CraftTable
end
function p.CraftTime(TimeInSeconds)
local CraftTime = "";
local Minutes = 0;
local Seconds = 0;
if (TimeInSeconds >= 60) then Minutes = math.floor(TimeInSeconds / 60); Seconds = TimeInSeconds - Minutes * 60; else Seconds = TimeInSeconds; end
if (Minutes <10) then CraftTime = "0" .. Minutes .. ":" else CraftTime = Minutes .. ":" end
if (Seconds < 10) then CraftTime = CraftTime .. "0" end
CraftTime = CraftTime .. Seconds;
return CraftTime
end
return p