Module:HeroTable/fr: Difference between revisions
From Heroes of Might and Magic: Olden Era Official Wiki
Created page with "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.</stro..." |
No edit summary |
||
| (8 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- Chargement des | -- Chargement de la base de données des héros | ||
local heroesData = require('Module:HeroData/fr') | local heroesData = require('Module:HeroData/fr') | ||
function p. | -- Fonction principale pour générer toutes les lignes du tableau | ||
-- Récupère | function p.renderTable(frame) | ||
local args | -- Récupère l'argument de faction s'il est spécifié (ex: {{#invoke:HeroTable/fr|renderTable|faction=Temple}}) | ||
local targetFaction = frame.args.faction or frame:getParent().args.faction | |||
if | if type(heroesData) ~= "table" then | ||
return "<strong class='error'>Erreur : Le | return "<strong class='error'>Erreur critique : Le Module:HeroData/fr n'a pas pu être chargé.</strong>" | ||
end | end | ||
local | -- --- MODIFICATION : TRI PAR HERO_ID --- | ||
-- On crée une table contenant des sous-tables { name = "NomEn", id = 123 } | |||
local sortedHeroes = {} | |||
for heroKey, heroData in pairs(heroesData) do | |||
-- Sécurité : conversion de l'ID en nombre, s'il n'existe pas ou est invalide, on met 999 | |||
local idValue = tonumber(heroData.hero_id) or 999 | |||
table.insert(sortedHeroes, { name = heroKey, id = idValue }) | |||
end | end | ||
-- | -- Algorithme de tri personnalisé basé sur la valeur du ID numérique | ||
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] | |||
if | -- Si on a demandé une faction spécifique, on filtre les autres | ||
if not targetFaction or targetFaction == "" or data.faction == targetFaction then | |||
-- Préparation des variables de base | |||
local icon = data.icon or (heroName .. ".png") | |||
local name_fr = data.name_fr or heroName | |||
local class = data.class or "" | |||
local class_fr = data.class_fr or class | |||
-- 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 .. "|70px|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" | |||
-- Colonne 3 : Classe | |||
wiki = wiki .. "|style='text-align:center;'|[[" .. class .. "/fr|" .. class_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 "" | |||
-- Colonne 4 : Icône Spécialisation | |||
wiki = wiki .. "|style='padding:0.25em 0.25em; border-right:0px; text-align:center;'|[[File:" .. spec_icon .. "|64px]]\n" | |||
-- Colonne 5 : Nom + Desc courte + Infobulle (tt) pour la version longue | |||
wiki = wiki .. "|style='border-left:0px; text-align:left;'|'''" .. spec_name .. "'''<br/>" .. spec_short .. " <sup>''(<span class='explain' title=\"" .. spec_full:gsub('"', '"') .. "\">plus d'infos</span>)''</sup>\n" | |||
else | |||
wiki = wiki .. "|style='padding:0.25em 0.25em; border-right:0px;'|\n|style='border-left:0px;'|\n" | |||
end | |||
-- Colonne 6 : 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 7 : 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 | ||
end | end | ||
Latest revision as of 14:43, 23 May 2026
Documentation for this module may be created at Module:HeroTable/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 l'argument de faction s'il est spécifié (ex: {{#invoke:HeroTable/fr|renderTable|faction=Temple}})
local targetFaction = frame.args.faction or frame:getParent().args.faction
if type(heroesData) ~= "table" then
return "<strong class='error'>Erreur critique : Le Module:HeroData/fr n'a pas pu être chargé.</strong>"
end
-- --- MODIFICATION : TRI PAR HERO_ID ---
-- On crée une table contenant des sous-tables { name = "NomEn", id = 123 }
local sortedHeroes = {}
for heroKey, heroData in pairs(heroesData) do
-- Sécurité : conversion de l'ID en nombre, s'il n'existe pas ou est invalide, on met 999
local idValue = tonumber(heroData.hero_id) or 999
table.insert(sortedHeroes, { name = heroKey, id = idValue })
end
-- Algorithme de tri personnalisé basé sur la valeur du ID numérique
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]
-- Si on a demandé une faction spécifique, on filtre les autres
if not targetFaction or targetFaction == "" or data.faction == targetFaction then
-- Préparation des variables de base
local icon = data.icon or (heroName .. ".png")
local name_fr = data.name_fr or heroName
local class = data.class or ""
local class_fr = data.class_fr or class
-- 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 .. "|70px|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"
-- Colonne 3 : Classe
wiki = wiki .. "|style='text-align:center;'|[[" .. class .. "/fr|" .. class_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 ""
-- Colonne 4 : Icône Spécialisation
wiki = wiki .. "|style='padding:0.25em 0.25em; border-right:0px; text-align:center;'|[[File:" .. spec_icon .. "|64px]]\n"
-- Colonne 5 : Nom + Desc courte + Infobulle (tt) pour la version longue
wiki = wiki .. "|style='border-left:0px; text-align:left;'|'''" .. spec_name .. "'''<br/>" .. spec_short .. " <sup>''(<span class='explain' title=\"" .. spec_full:gsub('"', '"') .. "\">plus d'infos</span>)''</sup>\n"
else
wiki = wiki .. "|style='padding:0.25em 0.25em; border-right:0px;'|\n|style='border-left:0px;'|\n"
end
-- Colonne 6 : 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 7 : 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


