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éc. | Spécialisation | Compétences | Sort(s) |
|---|
{{#invoke:HeroList|display|faction=Grove|language=ja}}
| Portrait | Nom | Classe | Icône Spéc. | Spécialisation | Compétences | Sort(s) |
|---|
local p = {}
-- Fonction de récupération simplifiée
local function getTrans(target_id, lang)
local query = mw.ext.cargo.query("Translation", "name", {
where = string.format("target_id = '%s' AND language = '%s'", target_id, lang),
limit = 1
})
if query and #query > 0 then return query[1].name end
-- Fallback en anglais si la langue n'est pas trouvée
local fallback = mw.ext.cargo.query("Translation", "name", {
where = string.format("target_id = '%s' AND language = 'en'", target_id),
limit = 1
})
if fallback and #fallback > 0 then return fallback[1].name end
return nil -- Aucune traduction trouvée
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, icon", {
where = string.format("faction = '%s'", faction), orderBy = "id"
})
local html = {'{| class="wikitable sortable"', '! Portrait !! Nom !! Classe !! Icône Spéc. !! Spécialisation !! Compétences !! Sort(s)'}
for _, h in ipairs(heroes) do
local name = getTrans(h.name_sid, lang) or h.id
local class_name = getTrans(h.class_id, lang) or h.class_id
local spec_name = getTrans(h.specialization_id, lang) or "Spec"
table.insert(html, "|-")
table.insert(html, string.format('| [[File:%s.png|70px]]', getTrans(h.name_sid, 'en') or h.id))
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))
table.insert(html, string.format('| \'\'\'%s\'\'\'', spec_name))
-- Skills (on traite chaque skill)
local skill_cell = ""
for skill_id in string.gmatch(h.start_skills or "", "([^,]+)") do
local s_name = getTrans(skill_id .. "_name", lang) or skill_id
skill_cell = skill_cell .. string.format('[[File:Skill %s.png|28px]] %s<br>', (getTrans(skill_id .. "_name", 'en') or skill_id), s_name)
end
table.insert(html, "| " .. skill_cell)
table.insert(html, string.format('| %s', h.start_magics or ""))
end
table.insert(html, "|}")
return table.concat(html, "\n")
end
return p


