Module:HeroPage/fr
From Heroes of Might and Magic: Olden Era Official Wiki
Documentation for this module may be created at Module:HeroPage/fr/doc
local p = {}
-- Chargement des données brutes traduites
local heroesData = require('Module:HeroData/fr')
function p.renderInfobox(frame)
-- Récupère les arguments passés au Modèle (ex: {{Infobox Héros|Mila|army1count=10}})
local args = frame:getParent().args
local heroName = args[1] or args['name']
if not heroName or heroName == "" then
return "<strong class='error'>Erreur : Le nom du héros est manquant dans l'appel du modèle.</strong>"
end
-- Sécurité si la table est mal chargée
if type(heroesData) ~= "table" then
return "<strong class='error'>Erreur critique : Le Module:HeroData/fr n'a pas renvoyé une table valide.</strong>"
end
local data = heroesData[heroName]
if not data then
return "<strong class='error'>Erreur : Le héros '" .. heroName .. "' est introuvable dans le Module:HeroData/fr.</strong>"
end
-- --- 1. PRÉPARATION DES VARIABLES COMPOSÉES (LUA + WIKI) ---
local name_fr = data.name_fr or heroName
local faction = data.faction or ""
local faction_fr = data.faction_fr or faction
local class = data.class or ""
local class_fr = data.class_fr or class
-- Statistiques
local att = (data.attributes and data.attributes.attack) or 0
local def = (data.attributes and data.attributes.defense) or 0
local sp = (data.attributes and data.attributes.spellpower) or 0
local kn = (data.attributes and data.attributes.knowledge) or 0
-- Gestion dynamique de la ligne "Compétences de départ"
local skillsHTML = ""
if data.skill2 and data.skill2.en and data.skill2.en ~= "" then
-- Le héros a 2 compétences
skillsHTML = "!colspan=2 style='border: 1px solid #BCB096; background-color:#1E3758; color:white;'|[[Skills/fr|Compétences de départ]]\n|-\n" ..
"|colspan=2 style='color: white; border: 1px solid #BCB096; padding:4px;'|\n" ..
"<div>[[File:Skill " .. data.skill1.en .. ".png|50px|link=" .. data.skill1.en .. "/fr]] [[" .. data.skill1.en .. "/fr|" .. data.skill1.fr .. "]] (" .. (data.skill1.gender == "f" and "Basique" or "Basique") .. ")</div>\n" ..
"<div>[[File:Skill " .. data.skill2.en .. ".png|50px|link=" .. data.skill2.en .. "/fr]] [[" .. data.skill2.en .. "/fr|" .. data.skill2.fr .. "]] (" .. (data.skill2.gender == "f" and "Basique" or "Basique") .. ")</div>"
else
-- Le héros n'a qu'une seule compétence (Maîtrise avancée "Advanced")
skillsHTML = "!colspan=2 style='border: 1px solid #BCB096; background-color:#1E3758; color:white;'|[[Skills/fr|Compétence de départ]]\n|-\n" ..
"|colspan=2 style='color: white; border: 1px solid #BCB096; padding:4px;'|\n" ..
"<div>[[File:Skill Advanced " .. data.skill1.en .. ".png|50px|link=" .. data.skill1.en .. "/fr]] [[" .. data.skill1.en .. "/fr|" .. data.skill1.fr .. "]] (" .. (data.skill1.gender == "f" and "Avancée" or "Avancé") .. ")</div>"
end
-- Gestion dynamique de la ligne "Sorts de départ"
local spellsHTML = ""
if data.spells and #data.spells > 0 then
local label = (#data.spells > 1) and "Sorts de départ" or "Sort de départ"
spellsHTML = "!colspan=2 style='border: 1px solid #BCB096; background-color:#1E3758; color:white;'|[[Spells/fr|" .. label .. "]]\n|-\n" ..
"|colspan=2 style='color: white; border: 1px solid #BCB096; padding:4px;'|\n"
for _, spell in ipairs(data.spells) do
spellsHTML = spellsHTML .. "<div>[[File:" .. spell.en .. ".png|50px|link=" .. spell.en .. "/fr]] [[" .. spell.en .. "/fr|" .. spell.fr .. "]]</div>"
end
else
spellsHTML = "!colspan=2 style='border: 1px solid #BCB096; background-color:#1E3758; color:white;'|[[Spells/fr|Sort de départ]]\n|-\n" ..
"|colspan=2 style='color: white; border: 1px solid #BCB096; padding:4px;'|<div>Aucun.</div>"
end
-- Gestion dynamique de l'armée (Paramètres manuels du wiki)
local armyHTML = ""
if args.army1creature and args.army1creature ~= "" then
armyHTML = "!colspan=2 style='border: 1px solid #BCB096; background-color:#1E3758; color:white;'|Armée de départ\n|-\n" ..
"|colspan=2|\n{| style='width:100%; text-align:center;'\n|-\n" ..
"|style='width:25%;'|<div style='color: white; display:inline-block; margin:4px 8px; vertical-align:top; text-align:center;'>[[File:" .. args.army1creature .. "_icon.png|75px|link=" .. args.army1creature .. "/fr]]<br/><span style='font-size:1.1em; color:white;'>" .. (args.army1count or "") .. "</span></div>"
if args.army2creature and args.army2creature ~= "" then
armyHTML = armyHTML .. "||style='width:25%;'|<div style='color: white; display:inline-block; margin:4px 8px; vertical-align:top; text-align:center;'>[[File:" .. args.army2creature .. "_icon.png|75px|link=" .. args.army2creature .. "/fr]]<br/><span style='font-size:1.1em; color:white;'>" .. (args.army2count or "") .. "</span></div>"
end
if args.army3creature and args.army3creature ~= "" then
armyHTML = armyHTML .. "||style='width:25%;'|<div style='color: white; display:inline-block; margin:4px 8px; vertical-align:top; text-align:center;'>[[File:" .. args.army3creature .. "_icon.png|75px|link=" .. args.army3creature .. "/fr]]<br/><span style='font-size:1.1em; color:white;'>" .. (args.army3count or "") .. "</span></div>"
end
armyHTML = armyHTML .. "\n|}"
end
-- --- 2. CONSTRUCTION DE LA STRUCTURE DE L'INFOBOX ---
local wiki = "{| class=infobox style='margin:0em 1em 1em 1em; float:right; text-align: center; vertical-align: middle; width:25%; border-collapse: collapse; border: 1px solid #BCB096'\n" ..
"|-style='border-bottom: 1px solid #BCB096; background-color:#1E3758'\n" ..
"|colspan=2|\n{|style='width:100%; text-align: center; vertical-align: middle; border-collapse: collapse;'\n" ..
"|<span style='font-size: 150%; color:white;'>" .. name_fr .. "</span>\n" ..
"|}\n" ..
"|-style='border-bottom: 1px solid #BCB096'\n" ..
"|colspan=2|[[File:" .. heroName .. ".png|300px|link=]]\n" ..
"|-style='border-bottom: 1px solid #BCB096; background-color:#1E3758'\n" ..
"|style='border: 1px solid #BCB096; width:50%; color:white;'|[[Faction/fr|Faction]]||style='border: 1px solid #BCB096; width:50%; color:white;'|[[Class/fr|Classe]]\n" ..
"|-\n" ..
"|style='border: 1px solid #BCB096; padding:4px; width:50%;'|<div>[[File:" .. faction .. "_icon.png|x30px|link=" .. faction .. "/fr]][[" .. faction .. "/fr|" .. faction_fr .. "]]</div>||style='border: 1px solid #BCB096; padding:4px; width:50%;'|<div>[[File:" .. class .. ".png|x30px|link=" .. class .. "/fr]][[" .. class .. "/fr|" .. class_fr .. "]]</div>\n" ..
"|-style='border-bottom: 1px solid #BCB096; background-color:#1E3758'\n" ..
"|colspan=2 style='color:white;'|[[Hero Basics/fr#Attributs|Statistiques de départ]]\n" ..
"|-style='border-bottom: 1px solid #BCB096'\n" ..
"|colspan=2|\n" ..
"{|style='gap:8px; justify-content:space-between; align-items:center; width:100%;'\n" ..
"|style='color:white; text-align:center; width:25%;'|<div><div style='font-weight:bold; color:white;'>" .. att .. "</div><div style='margin-top:6px;'>[[File:Icon Stats Attack.png|28px|link=Hero_Basics/fr#Attributs]]<br><small>[[:Hero_Basics/fr#Attributs|Attaque]]</div></div>\n" ..
"|style='color:white; text-align:center; width:25%;'|<div><div style='font-weight:bold; color:white;'>" .. def .. "</div><div style='margin-top:6px;'>[[File:Icon Stats Defence.png|28px|link=Hero_Basics/fr#Attributs]]<br><small>[[:Hero_Basics/fr#Attributs|Défense]]</div></div>\n" ..
"|style='color:white; text-align:center; width:25%;'|<div><div style='font-weight:bold; color:white;'>" .. sp .. "</div><div style='margin-top:6px;'>[[File:Icon Stats Spellpower.png|28px|link=Hero_Basics/fr#Attributs]]<br><small>[[:Hero_Basics/fr#Attributs|P d S]]</div></div>\n" ..
"|style='color:white; text-align:center; width:25%;'|<div><div style='font-weight:bold; color:white;'>" .. kn .. "</div><div style='margin-top:6px;'>[[File:Icon Stats Inteligence.png|28px|link=Knowledge/fr]]<br><small>[[:Hero_Basics/fr#Attributs|Savoir]]</div></div>\n" ..
"|}\n" ..
"|-\n" .. skillsHTML .. "\n" ..
"|-\n" .. spellsHTML .. "\n" ..
"|-\n" .. armyHTML .. "\n" ..
"|}\n\n"
-- --- 3. SECTIONS HORS INFOBOX (TEXTES ET BIOGRAPHIE) ---
if args.tagline and args.tagline ~= "" then
wiki = wiki .. "{| class=\"quote\" cellspacing=\"0\" cellpadding=\"0\" style=\"padding:0; margin:.5em 1em .5em 1em; width:auto;\"\n" ..
"|style=\"padding:2.5px 10px; text-align:center\"|''" .. args.tagline .. "''<br>\n" ..
"|}\n"
end
if args.intro and args.intro ~= "" then
wiki = wiki .. args.intro .. "\n\n"
end
if args.biography and args.biography ~= "" then
wiki = wiki .. "==Biographie==\n" .. args.biography .. "\n\n"
end
-- --- 4. SECTION SPÉCIALISATION (DONNÉES AUTOMATIQUES) ---
if data.specialization then
local spec = data.specialization
local spec_icon = spec.icon or ""
local spec_name = spec.name_fr or ""
local spec_desc = spec.desc_full_fr or ""
wiki = wiki .. "==Spécialisation==\n" ..
"<div style='display: block; clear: left; overflow: hidden;'>\n" .. -- Empêche les bugs de collision
"{|style='border-collapse: collapse; border: 1px solid #BCB096; max-width: 70%; width: auto; margin: 8px 0px 8px;'\n" .. -- max-width évite d'écraser l'infobox de droite
"|-style='border: 1px solid #BCB096; background-color:#1E3758;'\n" ..
"| style='text-align:center; width:80px; vertical-align:middle; padding:5px' |[[File:" .. spec_icon .. "|70px]]|| style='padding:10px; color:white;' | <b>" .. spec_name .. "</b>\n" ..
"|-style='color: black;'\n" .. -- Forcé en noir pour la lisibilité sur fond blanc du wiki
"|style='padding:10px;' colspan=2|" .. spec_desc .. "\n" ..
"|}\n" ..
"</div>\n\n"
end
-- --- 5. STRATÉGIE ET ANECDOTE ---
wiki = wiki .. "==Stratégie==\n"
if args.strategy and args.strategy ~= "" then
wiki = wiki .. args.strategy .. "\n\n"
else
wiki = wiki .. "<span style=\"font-style: italic;\">à venir.</span>\n\n"
end
if args.trivia and args.trivia ~= "" then
wiki = wiki .. "==Anecdote==\n" .. args.trivia .. "\n"
end
return wiki
end
-- Fonction d'aide pour découper les chaînes (utilisée pour les sorts si besoin)
function p.split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
local i = 1
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
t[i] = str
i = i + 1
end
return t
end
return p


