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 |
|---|---|---|---|---|---|
| Bulwark | Death Knight | File:Necro Hero 1 Specialization Icon.png | Built Different (+++++) |
||
| King-of-Kings | Death Knight | File:Necro Hero 2 Specialization Icon.png | Charismatic (+++++) |
||
| Onkos | Death Knight | File:Necro Hero 3 Specialization Icon.png | Perfect Puppets (+++++) |
||
| Kel'Ghul | Death Knight | File:Necro Hero 4 Specialization Icon.png | Dreadful War (+++++) |
||
| Natalida | Death Knight | File:Necro Hero 5 Specialization Icon.png | Part of a Pack (+++++) |
||
| Artorius Veritas | Death Knight | File:Necro Hero 6 Specialization Icon.png | Drive 'em Crazy (+++++) |
||
| Marl | Death Knight | File:Necro Hero 7 Specialization Icon.png | Languid Soil (+++++) |
||
| Tarius | Death Knight | File:Necro Hero 8 Specialization Icon.png | Undead Legion (+++++) |
||
| Zam | Death Knight | File:Necro Hero 9 Specialization Icon.png | Alchemist (+++++) |
||
| Mag | Necromancer | File:Necro Hero 10 Specialization Icon.png | Arcane Dominion (+++++) |
||
| Adahn | Necromancer | File:Necro Hero 11 Specialization Icon.png | Amnesiac (+++++) |
||
| Ethric | Necromancer | File:Necro Hero 12 Specialization Icon.png | Tomb-bound Will (+++++) |
||
| Guildmaster Klastor | Necromancer | File:Necro Hero 13 Specialization Icon.png | Bones Guild (+++++) |
||
| Shadespinner Oona | Necromancer | File:Necro Hero 14 Specialization Icon.png | Shadowmastery (+++++) |
||
| Laura | Necromancer | File:Necro Hero 15 Specialization Icon.png | Moldering (+++++) |
||
| Lord Rufus | Necromancer | File:Necro Hero 16 Specialization Icon.png | Wistful Nostalgia (+++++) |
||
| Funerella | Necromancer | File:Necro Hero 17 Specialization Icon.png | Undead Legion (+++++) |
||
| Milossa the Golden | Necromancer | File:Necro Hero 18 Specialization Icon.png | Wealthy (+++++) |
{{#invoke:HeroList|display|faction=Grove|language=ja}}
local p = {}
-- Fonction pour mettre la première lettre de chaque mot en majuscule
local function toTitleCase(str)
return str:gsub("(%a)([%w_]*)", function(first, rest)
return first:upper() .. rest:lower()
end)
end
-- Fonction utilitaire pour récupérer une traduction
local function getTrans(target_id, lang, type, field)
field = field or "name"
if not target_id or target_id == "" then return nil end
local query = mw.ext.cargo.query("Translation", field, {
where = string.format("target_id = '%s' AND language = '%s' AND type = '%s'", target_id, lang, type),
limit = 1
})
if not query or #query == 0 then
query = mw.ext.cargo.query("Translation", "name", {
where = string.format("target_id = '%s' AND language = 'en' AND type = '%s'", target_id, type),
limit = 1
})
end
return (query and #query > 0) and query[1][field] or nil
end
function p.display(frame)
local raw_faction = frame.args.faction
local lang = frame.args.language or mw.title.getCurrentTitle().text:match("/(%a%a)$") or "en"
local faction_query = mw.ext.cargo.query("Translation", "target_id", {
where = string.format("name = '%s' AND type = 'faction'", raw_faction),
limit = 1
})
local faction_id = (faction_query and #faction_query > 0) and faction_query[1].target_id or raw_faction
-- Ajout de start_skills à la requête
local heroes = mw.ext.cargo.query("Hero", "id, name_sid, class_id, specialization_id, start_skills", {
where = string.format("faction = '%s' AND id NOT LIKE '%%campaign%%' AND id NOT LIKE '%%tutorial%%' AND id NOT LIKE '%%cm_fun%%'", faction_id)
})
table.sort(heroes, function(a, b)
local numA = tonumber(a.id:match("(%d+)$")) or 0
local numB = tonumber(b.id:match("(%d+)$")) or 0
return numA < numB
end)
local html = {'{| class="wikitable sortable"', '! Portrait !! Nom !! Classe !! Icône !! Spécialisation !! Compétences'}
for _, h in ipairs(heroes) do
local name = getTrans(h.name_sid, lang, 'hero') or h.name_sid
local file_name = getTrans(h.name_sid, 'en', 'hero') or h.id
local class_name = getTrans(h.class_id, lang, 'hero_class') or h.class_id
-- SPÉCIALISATION
local spec_name = getTrans(h.specialization_id, lang, 'hero_specialization') or h.specialization_id
local spec_desc = getTrans(h.specialization_id, lang, 'hero_specialization', 'description') or "Pas de description"
local clean_desc = spec_desc:gsub("\n", " "):gsub("\r", " "):gsub('"', '"'):gsub("'", "'"):gsub("<", "<"):gsub(">", ">")
local icon_data = mw.ext.cargo.query("HeroSpecialization", "icon", {where = string.format("id = '%s'", h.specialization_id), limit = 1})
local icon_val = (icon_data and #icon_data > 0) and icon_data[1].icon or ""
local formatted_icon = toTitleCase(icon_val:gsub("_", " "))
local spec_icon = string.format("[[File:%s.png|70px|link=]]", formatted_icon)
local spec_formatted = string.format("'''%s'''<br><span title=\"%s\" style=\"cursor: help;\"><u>''(+++++)''</u></span>", spec_name, clean_desc)
-- COMPÉTENCES
local skills_html = {}
if h.start_skills then
for skill_id in string.gmatch(h.start_skills, "([^,]+)") do
local s_name = getTrans(skill_id, lang, 'skill') or skill_id
local s_name_en = getTrans(skill_id, 'en', 'skill') or skill_id
-- Formatage icône : "Skill_Nom_Anglais.png"
-- On remplace les espaces par des underscores
local icon_name = s_name_en:gsub("%s+", "_")
local s_icon = string.format("[[File:Skill_%s.png|25px|link=]]", icon_name)
table.insert(skills_html, s_icon .. " " .. s_name)
end
end
table.insert(html, "|-")
table.insert(html, string.format('| [[File:%s.png|70px]]', file_name))
table.insert(html, string.format('| [[%s|%s]]', file_name, name))
table.insert(html, "| " .. class_name)
table.insert(html, "| " .. spec_icon)
table.insert(html, "| " .. spec_formatted)
table.insert(html, "| " .. table.concat(skills_html, "<br>"))
end
table.insert(html, "|}")
return table.concat(html, "\n")
end
return p


