« 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
Aucun résumé des modifications
Balise : Révoqué
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.ItemCraft(ItemName)
function p.main(param)
     local Recipes = ""
     local Utils = require('Module:Utils')
    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 Icon = ''
     local Recipes = ""
     local IconStyle = ''
     for RecipeName,RecipeData in pairs(RecipesData.recipes) do
     local IconSize = ''
        for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do
    local IconLink = ''
            if IngredientName == TagName and IngredientData.Type == "TAG" then
     local IconBorder = ''
                if (Recipes == "") then Recipes = Recipes .. RecipeName else Recipes = Recipes .. "," .. RecipeName end
     local IconCount = ''
            end
        end
     end
     return Recipes
end


function p.TagsIngredient(TagsList)
     local args = Utils.normalise(param)
     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)
     if args.id == nil or args.name == '' then return 'Module:IconUtils \'id\' must be specified.' end
     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 Icon = args.id .. '_Icon.png'
     local CraftTable = ""


     if (RecipeList ~= "") then
     if args.size == nil or args.size == '' then IconSize = 28 else IconSize = args.size end
        CraftTable = CraftTable .. '<table class="table table-striped table-bordered sortable"><tr class="thead-dark">';
    if args.style == nil or args.style == '' then IconStyle = '1' else IconStyle = args.style 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 == nil or args.link == '' then IconLink = '' else IconLink = '[[' .. args.link .. ']]' end 
       
    if args.link == '1' then IconLink = '[[' .. args.name .. ']]' end
        for RecipeName in string.gmatch(RecipeList, "([^,]+)") do
    if IconLink == '' then IconTextLine = '  ' .. args.name IconTextBr = '<br>' .. args.name else IconTextLine = '  ' .. IconLink IconTextBr = '<br>' .. IconLink end
            local CraftTableRow = "";
    if args.count == nil or args.count == '' then IconCount = '1' else IconCount = args.count end
            local RecipeData = RecipesData.recipes[RecipeName];
    if args.border == nil or args.border == '' then IconBorder = ' borderwhite' else IconBorder = ' border' .. args.border end
            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 = "";
    if IconStyle == '1' then return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' end
            local TagString = Utils.Translate("{0} Tag");
    if IconStyle == '2' then return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextLine end
            for IngredientName,IngredientData in pairs(RecipeData.Ingredients) do
    if IconStyle == '3' then return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr end
            if IngredientData.IsStatic == 'True' then ItemBorder = 'yellow' else ItemBorder = 'green' end
    if IconStyle == '4' then return '<div class="IconFrame">[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr .. '</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 == '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
            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>';
     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
            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

Version du 25 février 2026 à 21:52

La documentation pour ce module peut être créée à Module:RecipeUtils/doc

local p = {}

function p.main(param)
    local Utils = require('Module:Utils')

    local Icon = ''
    local IconStyle = ''
    local IconSize = ''
    local IconLink = ''
    local IconBorder = ''
    local IconCount = ''

    local args = Utils.normalise(param)

    if args.id == nil or args.name == '' then return 'Module:IconUtils \'id\' must be specified.' end

    local Icon = args.id .. '_Icon.png'

    if args.size == nil or args.size == '' then IconSize = 28 else IconSize = args.size end
    if args.style == nil or args.style == '' then IconStyle = '1' else IconStyle = args.style end
    if args.link == nil or args.link == '' then IconLink = '' else IconLink = '[[' .. args.link .. ']]' end   
    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
    if args.count == nil or args.count == '' then IconCount = '1' else IconCount = args.count end
    if args.border == nil or args.border == '' then IconBorder = ' borderwhite' else IconBorder = ' border' .. args.border end

    if IconStyle == '1' then return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' end
    if IconStyle == '2' then return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextLine end
    if IconStyle == '3' then return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr end
    if IconStyle == '4' then return '<div class="IconFrame">[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr .. '</div>' 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 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
end

return p