« Module:IconUtils » : 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
Ligne 3 : Ligne 3 :
function p.main(param)
function p.main(param)
     local Utils = require('Module:Utils')
     local Utils = require('Module:Utils')
     local args = Utils.normalise(param)
     local args = Utils.normalise(param)


    -- Vérifie que l'ID est fourni
     if not args.id then
     if not args.id or args.id == '' then
         return "Module:IconUtils : 'id' must be specified."
         return "Module:IconUtils FR : 'id' must be specified."
     end
     end


     -- Récupère le nom localisé de l'item
     -- nom à afficher : si name fourni, on l'utilise, sinon fallback via Utils.ItemNameFromID
    local itemName = Utils.ItemNameFromID(args.id)
     local name = args.name or Utils.ItemNameFromID(args.id)
 
    -- Nom du fichier image
     local IconFile = args.id .. "_Icon.png"
 
    -- Vérifie que le fichier existe
    if Utils.checkImage(IconFile) ~= "Y" then
        return "Image not found: " .. IconFile
    end


     -- Taille et style par défaut
     local Icon = args.id .. "_Icon.png"
     local IconSize = (not args.size or args.size == '') and 28 or args.size
     local IconSize = args.size or 28
     local IconStyle = (not args.style or args.style == '') and '1' or args.style
     local IconStyle = args.style or "1"


    -- Gestion du lien
     local IconLink = ""
     local IconLink = ''
     if args.link == "1" then
     if args.link == '1' then
         IconLink = "[[" .. name .. "]]"
         IconLink = '[[' .. itemName .. ']]'
     elseif args.link and args.link ~= "" then
     elseif args.link and args.link ~= '' then
         IconLink = "[[" .. args.link .. "]]"
         IconLink = '[[' .. args.link .. ']]'
     end
     end


    -- Texte additionnel pour certains styles
     local IconTextLine = IconLink ~= "" and " " .. IconLink or " " .. name
     local IconTextLine = IconLink ~= '' and ' ' .. IconLink or ' ' .. itemName
     local IconTextBr  = IconLink ~= "" and "<br>" .. IconLink or "<br>" .. name
     local IconTextBr  = IconLink ~= '' and '<br>' .. IconLink or '<br>' .. itemName


    -- Retour selon style
     if IconStyle == "1" then
     if IconStyle == '1' then
         return "[[File:" .. Icon .. "|" .. IconSize .. "px|link=" .. IconLink .. "]]"
         return '[[File:' .. IconFile .. '|' .. IconSize .. 'px|link=' .. IconLink .. ']]'
     elseif IconStyle == "2" then
     elseif IconStyle == '2' then
         return "[[File:" .. Icon .. "|" .. IconSize .. "px|link=" .. IconLink .. "]]" .. IconTextLine
         return '[[File:' .. IconFile .. '|' .. IconSize .. 'px|link=' .. IconLink .. ']]' .. IconTextLine
     elseif IconStyle == "3" then
     elseif IconStyle == '3' then
         return "[[File:" .. Icon .. "|" .. IconSize .. "px|link=" .. IconLink .. "]]" .. IconTextBr
         return '[[File:' .. IconFile .. '|' .. IconSize .. 'px|link=' .. IconLink .. ']]' .. IconTextBr
     elseif IconStyle == "4" then
     elseif IconStyle == '4' then
         return '<div class="IconFrame">[[File:' .. Icon .. "|" .. IconSize .. "px|link=" .. IconLink .. "]]" .. IconTextBr .. "</div>"
         return '<div class="IconFrame">[[File:' .. IconFile .. '|' .. IconSize .. 'px|link=' .. IconLink .. ']]' .. IconTextBr .. '</div>'
    else
        -- fallback style 1 si style inconnu
        return '[[File:' .. IconFile .. '|' .. IconSize .. 'px|link=' .. IconLink .. ']]'
     end
     end
end
end


return p
return p

Version du 16 novembre 2025 à 11:14

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

local p = {}

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

    if not args.id then
        return "Module:IconUtils : 'id' must be specified."
    end

    -- nom à afficher : si name fourni, on l'utilise, sinon fallback via Utils.ItemNameFromID
    local name = args.name or Utils.ItemNameFromID(args.id)

    local Icon = args.id .. "_Icon.png"
    local IconSize = args.size or 28
    local IconStyle = args.style or "1"

    local IconLink = ""
    if args.link == "1" then
        IconLink = "[[" .. name .. "]]"
    elseif args.link and args.link ~= "" then
        IconLink = "[[" .. args.link .. "]]"
    end

    local IconTextLine = IconLink ~= "" and "  " .. IconLink or "  " .. name
    local IconTextBr   = IconLink ~= "" and "<br>" .. IconLink or "<br>" .. name

    if IconStyle == "1" then
        return "[[File:" .. Icon .. "|" .. IconSize .. "px|link=" .. IconLink .. "]]"
    elseif IconStyle == "2" then
        return "[[File:" .. Icon .. "|" .. IconSize .. "px|link=" .. IconLink .. "]]" .. IconTextLine
    elseif IconStyle == "3" then
        return "[[File:" .. Icon .. "|" .. IconSize .. "px|link=" .. IconLink .. "]]" .. IconTextBr
    elseif IconStyle == "4" then
        return '<div class="IconFrame">[[File:' .. Icon .. "|" .. IconSize .. "px|link=" .. IconLink .. "]]" .. IconTextBr .. "</div>"
    end
end

return p