« 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 ItemData = require('Module:ItemData') or {}
     local Icon = ''
    local IconStyle = ''
    local IconSize = ''
    local IconLink = ''
    local DisplayName = ''
   
     local args = Utils.normalise(param)
     local args = Utils.normalise(param)
 
   
     if not args.id or args.id == '' then
     if args.id == nil or args.id == '' then
         return "Module:IconUtils 'id' must be specified."
         return 'Module:IconUtils \'id\' must be specified.'
     end
     end
 
   
     local Icon = args.id .. "_Icon.png"
     Icon = args.id .. '_Icon.png'
     local IconSize = args.size and args.size ~= '' and args.size or 28
   
     local IconStyle = args.style and args.style ~= '' and args.style or '1'
    -- Gestion de la taille
 
     if args.size == nil or args.size == '' then
     -- ==========================
        IconSize = 28
     -- Récupération nom auto
     else
     -- ==========================
        IconSize = args.size
     local name = args.name
    end
     local link = args.link
      
     local defaultLang = "French"
     -- Gestion du style
 
     if args.style == nil or args.style == '' then
     if not name or name == '' or not link or link == '' then
        IconStyle = '1'
         for _, item in pairs(ItemData) do
     else
            if type(item) == "table" and item.ID == args.id and item.Name then
        IconStyle = args.style
                local fr = item.Name[defaultLang]
     end
                local en = item.Name['English']
      
 
    -- Récupération automatique du nom si non spécifié
                if (not name or name == '') then
     if args.name == nil or args.name == '' then
                    if fr and fr ~= '' then
         -- Charger les données de traduction
                        name = fr
        local ItemData = require('Module:ItemData')
                    elseif en and en ~= '' then
        local itemInfo = ItemData.items[args.id .. 'Item']
                        name = en
       
                    else
        if itemInfo and itemInfo.Name then
                        name = args.id
            -- Priorité au français, sinon anglais
                    end
            DisplayName = itemInfo.Name['French'] or itemInfo.Name['English'] or args.id
                end
        else
 
            DisplayName = args.id
                if (not link or link == '') then
                    if fr and fr ~= '' then
                        link = fr
                    elseif en and en ~= '' then
                        link = en
                    else
                        link = args.id
                    end
                end
            end
         end
         end
    else
        DisplayName = args.name
    end
   
    -- Gestion du lien
    if args.link == nil or args.link == '' then
        IconLink = ''
    else
        IconLink = '[[' .. args.link .. ']]'
    end
   
    if args.link == '1' then
        IconLink = '[[' .. DisplayName .. ']]'
    end
   
    -- Création des variations de texte
    local IconTextLine, IconTextBr
    if IconLink == '' then
        IconTextLine = ' ' .. DisplayName
        IconTextBr = '<br>' .. DisplayName
    else
        IconTextLine = ' ' .. IconLink
        IconTextBr = '<br>' .. IconLink
     end
     end
 
      
    if not name or name == '' then name = args.id end
     -- Rendu selon le style
     if not link or link == '' then link = name end
 
     -- Construit le lien final
    local IconLink = '[[' .. link .. ']]'
    local IconTextLine = '  ' .. IconLink
    local IconTextBr  = '<br>' .. IconLink
 
     if IconStyle == '1' then
     if IconStyle == '1' then
         return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]'
         return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]'
     elseif IconStyle == '2' then
     end
   
    if IconStyle == '2' then
         return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextLine
         return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextLine
     elseif IconStyle == '3' then
     end
   
    if IconStyle == '3' then
         return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr
         return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextBr
     elseif IconStyle == '4' then
     end
   
    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

Version du 16 novembre 2025 à 10:23

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

local p = {}

function p.main(param)
    local Utils = require('Module:Utils')
    local Icon = ''
    local IconStyle = ''
    local IconSize = ''
    local IconLink = ''
    local DisplayName = ''
    
    local args = Utils.normalise(param)
    
    if args.id == nil or args.id == '' then
        return 'Module:IconUtils \'id\' must be specified.'
    end
    
    Icon = args.id .. '_Icon.png'
    
    -- Gestion de la taille
    if args.size == nil or args.size == '' then
        IconSize = 28
    else
        IconSize = args.size
    end
    
    -- Gestion du style
    if args.style == nil or args.style == '' then
        IconStyle = '1'
    else
        IconStyle = args.style
    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
            DisplayName = args.id
        end
    else
        DisplayName = args.name
    end
    
    -- Gestion du lien
    if args.link == nil or args.link == '' then
        IconLink = ''
    else
        IconLink = '[[' .. args.link .. ']]'
    end
    
    if args.link == '1' then
        IconLink = '[[' .. DisplayName .. ']]'
    end
    
    -- 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
        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