Module:HeroTableSimple/fr
From Heroes of Might and Magic: Olden Era Official Wiki
Documentation for this module may be created at Module:HeroTableSimple/fr/doc
local p = {}
-- Chargement de la base de données des héros
local heroesData = require('Module:HeroData/fr')
-- Fonction principale pour générer toutes les lignes du tableau
function p.renderTable(frame)
-- Récupère les arguments passés au invoke ou au modèle parent
local args = frame.args
local parentArgs = frame:getParent().args
-- Récupère les arguments de tri/filtrage
local targetFaction = args.faction or parentArgs.faction
local targetClass = args.class or parentArgs.class -- <-- AJOUTÉ : Détection de la classe
if type(heroesData) ~= "table" then
return "<strong class='error'>Erreur critique : Le Module:HeroData/fr n'a pas pu être chargé.</strong>"
end
-- --- TRI PAR HERO_ID ---
local sortedHeroes = {}
for heroKey, heroData in pairs(heroesData) do
local idValue = tonumber(heroData.hero_id) or 999
table.insert(sortedHeroes, { name = heroKey, id = idValue })
end
table.sort(sortedHeroes, function(a, b)
if a.id ~= b.id then
return a.id < b.id -- Trie du plus petit ID au plus grand
else
return a.name < b.name -- En cas d'IDs identiques, trie par ordre alphabétique
end
end)
local wiki = ""
-- On parcourt tous les héros triés par leur ID
for _, sortedData in ipairs(sortedHeroes) do
local heroName = sortedData.name
local data = heroesData[heroName]
-- --- APPLICATION DES FILTRES (FACTION & CLASSE) ---
local matchFaction = (not targetFaction or targetFaction == "" or data.faction == targetFaction)
local matchClass = (not targetClass or targetClass == "" or data.class == targetClass or data.class_fr == targetClass) -- <-- AJOUTÉ
-- On n'affiche le héros que s'il valide les filtres actifs
if matchFaction and matchClass then -- <-- MODIFIÉ
-- Préparation des variables de base
local icon = data.icon or (heroName .. ".png")
local name_fr = data.name_fr or heroName
-- Début de la ligne du tableau
wiki = wiki .. "|-\n"
-- Colonne 1 : Image du héros
wiki = wiki .. "|style='padding:0.25em 0; border-right:0px; text-align:center;'|[[File:" .. icon .. "|50px|link=" .. heroName .. "/fr]]\n"
-- Colonne 2 : Nom du héros (avec lien interne)
wiki = wiki .. "|style='border-left:0px; text-align:left;'|[[" .. heroName .. "/fr|" .. name_fr .. "]]\n"
-- Colonnes Spécialisation
if data.specialization then
local spec = data.specialization
local spec_icon = spec.icon or ""
local spec_name = spec.name_fr or ""
local spec_short = spec.desc_short_fr or ""
local spec_full = spec.desc_full_fr or ""
-- Fusion visuelle pour s'accorder avec l'en-tête (Icône incluse dans la cellule)
wiki = wiki .. "|style='text-align:left;'|[[File:" .. spec_icon .. "|40px|vertical-align:middle; margin-right:4px;]] '''" .. spec_name .. "'''<br/>" .. spec_short .. " <sup>''(<span class='explain' title=\"" .. spec_full:gsub('"', '"') .. "\">plus d'infos</span>)''</sup>\n"
else
wiki = wiki .. "|style='text-align:left;'|\n"
end
-- Colonne 4 : Compétences
if data.skill2 and data.skill2.en and data.skill2.en ~= "" then
local sk1_en = data.skill1.en or ""
local sk1_fr = data.skill1.fr or ""
local sk2_en = data.skill2.en or ""
local sk2_fr = data.skill2.fr or ""
wiki = wiki .. "|style='border-left:0px; text-align:left;'|[[File:Skill " .. sk1_en .. ".png|28px]] [[" .. sk1_en .. "/fr|" .. sk1_fr .. "]]<br/>[[File:Skill " .. sk2_en .. ".png|28px]] [[" .. sk2_en .. "/fr|" .. sk2_fr .. "]]\n"
else
local sk1_en = data.skill1.en or ""
local sk1_fr = data.skill1.fr or ""
wiki = wiki .. "|style='border-left:0px; text-align:left;'|[[File:Skill Advanced " .. sk1_en .. ".png|28px]] [[" .. sk1_en .. "/fr|" .. sk1_fr .. "]]\n"
end
-- Colonne 5 : Sorts de départ
wiki = wiki .. "|style='text-align:left; border-left:0px;'|"
if data.spells and #data.spells > 0 then
for i, spell in ipairs(data.spells) do
if i > 1 then wiki = wiki .. "<br/>" end
wiki = wiki .. "[[File:" .. spell.en .. ".png|24px]] [[" .. spell.en .. "/fr|" .. spell.fr .. "]]"
end
end
wiki = wiki .. "\n"
end
end
return wiki
end
return p


