Module:RecipeUtils
De Eco - Wiki Français
La documentation pour ce module peut être créée à 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 SkillsData = require('Module:SkillData')
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 = 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 = RecipeName else Recipes = Recipes .. "," .. RecipeName end
end
end
end
return Recipes
end
function p.TagsIngredient(TagsList)
local Recipes = ""
for Count, TagName in pairs(TagsList) do
RecipeList = p.TagIngredient(TagName)
if (Recipes == "") then Recipes = RecipeList else Recipes = Recipes .. "," .. RecipeList end
end
Recipes = Utils.CheckList(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 = 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>' .. Utils.Translate("Crafting Table", "Poste de Fabrication") .. '</th>'
CraftTable = CraftTable .. '<th class="unsortable">' .. Utils.Translate("Products", "Produits") .. '</th>'
CraftTable = CraftTable .. '<th class="unsortable">' .. Utils.Translate("Ingredients", "Ingrédients") .. '</th>'
CraftTable = CraftTable .. '<th data-sort-type="mm:ss">' .. Utils.Translate("Craft time", "Temps de fabrication") .. '</th>'
CraftTable = CraftTable .. '<th>' .. Utils.Translate("Labor", "Calories") .. '</th>'
CraftTable = CraftTable .. '<th>' .. Utils.Translate("Skill Requirements", "Compétence requise") .. '</th>'
CraftTable = CraftTable .. '<th>' .. Utils.Translate("Experience", "Expérience") .. '</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 = 48, style = 2, link = CraftTableData.Name[Lang] } .. "</td>";
-- Produits
local RecipeProducts = "";
for ProductName,ProductData in pairs(RecipeData.Products) do
local Item = ItemsData.items[ProductName]
RecipeProducts = RecipeProducts .. "<span>" .. IconUtils.main{ name = Item.Name[Lang], id = Item.ID, size = 48, style = 2, link = Item.Name[Lang] } .. "</span>";
end
CraftTableRow = CraftTableRow .. "<td>" .. RecipeProducts .. "</td>";
-- Ingrédients
local RecipeIngredients = "";
local TagString = Utils.Translate("{0} Tag", "Étiquette {0}")
for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do
if (IngredientData.Type == "TAG") then
local Tag = TagsData.tags[IngredientName]
local TagLink = Utils.VSTranslate(TagString, Tag.Name[Lang])
RecipeIngredients = RecipeIngredients .. "<span>" .. IconUtils.main{ name = Tag.Name[Lang], id = Tag.ID, size = 48, style = 2, link = TagLink } .. "</span>"
else
local Item = ItemsData.items[IngredientName]
RecipeIngredients = RecipeIngredients .. "<span>" .. IconUtils.main{ name = Item.Name[Lang], id = Item.ID, size = 48, style = 2, link = Item.Name[Lang] } .. "</span>"
end
end
if (RecipeData.RequiresStrangeBlueprint == "True") then
RecipeIngredients = RecipeIngredients .. "<span>" .. IconUtils.main{ name = "Plan secret", id = "BlueprintItem", size = 48, style = 3, link = "Marketplace"} .. "</span>"
end
CraftTableRow = CraftTableRow .. "<td>" .. RecipeIngredients .. "</td>";
-- Temps / Calories / compétence / XP
CraftTableRow = CraftTableRow .. "<td><span>" .. p.CraftTime(tonumber(RecipeData.CraftTime)) .. "</span></td>";
CraftTableRow = CraftTableRow .. "<td><span>" .. RecipeData.LaborInCalories .. "</span></td>";
CraftTableRow = CraftTableRow .. "<td>" .. p.RecipeRequiredSkill(RecipeData.RequiredSkill) .. "</td>";
CraftTableRow = CraftTableRow .. "<td><span>" .. RecipeData.ExperienceOnCraft .. "</span></td>";
CraftTable = CraftTable .. "<tr>" .. CraftTableRow .. "</tr>";
end
CraftTable = CraftTable .. "</table>";
end
return CraftTable
end
function p.CraftTime(TimeInSeconds)
local Minutes = math.floor(TimeInSeconds / 60)
local Seconds = TimeInSeconds % 60
return string.format("00:%02d:%02d", Minutes, Seconds)
end
function p.RecipeRequiredSkill(SkillData)
local SkillID = SkillData[1]
local SkillLevel = SkillData[2]
local SkillName = (SkillID == "" or SkillID == "nil") and "None" or Utils.SkillSearchByID(SkillID)
if (SkillName == "None") then
return IconUtils.main{ name = Utils.Translate("None", "Aucune"), id = 'NoSkillLabor', size = 48, style = 2 }
else
local Skill = SkillsData.skills[SkillName]
return IconUtils.main{
name = Skill.Name[Lang],
id = Skill.SkillID,
size = 48,
style = 2,
link = Skill.Name[Lang]
} .. " " .. SkillLevel
end
end
return p