Module:HeroList
From Heroes of Might and Magic: Olden Era Official Wiki
Description
This module generates an automated table of heroes belonging to a specific faction. It dynamically retrieves localization for hero names, classes, and specializations, and formats the starting skills and spells into a clean, sortable layout.
Usage
The module is invoked via the display function:
{{#invoke:HeroList|display|faction=...|language=...}}
Parameters
| Parameter | Description | Example |
|---|---|---|
faction |
The name of the faction (as stored in the Translation table). | faction=Necropolis
|
language |
Forces the Wiki language (if omitted, it detects the page suffix). | language=fr
|
Key Features
- Dynamic Localization: Translates headers (Name, Class, etc.) and hero-specific data (Names, Skills, Spells) based on the provided language.
- Automatic Formatting:
- Displays hero portraits and icons.
- Formats specializations with tooltips showing descriptions.
- Lists starting skills and spells as link-lists with icons.
- Sorting Support: The table uses the
sortableclass, allowing users to reorder heroes based on columns. - Data Cleanup: Automatically filters out campaign, tutorial, and internal testing heroes (e.g.,
cm_fun).
Implementation Example
To display all heroes of the "Necropolis" faction:
== Necropolis Heroes ==
{{#invoke:HeroList|display|faction=Necropolis}}
Technical Notes
- The module queries the
Herotable and joins data with theTranslationtable. - It uses
sortabletables; ensure the MediaWiki "Sortable" extension is active for full functionality. - Specialization icons are automatically inferred from the
HeroSpecializationtable and formatted to match faction naming conventions.
Examples
{{#invoke:HeroList|display|faction=Necropolis}}
| Portrait | Nom | Classe | Icône | Spécialisation | Compétences | Sort(s) |
|---|
{{#invoke:HeroList|display|faction=Grove|language=ja}}
| Portrait | Nom | Classe | Icône | Spécialisation | Compétences | Sort(s) |
|---|
local p = {}
-- Fonction pour récupérer les traductions en masse
local function getTrans(target_ids, lang)
local results = {}
if #target_ids == 0 then return results end
local query = mw.ext.cargo.query("Translation", "target_id, language, name, description", {
where = string.format("target_id IN ('%s')", table.concat(target_ids, "','")),
})
for _, row in ipairs(query) do
if not results[row.target_id] then results[row.target_id] = {} end
results[row.target_id][row.language] = {name = row.name, desc = row.description}
end
return results
end
function p.display(frame)
local faction = frame.args.faction
local lang = frame.args.lang or mw.language.getContentLanguage():getCode()
local heroes = mw.ext.cargo.query("Hero", "id, name_sid, class_id, specialization_id, start_skills, start_magics", {
where = string.format("faction = '%s'", faction), orderBy = "id"
})
-- Préparation des IDs pour une seule requête de traduction
local ids_to_translate = {}
for _, h in ipairs(heroes) do
table.insert(ids_to_translate, h.name_sid)
table.insert(ids_to_translate, h.specialization_id)
-- Ajout des skills
for skill in string.gmatch(h.start_skills or "", "([^,]+)") do
table.insert(ids_to_translate, skill .. "_name")
end
end
local trans = getTrans(ids_to_translate, lang)
local html = {'{| class="wikitable sortable"', '! Portrait !! Nom !! Classe !! Icône !! Spécialisation !! Compétences !! Sort(s)'}
for _, h in ipairs(heroes) do
local name = (trans[h.name_sid] and (trans[h.name_sid][lang] or trans[h.name_sid]['en'])) and trans[h.name_sid][lang].name or h.id
local class_name = trans[h.class_id] and trans[h.class_id][lang].name or h.class_id
local spec_name = trans[h.specialization_id] and trans[h.specialization_id][lang].name or "???"
table.insert(html, "|-")
-- Portrait (Nom en anglais requis pour le fichier)
table.insert(html, string.format('| [[File:%s.png|70px]]', trans[h.name_sid]['en'].name))
table.insert(html, string.format('| [[%s|%s]]', name, name))
table.insert(html, string.format('| %s', class_name))
table.insert(html, string.format('| [[File:%s Specialization Icon.png|64px]]', h.id)) -- Règle icône spec
table.insert(html, string.format('| \'\'\'%s\'\'\'<br><small>(++++)</small>', spec_name))
-- Skills
local skill_cell = ""
for skill_id in string.gmatch(h.start_skills or "", "([^,]+)") do
local s_name = trans[skill_id .. "_name"] and trans[skill_id .. "_name"][lang].name or skill_id
skill_cell = skill_cell .. string.format('[[File:Skill %s.png|28px]] %s<br>', s_name, s_name)
end
table.insert(html, "| " .. skill_cell)
table.insert(html, string.format('| %s', h.start_magics or ""))
table.insert(html, "|-")
end
table.insert(html, "|}")
return table.concat(html, "\n")
end
return p


