Aller au contenu

« Module:Charte » : différence entre les versions

De Wikiquestia
Aucun résumé des modifications
Balise : Révoqué
Aucun résumé des modifications
 
(34 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
local p = {}
local p = {}


-- Tableau des chartes pré-définies
local chartes = {
local chartes = {
   defaut = {
   biographie = {
     titre = "#ddd",
     titre     = "#6eacdc9c",
     hr = "#ccc",
    soustitre = "#a9c8e09c",
     header = "Informations générales",
    hr        = "#6eacdc9c",
  },
  empire = {
    titre    = "#993333b0",
    soustitre = "#831f1fc7",
    hr        = "#993333b0",
  },
  geographie = {
    titre    = "#209a57d9",
    soustitre = "#209a57a8",
     hr       = "#209a57d9",
  },
  conflit = {
     titre    = "#B0C4DE",
    soustitre = "#B0C4DE",
    hr        = "#B0C4DE",
  },
  darkgods = {
    titre    = "#000000",
    soustitre = "#000000e8",
    hr        = "#000000",
    color    = "#ffffff",
  },
  langue = {
    titre    = "#9b59b6b0",
    soustitre = "#a674c8a8",
    hr        = "#9b59b6b0",
   },
   },
   royaume = {
   royaume = {
     titre = "#995333",
     titre     = "#f0b58fb0", -- pêche pastel
     hr = "#d8c9b8",
    soustitre = "#f8caa89c",
     header = '[[Fichier:Drapeau_du_Royaume.png|50px|center]]<br>Informations du Royaume',
    hr        = "#f0b58fb0",
  },
  republique = {
    titre    = "#a4cbb3b0", -- vert pastel doux
    soustitre = "#b9ddc3a0",
    hr        = "#a4cbb3b0",
  },
  legendes = {
    titre    = "#cab2d6b0", -- lilas pastel
    soustitre = "#ddcae6a8",
    hr        = "#cab2d6b0",
  },
  federation = {
    titre    = "#89c7dab0", -- bleu ciel pastel
    soustitre = "#b3dce8a8",
    hr        = "#89c7dab0",
  },
  cite_naine = {
    titre    = "#c8c8c8b0", -- gris pastel
    soustitre = "#d9d9d9a8",
     hr       = "#c8c8c8b0",
  },
  cite_independante = {
    titre     = "#e6b8a2b0", -- terracotta pastel
    soustitre = "#f1cdb99c",
    hr        = "#e6b8a2b0",
  },
  ville_etat = {
    titre    = "#d4d1f0b0", -- lavande/gris bleuté pastel
    soustitre = "#e0dff79c",
    hr        = "#d4d1f0b0",
   },
   },
   biographie = {
   defaut = {
     titre = "#334455",
     titre     = "#eaecf0",
     hr = "#8899aa",
     soustitre = "#a2a9b1",
     header = '[[Fichier:Portrait_Biographie.jpg|40px|left]]<br>Infos biographiques',
     hr        = "#eaecf0",
   }
   }
}
}


-- Alias pour noms accentués (compatibilité avec les appels charte="cité-naine", etc.)
chartes["cité-naine"] = chartes.cite_naine
chartes["cité-indépendante"] = chartes.cite_independante
chartes["ville-état"] = chartes.ville_etat
-- Textes par défaut selon la charte
local soustitres = {
  biographie = "Informations biographiques",
  empire    = "Données impériales",
  geographie = "Informations géographiques",
  darkgods  = "Entité obscure",
  defaut    = "Informations générales",
}
-- Fonction pour détecter un code hex (#xxxxxx ou #xxxxxxx)
local function isHexCode(value)
  return type(value) == "string" and mw.ustring.match(value, "^#%x%x%x%x%x%x%x?$") ~= nil
end
-- Fonction principale pour renvoyer une couleur selon charte et type, avec frame
function p.couleur(frame)
function p.couleur(frame)
   local args = frame.args or {}
   local args = (type(frame) == "table" and frame.args) or {}
   local charte = args.charte or "defaut"
 
   local type_ = args.type or "titre"
   local couleurOuCharte = (args["couleur"] and args["couleur"] ~= "") and args["couleur"]
   if chartes[charte] and chartes[charte][type_] then
                      or (args["charte"] and args["charte"] ~= "") and args["charte"]
     return chartes[charte][type_]
                      or "defaut"
 
   local typeCouleur = args["type"] or "titre"
 
  -- Si l'utilisateur fournit un code hexadécimal direct
  if isHexCode(couleurOuCharte) then
    if typeCouleur == "texte" then
      return "#000000"
    else
      return couleurOuCharte
    end
  end
 
  -- Si type=texte et une couleur de texte personnalisée est définie
  if typeCouleur == "texte" then
    if chartes[couleurOuCharte] and chartes[couleurOuCharte].color then
      return chartes[couleurOuCharte].color
    else
      return "#000000"
    end
  end
 
  -- Si type=soustitre
  if typeCouleur == "soustitre" then
    if chartes[couleurOuCharte] and chartes[couleurOuCharte].soustitre then
      return chartes[couleurOuCharte].soustitre
    else
      return chartes["defaut"].soustitre
    end
  end
 
  -- Autres types (titre, hr, etc.)
   if chartes[couleurOuCharte] and chartes[couleurOuCharte][typeCouleur] then
     return chartes[couleurOuCharte][typeCouleur]
   else
   else
     return chartes.defaut[type_] or ""
     return chartes["defaut"][typeCouleur] or "#000000"
   end
   end
end
end


function p.header(frame)
-- Fonction alternative pour usage direct : getCouleur("charte", "type")
   local args = frame.args or {}
function p.getCouleur(charteNom, typeCouleur)
   local charte = args.charte or "defaut"
   charteNom = mw.ustring.lower(charteNom or "defaut")
   if chartes[charte] and chartes[charte].header then
   typeCouleur = typeCouleur or "titre"
     return chartes[charte].header
 
   if chartes[charteNom] and chartes[charteNom][typeCouleur] then
     return chartes[charteNom][typeCouleur]
   else
   else
     return chartes.defaut.header or ""
     return chartes["defaut"][typeCouleur] or "#000000"
   end
   end
end
-- Fonction pour renvoyer un texte de sous-titre par défaut
function p.soustitre(frame)
  local args = (type(frame) == "table" and frame.args) or {}
  local charte = args["charte"] or "defaut"
  charte = mw.ustring.lower(charte)
  return soustitres[charte] or soustitres["defaut"]
end
end


return p
return p

Dernière version du 21 juillet 2025 à 08:02

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

local p = {}

-- Tableau des chartes pré-définies
local chartes = {
  biographie = {
    titre     = "#6eacdc9c",
    soustitre = "#a9c8e09c",
    hr        = "#6eacdc9c",
  },
  empire = {
    titre     = "#993333b0",
    soustitre = "#831f1fc7",
    hr        = "#993333b0",
  },
  geographie = {
    titre     = "#209a57d9",
    soustitre = "#209a57a8",
    hr        = "#209a57d9",
  },
  conflit = {
    titre     = "#B0C4DE",
    soustitre = "#B0C4DE",
    hr        = "#B0C4DE",
  },
  darkgods = {
    titre     = "#000000",
    soustitre = "#000000e8",
    hr        = "#000000",
    color     = "#ffffff",
  },
  langue = {
    titre     = "#9b59b6b0",
    soustitre = "#a674c8a8",
    hr        = "#9b59b6b0",
  },
  royaume = {
    titre     = "#f0b58fb0", -- pêche pastel
    soustitre = "#f8caa89c",
    hr        = "#f0b58fb0",
  },
  republique = {
    titre     = "#a4cbb3b0", -- vert pastel doux
    soustitre = "#b9ddc3a0",
    hr        = "#a4cbb3b0",
  },
  legendes = {
    titre     = "#cab2d6b0", -- lilas pastel
    soustitre = "#ddcae6a8",
    hr        = "#cab2d6b0",
  },
  federation = {
    titre     = "#89c7dab0", -- bleu ciel pastel
    soustitre = "#b3dce8a8",
    hr        = "#89c7dab0",
  },
  cite_naine = {
    titre     = "#c8c8c8b0", -- gris pastel
    soustitre = "#d9d9d9a8",
    hr        = "#c8c8c8b0",
  },
  cite_independante = {
    titre     = "#e6b8a2b0", -- terracotta pastel
    soustitre = "#f1cdb99c",
    hr        = "#e6b8a2b0",
  },
  ville_etat = {
    titre     = "#d4d1f0b0", -- lavande/gris bleuté pastel
    soustitre = "#e0dff79c",
    hr        = "#d4d1f0b0",
  },
  defaut = {
    titre     = "#eaecf0",
    soustitre = "#a2a9b1",
    hr        = "#eaecf0",
  }
}

-- Alias pour noms accentués (compatibilité avec les appels charte="cité-naine", etc.)
chartes["cité-naine"] = chartes.cite_naine
chartes["cité-indépendante"] = chartes.cite_independante
chartes["ville-état"] = chartes.ville_etat

-- Textes par défaut selon la charte
local soustitres = {
  biographie = "Informations biographiques",
  empire     = "Données impériales",
  geographie = "Informations géographiques",
  darkgods   = "Entité obscure",
  defaut     = "Informations générales",
}

-- Fonction pour détecter un code hex (#xxxxxx ou #xxxxxxx)
local function isHexCode(value)
  return type(value) == "string" and mw.ustring.match(value, "^#%x%x%x%x%x%x%x?$") ~= nil
end

-- Fonction principale pour renvoyer une couleur selon charte et type, avec frame
function p.couleur(frame)
  local args = (type(frame) == "table" and frame.args) or {}

  local couleurOuCharte = (args["couleur"] and args["couleur"] ~= "") and args["couleur"]
                       or (args["charte"] and args["charte"] ~= "") and args["charte"]
                       or "defaut"

  local typeCouleur = args["type"] or "titre"

  -- Si l'utilisateur fournit un code hexadécimal direct
  if isHexCode(couleurOuCharte) then
    if typeCouleur == "texte" then
      return "#000000"
    else
      return couleurOuCharte
    end
  end

  -- Si type=texte et une couleur de texte personnalisée est définie
  if typeCouleur == "texte" then
    if chartes[couleurOuCharte] and chartes[couleurOuCharte].color then
      return chartes[couleurOuCharte].color
    else
      return "#000000"
    end
  end

  -- Si type=soustitre
  if typeCouleur == "soustitre" then
    if chartes[couleurOuCharte] and chartes[couleurOuCharte].soustitre then
      return chartes[couleurOuCharte].soustitre
    else
      return chartes["defaut"].soustitre
    end
  end

  -- Autres types (titre, hr, etc.)
  if chartes[couleurOuCharte] and chartes[couleurOuCharte][typeCouleur] then
    return chartes[couleurOuCharte][typeCouleur]
  else
    return chartes["defaut"][typeCouleur] or "#000000"
  end
end

-- Fonction alternative pour usage direct : getCouleur("charte", "type")
function p.getCouleur(charteNom, typeCouleur)
  charteNom = mw.ustring.lower(charteNom or "defaut")
  typeCouleur = typeCouleur or "titre"

  if chartes[charteNom] and chartes[charteNom][typeCouleur] then
    return chartes[charteNom][typeCouleur]
  else
    return chartes["defaut"][typeCouleur] or "#000000"
  end
end

-- Fonction pour renvoyer un texte de sous-titre par défaut
function p.soustitre(frame)
  local args = (type(frame) == "table" and frame.args) or {}
  local charte = args["charte"] or "defaut"
  charte = mw.ustring.lower(charte)
  return soustitres[charte] or soustitres["defaut"]
end

return p