« 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 IconTextLine = ''
    local IconTextBr = ''
 
     local args = Utils.normalise(param)
     local args = Utils.normalise(param)


    -- Vérifie qu'on a au moins un id
     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


     -- Détermine le nom automatiquement
    local Icon = args.id .. "_Icon.png"
     local defaultLang = 'French'
    local IconSize = args.size and args.size ~= '' and args.size or 28
    local IconStyle = args.style and args.style ~= '' and args.style or '1'
 
     -- ==========================
    -- Récupération nom auto
     -- ==========================
     local name = args.name
     local name = args.name
    local link = args.link
    local defaultLang = "French"


     if not name or name == '' then
     if not name or name == '' or not link or link == '' then
         -- Essaie de récupérer le nom depuis args[defaultLang]
         for _, item in pairs(ItemData) do
        if args[defaultLang] and args[defaultLang] ~= '' then
            if type(item) == "table" and item.ID == args.id and item.Name then
            name = args[defaultLang]
                local fr = item.Name[defaultLang]
        elseif args['English'] and args['English'] ~= '' then
                local en = item.Name['English']
            name = args['English']
 
        else
                if (not name or name == '') then
            name = args.id
                    if fr and fr ~= '' then
                        name = fr
                    elseif en and en ~= '' then
                        name = en
                    else
                        name = args.id
                    end
                end
 
                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
     end
     end


     Icon = args.id .. '_Icon.png'
     if not name or name == '' then name = args.id end
    if not link or link == '' then link = name end


     if args.size == nil or args.size == '' then IconSize = 28 else IconSize = args.size end
     -- Construit le lien final
     if args.style == nil or args.style == '' then IconStyle = '1' else IconStyle = args.style end
    local IconLink = '[[' .. link .. ']]'
    if args.link == nil or args.link == '' then IconLink = '' else IconLink = '[[' .. args.link .. ']]' end 
    local IconTextLine = '  ' .. IconLink
     if args.link == '1' then IconLink = '[[' .. name .. ']]' end
    local IconTextBr  = '<br>' .. IconLink
     if IconLink == '' then  
 
         IconTextLine = ' ' .. name
     if IconStyle == '1' then
        IconTextBr = '<br>' .. name
        return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]'
    else
    elseif IconStyle == '2' then
        IconTextLine = ' ' .. IconLink
        return '[[file:'.. Icon ..'|'.. IconSize ..'px|link='.. IconLink ..']]' .. IconTextLine
        IconTextBr = '<br>' .. IconLink
     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
    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
end


return p
return p

Version du 16 novembre 2025 à 10:21

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

local p = {}

function p.main(param)
    local Utils = require('Module:Utils')
    local ItemData = require('Module:ItemData') or {}
    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 ~= '' and args.size or 28
    local IconStyle = args.style and args.style ~= '' and args.style or '1'

    -- ==========================
    -- Récupération nom auto
    -- ==========================
    local name = args.name
    local link = args.link
    local defaultLang = "French"

    if not name or name == '' or not link or link == '' then
        for _, item in pairs(ItemData) do
            if type(item) == "table" and item.ID == args.id and item.Name then
                local fr = item.Name[defaultLang]
                local en = item.Name['English']

                if (not name or name == '') then
                    if fr and fr ~= '' then
                        name = fr
                    elseif en and en ~= '' then
                        name = en
                    else
                        name = args.id
                    end
                end

                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

    if not name or name == '' then name = args.id end
    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
        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