Basculer le menu
Changer de menu des préférences
Basculer le menu personnel
Non connecté(e)
Votre adresse IP sera visible au public si vous faites des modifications.

« Module:Infobox/Core » : différence entre les versions

De Nefald
Hiob (discussion | contributions)
Page créée avec « local p = {} function p.build(args, config) if not config then return '<div class="error">Configuration manquante pour ce type d\'infobox</div>' end -- Création de la table principale local html = mw.html.create('table') :addClass('infobox_v2') :attr('cellspacing', '7') -- Titre principal avec classe spécifique local nom = args.nom or mw.title.getCurrentTitle().text if nom and nom ~= '' then... »
Balises : Modification par mobile Modification par le web mobile
 
Hiob (discussion | contributions)
Aucun résumé des modifications
Balises : Modification par mobile Modification par le web mobile
Ligne 6 : Ligne 6 :
     end
     end
      
      
     -- Création de la table principale
     -- Création de la table principale avec la classe CSS appropriée
     local html = mw.html.create('table')
     local html = mw.html.create('table')
         :addClass('infobox_v2')
         :addClass('infobox-table')
        :attr('cellspacing', '7')
      
      
     -- Titre principal avec classe spécifique
     -- Titre principal (nom)
     local nom = args.nom or mw.title.getCurrentTitle().text
     local nom = args.nom or mw.title.getCurrentTitle().text
     if nom and nom ~= '' then
     if nom and nom ~= '' then
        local headerClass = 'entete ' .. (config.headerClass or 'monde')
        local headerStyle = string.format(
            'background-color:%s; color:#fff; font-size:1.4em; text-shadow:0.1em 0.1em 0.1em #000',
            config.headerColor or '#86C705'
        )
       
         html:tag('tr')
         html:tag('tr')
             :tag('th')
             :tag('th')
             :attr('colspan', '2')
             :attr('colspan', '2')
             :addClass(headerClass)
             :addClass('infobox-table-name')
            :cssText(headerStyle)
             :wikitext(nom)
             :wikitext(nom)
     end
     end
Ligne 50 : Ligne 42 :
          
          
         html:tag('tr')
         html:tag('tr')
            :attr('id', 'infobox-table-img-bg')
             :tag('td')
             :tag('td')
             :attr('colspan', '5')
             :attr('colspan', '2')
             :cssText('font-size: smaller; text-align: center;')
             :addClass('infobox-table-img')
             :wikitext(string.format('[[Fichier:%s|%s|%s]]', args.image, imageSize, caption))
             :wikitext(string.format('[[Fichier:%s|%s|%s]]', args.image, imageSize, caption))
     end
     end
Ligne 65 : Ligne 58 :
         local field = p.findField(config.fields, fieldKey)
         local field = p.findField(config.fields, fieldKey)
         if field and args[fieldKey] and args[fieldKey] ~= '' then
         if field and args[fieldKey] and args[fieldKey] ~= '' then
             if not field.optional or (field.optional and args[fieldKey] ~= '') then
             hasContent = true
                hasContent = true
            break
                break
            end
         end
         end
     end
     end
Ligne 75 : Ligne 66 :
      
      
     -- Ajouter le titre de section
     -- Ajouter le titre de section
     html:tag('tr')
     if section.title then
        :tag('th')
        html:tag('tr')
        :attr('colspan', '2')
            :tag('th')
        :addClass('infoboxcat')
            :attr('colspan', '2')
        :cssText('text-align:center; background-color:transparent; padding:3px; margin-top: 20px; border-bottom:1px solid #ccc; color:#099DFF;')
            :wikitext(section.title)
        :wikitext(section.title)
    end
      
      
     -- Ajouter les champs de la section
     -- Ajouter les champs de la section
     for _, fieldKey in ipairs(section.fields) do
     for _, fieldKey in ipairs(section.fields) do
         local field = p.findField(config.fields, fieldKey)
         local field = p.findField(config.fields, fieldKey)
         if field then
         if field and args[fieldKey] and args[fieldKey] ~= '' then
             p.addField(html, args, field, fieldKey)
             p.addField(html, args, fieldKey, field)
         end
         end
     end
     end
end
end


function p.addField(html, args, field, fieldKey)
function p.addField(html, args, fieldKey, field)
     local value = args[fieldKey]
     local value = args[fieldKey]
    if not value or value == '' then return end
      
      
     -- Champs spéciaux avec conditions
     -- Traitement spécial pour les coordonnées
     if fieldKey == 'coordonnees' or fieldKey == 'spawn' then
     if fieldKey == 'coordonnees' and args.x and args.y and args.z then
        if args.x and args.y and args.z then
        value = string.format(
            local worldName = args.monde or 'Harlan2'
             '[https://map.nefald.fr/?worldname=Harlan2&mapname=surface&zoom=4&x=%s&y=%s&z=%s %s, %s, %s]',
            local linkText = string.format('%s, %s, %s', args.x, args.y, args.z)
            args.x, args.y, args.z, args.x, args.y, args.z
             local mapUrl = string.format(
         )
                'https://map.nefald.fr/?worldname=%s&mapname=surface&zoom=4&x=%s&y=%s&z=%s',
                worldName, args.x, args.y, args.z
            )
            value = string.format("''[%s %s]''", mapUrl, linkText)
         else
            return -- Pas de coordonnées complètes
        end
     end
     end
      
      
     -- Vérifier si le champ doit être affiché
     -- Traitement spécial pour les liens wiki
     if not value or value == '' then
     if field.link then
        if field.optional then
        value = '[[' .. value .. ']]'
            return -- Champ optionnel vide, on l'ignore
        end
     end
     end
      
      
    -- Formatage spécial pour certains champs
    if field.format then
        if field.format == 'seed' then
            value = string.format('<span style="color:#099DFF;">\'\'%s\'\'</span>', value)
        elseif field.format == 'link' and value then
            value = string.format('[[%s]]', value)
        end
    end
   
    -- Ajouter la ligne du champ
     local row = html:tag('tr')
     local row = html:tag('tr')
     row:tag('th')
     row:tag('td'):wikitext(field.label)
        :attr('scope', 'row')
     row:tag('td'):wikitext(value)
        :wikitext(field.label)
     row:tag('td')
        :wikitext(value or '')
end
end


function p.addCustomFields(html, args)
function p.addCustomFields(html, args)
     -- Champs personnalisés (champ1/valeur1, champ2/valeur2, etc.)
     -- Champs personnalisés (champ1/valeur1, champ2/valeur2, etc.)
     for i = 1, 10 do
     for i = 1, 5 do
         local champKey = 'champ' .. i
         local champKey = 'champ' .. i
         local valeurKey = 'valeur' .. i
         local valeurKey = 'valeur' .. i
          
          
         if args[champKey] and args[valeurKey] and args[champKey] ~= '' and args[valeurKey] ~= '' then
         if args[champKey] and args[valeurKey] and  
          args[champKey] ~= '' and args[valeurKey] ~= '' then
             local row = html:tag('tr')
             local row = html:tag('tr')
             row:tag('th')
             row:tag('td'):wikitext(args[champKey])
                :attr('scope', 'row')
             row:tag('td'):wikitext(args[valeurKey])
                :wikitext(args[champKey])
             row:tag('td')
                :wikitext(args[valeurKey])
         end
         end
    end
end
-- Fonction pour ajouter des images spéciales (comme carte)
function p.addSpecialImage(html, args, imageKey, sizeKey, captionKey)
    if args[imageKey] and args[imageKey] ~= '' then
        local imageSize = args[sizeKey] or '280x200px'
        local caption = args[captionKey] or mw.title.getCurrentTitle().text
       
        html:tag('tr')
            :tag('td')
            :attr('colspan', '5')
            :cssText('font-size: smaller; text-align: center;')
            :wikitext(string.format('[[Fichier:%s|%s|%s]]', args[imageKey], imageSize, caption))
     end
     end
end
end


function p.findField(fields, key)
function p.findField(fields, key)
    if not fields then return nil end
     for _, field in ipairs(fields) do
     for _, field in ipairs(fields) do
         if field.key == key then
         if field.key == key then