« Module:RecipeUtils » : différence entre les versions

De Eco - Wiki Français
Aller à :navigation, rechercher
[version vérifiée][version vérifiée]
Aucun résumé des modifications
Balise : Révoqué
Aucun résumé des modifications
Balise : Révocation manuelle
 
Ligne 1 : Ligne 1 :
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 = {}
local p = {}


function p.main(param)
function p.ItemCraft(ItemName)
     local Utils = require('Module:Utils')
     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


     local Icon = ''
function p.TagIngredient(TagName)
     local IconStyle = ''
     local Recipes = ""
    local IconSize = ''
     for RecipeName,RecipeData in pairs(RecipesData.recipes) do
     local IconLink = ''
        for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do
     local IconBorder = ''
            if IngredientName == TagName and IngredientData.Type == "TAG" then
    local IconCount = ''
                if (Recipes == "") then Recipes = Recipes .. RecipeName else Recipes = Recipes .. "," .. RecipeName end
            end
        end
     end
     return Recipes
end


     local args = Utils.normalise(param)
function p.TagsIngredient(TagsList)
     local Recipes = ""
for Count, TagName in pairs(TagsList) do
RecipeList = p.TagIngredient(TagName)
if (Recipes == "") then Recipes = Recipes .. RecipeList else Recipes = Recipes .. "," .. RecipeList end
end
Recipes = Utils.CheckList(Recipes)
    return Recipes
end


     if args.id == nil or args.name == '' then return 'Module:IconUtils \'id\' must be specified.' 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


     local Icon = args.id .. '_Icon.png'
function p.CraftTable(RecipeList)
     local CraftTable = ""


     if args.size == nil or args.size == '' then IconSize = 28 else IconSize = args.size end
     if (RecipeList ~= "") then
    if args.style == nil or args.style == '' then IconStyle = '1' else IconStyle = args.style end
        CraftTable = CraftTable .. '<table class="table table-striped table-bordered sortable"><tr class="thead-dark">';
    if args.link == nil or args.link == '' then IconLink = '' else IconLink = '[[' .. args.link .. ']]' end 
        CraftTable = CraftTable .. '<th>' .. Utils.Translate("Crafting Table") .. '</th><th class="unsortable">' .. Utils.Translate("Products") .. '</th><th class="unsortable">' .. Utils.Translate("Ingredients") .. '</th><th data-sort-type="mm:ss">' .. Utils.Translate("Craft time") .. '</th><th>' .. Utils.Translate("Labor") .. '</th><th>' .. Utils.Translate("Skill Requirements") .. '</th><th>' .. Utils.Translate("Experience") .. '</th></tr>';
    if args.link == '1' then IconLink = '[[' .. args.name .. ']]' end
       
    if IconLink == '' then IconTextLine = '  ' .. args.name IconTextBr = '<br>' .. args.name else IconTextLine = '  ' .. IconLink IconTextBr = '<br>' .. IconLink end
        for RecipeName in string.gmatch(RecipeList, "([^,]+)") do
    if args.count == nil or args.count == '' then IconCount = '1' else IconCount = args.count end
            local CraftTableRow = "";
    if args.border == nil or args.border == '' then IconBorder = ' borderwhite' else IconBorder = ' border' .. args.border end
            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>";
           
            local RecipeProducts = "";
            for ProductName,ProductData in pairs(RecipeData.Products) do
            local Item = ItemsData.items[ProductName]
            if ProductData.IsStatic == 'True' then ItemBorder = 'yellow' else ItemBorder = 'green' end
                RecipeProducts = RecipeProducts .. '<span style="display: inline-block;">' .. IconUtils.main{ name = Item.Name[Lang], id = Item.ID, size = 48, style = 5, link = Item.Name[Lang], border = ItemBorder, count = ProductData.Quantity } .. '</span>';
            end
            CraftTableRow = CraftTableRow .. "<td>" .. RecipeProducts .. "</td>";


    if IconStyle == '1' then return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' end
            local RecipeIngredients = "";
    if IconStyle == '2' then return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextLine end
            local TagString = Utils.Translate("{0} Tag");
    if IconStyle == '3' then return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr end
            for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do
    if IconStyle == '4' then return '<div class="IconFrame">[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr .. '</div>' end
            if IngredientData.IsStatic == 'True' then ItemBorder = 'yellow' else ItemBorder = 'green' end
    if IconStyle == '5' then return '<div class="recipeitem withcount' .. IconBorder .. '" style="font-size:' .. IconSize .. 'px">' .. '<div class="recipeitemicon">[[file:'.. Icon ..'|'.. IconSize ..'px|link=]]</div><span class="recipeitemcount">' .. IconCount .. '</span>' .. '[[' .. args.link .. '|<div class="recipeitemlink" title="' .. args.link .. '"></div>]]</div>' end
            if (IngredientData['Type'] == "TAG") then local Tag = TagsData.tags[IngredientName]; local TagLink = Utils.VSTranslate(TagString,Tag.Name[Lang]); RecipeIngredients = RecipeIngredients .. '<span style="display: inline-block;">' .. IconUtils.main{ name = Tag.Name[Lang], id = Tag.ID, size = 48, style = 5, link = TagLink, border = ItemBorder, count = IngredientData.Quantity } .. '</span>';
     if IconStyle == '6' then return '<div class="recipeitem' .. IconBorder .. '" style="font-size:' .. IconSize .. 'px">' .. '<div class="recipeitemicon">[[file:'.. Icon ..'|'.. IconSize ..'px|link=]]</div>[[' .. args.link .. '|<div class="recipeitemlink" title="' .. args.link .. '"></div>]]</div>' end
            else  local Item = ItemsData.items[IngredientName]; RecipeIngredients = RecipeIngredients .. '<span style="display: inline-block;">' .. IconUtils.main{ name = Item.Name[Lang], id = Item.ID, size = 48, style = 5, link = Item.Name[Lang], border = ItemBorder, count = IngredientData.Quantity } .. '</span>';
            end
           
            end
            if (RecipeData.RequiresStrangeBlueprint == "True") then RecipeIngredients = RecipeIngredients .. '<span style="display: inline-block;">' .. IconUtils.main{ name = "Blueprint", id = "BlueprintItem", size = 48, style = 6, link = "Marketplace"} .. '</span>'; end
            CraftTableRow = CraftTableRow .. "<td>" .. RecipeIngredients .. "</td>";
            local CraftTime = tonumber(RecipeData.CraftTime)
CraftTableRow = CraftTableRow .. "<td><span>" .. p.CraftTime(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 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 = "00:" .. CraftTime .. Seconds;
    return CraftTime
end
 
function p.RecipeRequiredSkill(SkillData)
local SkillCell = ""
local SkillID = SkillData[1]
local SkillLevel = SkillData[2]
if ((SkillID == "") or (SkillID == "nil")) then SkillName = 'None' else SkillName = Utils.SkillSearchByID(SkillID) end
if (SkillName == "None") then SkillCell = IconUtils.main{ name = Utils.Translate("None"), id = 'NoSkillLabor', size = 48, style = 2 } else SkillCell = IconUtils.main{ name = SkillsData.skills[SkillName].Name[Lang], id = SkillsData.skills[SkillName].SkillID, size = 48, style = 2, link = SkillsData.skills[SkillName].Name[Lang]} .. " " .. SkillLevel end
return SkillCell
end
 
function p.CraftingTableRecipes(ItemName)
    local Recipes = ""
    for RecipeName,RecipeData in pairs(RecipesData.recipes) do
            if RecipeData.CraftingTables == ItemName then
                if (Recipes == "") then Recipes = Recipes .. RecipeName else Recipes = Recipes .. "," .. RecipeName end
            end
    end
         
    return Recipes
end
end


return p
return p

Dernière version du 25 février 2026 à 21:53

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 = 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.TagsIngredient(TagsList)
    local Recipes = ""
	for Count, TagName in pairs(TagsList) do
		RecipeList = p.TagIngredient(TagName)
		if (Recipes == "") then Recipes = 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 = 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") .. '</th><th class="unsortable">' .. Utils.Translate("Products") .. '</th><th class="unsortable">' .. Utils.Translate("Ingredients") .. '</th><th data-sort-type="mm:ss">' .. Utils.Translate("Craft time") .. '</th><th>' .. Utils.Translate("Labor") .. '</th><th>' .. Utils.Translate("Skill Requirements") .. '</th><th>' .. Utils.Translate("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 = 48, style = 2, link = CraftTableData.Name[Lang] } .. "</td>";
            
            local RecipeProducts = "";
            for ProductName,ProductData in pairs(RecipeData.Products) do
            	local Item = ItemsData.items[ProductName]
            	if ProductData.IsStatic == 'True' then ItemBorder = 'yellow' else ItemBorder = 'green' end
                RecipeProducts = RecipeProducts .. '<span style="display: inline-block;">' .. IconUtils.main{ name = Item.Name[Lang], id = Item.ID, size = 48, style = 5, link = Item.Name[Lang], border = ItemBorder, count = ProductData.Quantity } .. '</span>';
            end
            CraftTableRow = CraftTableRow .. "<td>" .. RecipeProducts .. "</td>";

            local RecipeIngredients = "";
            local TagString = Utils.Translate("{0} Tag");
            for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do
            	if IngredientData.IsStatic == 'True' then ItemBorder = 'yellow' else ItemBorder = 'green' end
            	if (IngredientData['Type'] == "TAG") then local Tag = TagsData.tags[IngredientName]; local TagLink = Utils.VSTranslate(TagString,Tag.Name[Lang]); RecipeIngredients = RecipeIngredients .. '<span style="display: inline-block;">' .. IconUtils.main{ name = Tag.Name[Lang], id = Tag.ID, size = 48, style = 5, link = TagLink, border = ItemBorder, count = IngredientData.Quantity } .. '</span>'; 
            	else  local Item = ItemsData.items[IngredientName]; RecipeIngredients = RecipeIngredients .. '<span style="display: inline-block;">' .. IconUtils.main{ name = Item.Name[Lang], id = Item.ID, size = 48, style = 5, link = Item.Name[Lang], border = ItemBorder, count = IngredientData.Quantity } .. '</span>';
            	end
            	
            end
            if (RecipeData.RequiresStrangeBlueprint == "True") then RecipeIngredients = RecipeIngredients .. '<span style="display: inline-block;">' .. IconUtils.main{ name = "Blueprint", id = "BlueprintItem", size = 48, style = 6, link = "Marketplace"} .. '</span>'; end
            CraftTableRow = CraftTableRow .. "<td>" .. RecipeIngredients .. "</td>";
            local CraftTime = tonumber(RecipeData.CraftTime)
			CraftTableRow = CraftTableRow .. "<td><span>" .. p.CraftTime(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 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 = "00:" .. CraftTime .. Seconds;
    return CraftTime
end

function p.RecipeRequiredSkill(SkillData)
	local SkillCell = ""
	local SkillID = SkillData[1]
	local SkillLevel = SkillData[2]
	if ((SkillID == "") or (SkillID == "nil")) then SkillName = 'None' else SkillName = Utils.SkillSearchByID(SkillID) end
	if (SkillName == "None") then SkillCell = IconUtils.main{ name = Utils.Translate("None"), id = 'NoSkillLabor', size = 48, style = 2 } else SkillCell = IconUtils.main{ name = SkillsData.skills[SkillName].Name[Lang], id = SkillsData.skills[SkillName].SkillID, size = 48, style = 2, link = SkillsData.skills[SkillName].Name[Lang]} .. " " .. SkillLevel end
	
	return SkillCell
end

function p.CraftingTableRecipes(ItemName)
    local Recipes = ""
    for RecipeName,RecipeData in pairs(RecipesData.recipes) do
            if RecipeData.CraftingTables == ItemName then
                if (Recipes == "") then Recipes = Recipes .. RecipeName else Recipes = Recipes .. "," .. RecipeName end
            end
    end
           
    return Recipes
end

return p