« 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 6 : Ligne 6 :
     local args = Utils.normalise(param)
     local args = Utils.normalise(param)


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


     -- Récupérer le nom via l'ID
     -- Récupère le nom localisé de l'item
local itemName = Utils.ItemNameFromID(args.id)
    local itemName = Utils.ItemNameFromID(args.id)
if not itemName or itemName == 'None' then
 
         itemName = 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
     end


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


    -- Gestion du lien
     local IconLink = ''
     local IconLink = ''
     if args.link == '1' then  
     if args.link == '1' then
         IconLink = '[[' .. itemName .. ']]'
         IconLink = '[[' .. itemName .. ']]'
     elseif args.link and args.link ~= '' then
     elseif args.link and args.link ~= '' then
Ligne 27 : Ligne 34 :
     end
     end


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


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


return p
return p

Version du 16 novembre 2025 à 11:00

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)

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

    -- Récupère le nom localisé de l'item
    local itemName = 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 IconSize = (not args.size or args.size == '') and 28 or args.size
    local IconStyle = (not args.style or args.style == '') and '1' or args.style

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

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

    -- Retour selon style
    if IconStyle == '1' then
        return '[[File:' .. IconFile .. '|' .. IconSize .. 'px|link=' .. IconLink .. ']]'
    elseif IconStyle == '2' then
        return '[[File:' .. IconFile .. '|' .. IconSize .. 'px|link=' .. IconLink .. ']]' .. IconTextLine
    elseif IconStyle == '3' then
        return '[[File:' .. IconFile .. '|' .. IconSize .. 'px|link=' .. IconLink .. ']]' .. IconTextBr
    elseif IconStyle == '4' then
        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

return p