« 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 2 : Ligne 2 :


function p.main(param)
function p.main(param)
     local Utils = require('Module:Utils')
     local Utils = require("Module:Utils")
    local Icon = ''
    local IconStyle = ''
    local IconSize = ''
    local IconLink = ''
    local DisplayName = ''
   
     local args = Utils.normalise(param)
     local args = Utils.normalise(param)
   
 
     if args.id == nil or args.id == '' then
     if not args.id or args.id == '' then
         return 'Module:IconUtils \'id\' must be specified.'
         return "Module:IconUtils 'id' must be specified."
     end
     end
   
 
     Icon = args.id .. '_Icon.png'
     local Icon = args.id .. "_Icon.png"
      
     local IconSize = args.size ~= '' and args.size or 28
    -- Gestion de la taille
     local IconStyle = args.style ~= '' and args.style or '1'
    if args.size == nil or args.size == '' then
 
        IconSize = 28
     -- Déterminer DisplayName
    else
     local DisplayName = args.name
        IconSize = args.size
    if not DisplayName or DisplayName == '' then
     end
         local Item = Utils.ItemSearchByID(args.id)
   
         if Item and Item.Name then
    -- Gestion du style
             local lang = Utils.getLanguageName()
    if args.style == nil or args.style == '' then
             DisplayName = Item.Name[lang]
        IconStyle = '1'
                      or Item.Name["French"]
    else
                      or Item.Name["English"]
        IconStyle = args.style
                      or args.id
    end
   
     -- Récupération automatique du nom si non spécifié
     if args.name == nil or args.name == '' then
        -- Charger les données de traduction
         local ItemData = require('Module:ItemData')
        local itemInfo = ItemData.items[args.id .. 'Item']
       
         if itemInfo and itemInfo.Name then
             -- Priorité au français, sinon anglais
             DisplayName = itemInfo.Name['French'] or itemInfo.Name['English'] or args.id
         else
         else
             DisplayName = args.id
             DisplayName = args.id
         end
         end
    else
        DisplayName = args.name
     end
     end
   
 
     -- Gestion du lien
     -- Gestion du link
     if args.link == nil or args.link == '' then
    local IconLink = ""
        IconLink = ''
     if args.link and args.link ~= '' then
    else
         IconLink = '[[' .. args.link .. ']]'
         IconLink = '[[' .. args.link .. ']]'
     end
     end
   
 
     if args.link == '1' then
     local text = IconLink ~= '' and IconLink or DisplayName
        IconLink = '[[' .. DisplayName .. ']]'
     local IconTextLine = "  " .. text
    end
     local IconTextBr = "<br>" .. text
   
 
    -- Création des variations de texte
     local IconTextLine, IconTextBr
    if IconLink == '' then
        IconTextLine = ' ' .. DisplayName
        IconTextBr = '<br>' .. DisplayName
     else
        IconTextLine = ' ' .. IconLink
        IconTextBr = '<br>' .. IconLink
    end
   
    -- Rendu selon le style
     if IconStyle == '1' then
     if IconStyle == '1' then
         return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]'
         return "[[file:"..Icon.."|"..IconSize.."px|link="..IconLink.."]]"
     end
     end
   
     if IconStyle == '2' then
     if IconStyle == '2' then
         return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextLine
         return "[[file:"..Icon.."|"..IconSize.."px|link="..IconLink.."]]" .. IconTextLine
     end
     end
   
     if IconStyle == '3' then
     if IconStyle == '3' then
         return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr
         return "[[file:"..Icon.."|"..IconSize.."px|link="..IconLink.."]]" .. IconTextBr
     end
     end
   
     if IconStyle == '4' then
     if IconStyle == '4' then
         return '<div class="IconFrame">[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr .. '</div>'
         return '<div class="IconFrame">[[file:'..Icon.."|"..IconSize.."px|link="..IconLink.."]]" .. IconTextBr .. "</div>"
     end
     end
end
end


return p
return p

Version du 16 novembre 2025 à 10:37

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 or args.id == '' then
        return "Module:IconUtils 'id' must be specified."
    end

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

    -- Déterminer DisplayName
    local DisplayName = args.name
    if not DisplayName or DisplayName == '' then
        local Item = Utils.ItemSearchByID(args.id)
        if Item and Item.Name then
            local lang = Utils.getLanguageName()
            DisplayName = Item.Name[lang]
                      or Item.Name["French"]
                      or Item.Name["English"]
                      or args.id
        else
            DisplayName = args.id
        end
    end

    -- Gestion du link
    local IconLink = ""
    if args.link and args.link ~= '' then
        IconLink = '[[' .. args.link .. ']]'
    end

    local text = IconLink ~= '' and IconLink or DisplayName
    local IconTextLine = "  " .. text
    local IconTextBr = "<br>" .. text

    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
end

return p