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
 
(17 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
local p = {}
local p = {}


-- Table des chartes avec leurs couleurs spécifiques
-- Tableau des chartes pré-définies
local chartes = {
local chartes = {
biographie = {
  biographie = {
titre    = "#6eacdc9c",
    titre    = "#6eacdc9c",
soustitre = "#a9c8e09c",
    soustitre = "#a9c8e09c",
hr        = "#6eacdc9c",
    hr        = "#6eacdc9c",
},
  },
empire = {
  empire = {
titre    = "#993333b0",
    titre    = "#993333b0",
soustitre = "#831f1fc7",
    soustitre = "#831f1fc7",
hr        = "#993333b0",
    hr        = "#993333b0",
},
  },
geographie = {
  geographie = {
titre    = "#209a57d9",
    titre    = "#209a57d9",
soustitre = "#209a57a8",
    soustitre = "#209a57a8",
hr        = "#209a57d9",
    hr        = "#209a57d9",
},
  },
darkgods = {
  conflit = {
titre    = "#000000cc",
    titre    = "#B0C4DE",
soustitre = "#000000a3",
    soustitre = "#B0C4DE",
hr        = "#000000a3",
    hr        = "#B0C4DE",
color    = "#ffffff", -- seul cas avec texte blanc
  },
},
  darkgods = {
defaut = {
    titre    = "#000000",
titre    = "#eaecf0",
    soustitre = "#000000e8",
soustitre = "#a2a9b1",
    hr        = "#000000",
hr        = "#eaecf0",
    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",
  }
}
}


-- Table des titres automatiques des sous-titres selon la charte
-- 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 = {
local soustitres = {
biographie = "Informations biographiques",
  biographie = "Informations biographiques",
empire    = "Données impériales",
  empire    = "Données impériales",
geographie = "Informations géographiques",
  geographie = "Informations géographiques",
darkgods  = "Entité obscure",
  darkgods  = "Entité obscure",
defaut    = "Informations générales"
  defaut    = "Informations générales",
}
}


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


-- Fonction centrale pour récupérer une couleur selon la charte et le type
-- Fonction principale pour renvoyer une couleur selon charte et type, avec frame
local function couleurDirect(charte, type)
function p.couleur(frame)
charte = mw.ustring.lower(charte or "defaut")
  local args = (type(frame) == "table" and frame.args) or {}
type = type or "titre"
 
  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"


-- Cas spécial : couleur du texte
  -- Si l'utilisateur fournit un code hexadécimal direct
if type == "texte" then
  if isHexCode(couleurOuCharte) then
if chartes[charte] and chartes[charte].color then
    if typeCouleur == "texte" then
return chartes[charte].color
      return "#000000"
else
    else
return "" -- pas de couleur forcée = hérite du style global
      return couleurOuCharte
end
    end
end
  end


-- Si on passe un code hexadécimal directement
  -- Si type=texte et une couleur de texte personnalisée est définie
if isHexCode(charte) then
  if typeCouleur == "texte" then
return charte
    if chartes[couleurOuCharte] and chartes[couleurOuCharte].color then
end
      return chartes[couleurOuCharte].color
    else
      return "#000000"
    end
  end


-- Si la charte et le type existent dans la table
  -- Si type=soustitre
if chartes[charte] and chartes[charte][type] then
  if typeCouleur == "soustitre" then
return chartes[charte][type]
    if chartes[couleurOuCharte] and chartes[couleurOuCharte].soustitre then
end
      return chartes[couleurOuCharte].soustitre
    else
      return chartes["defaut"].soustitre
    end
  end


-- Sinon, retour vers la charte "defaut"
  -- Autres types (titre, hr, etc.)
return chartes["defaut"][type] or "#dddddd"
  if chartes[couleurOuCharte] and chartes[couleurOuCharte][typeCouleur] then
    return chartes[couleurOuCharte][typeCouleur]
  else
    return chartes["defaut"][typeCouleur] or "#000000"
  end
end
end


-- Fonction appelée via #invoke sur le wiki
-- Fonction alternative pour usage direct : getCouleur("charte", "type")
function p.couleur(frameOrCharte, typeOrNil)
function p.getCouleur(charteNom, typeCouleur)
if type(frameOrCharte) == "table" and frameOrCharte.args then
  charteNom = mw.ustring.lower(charteNom or "defaut")
local args = frameOrCharte.args
  typeCouleur = typeCouleur or "titre"
return couleurDirect(args["charte"], args["type"])
 
else
  if chartes[charteNom] and chartes[charteNom][typeCouleur] then
return couleurDirect(frameOrCharte, typeOrNil)
    return chartes[charteNom][typeCouleur]
end
  else
    return chartes["defaut"][typeCouleur] or "#000000"
  end
end
end


-- Fonction pour générer un nom de sous-titre automatique (si non défini dans le modèle)
-- Fonction pour renvoyer un texte de sous-titre par défaut
function p.soustitre(frame)
function p.soustitre(frame)
local charte = frame.args["charte"] or "defaut"
  local args = (type(frame) == "table" and frame.args) or {}
charte = mw.ustring.lower(charte)
  local charte = args["charte"] or "defaut"
return soustitres[charte] or soustitres["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