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 sortable class, 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 Hero table and joins data with the Translation table.
  • It uses sortable tables; ensure the MediaWiki "Sortable" extension is active for full functionality.
  • Specialization icons are automatically inferred from the HeroSpecialization table and formatted to match faction naming conventions.

Examples

{{#invoke:HeroList|display|faction=Necropolis}}

Lua error at line 1: attempt to index global 'p' (a nil value).

{{#invoke:HeroList|display|faction=Grove|language=ja}}

Lua error at line 1: attempt to index global 'p' (a nil value).


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"
    
    -- Récupération dynamique des en-têtes
    local h_name   = getWikiTrans("wiki_name", lang) or "Name"
    local h_class  = getWikiTrans("wiki_hero_class", lang) or "Class"
    local h_spec   = getWikiTrans("wiki_hero_spec", lang) or "Specialization" -- Utilise ton ID de spec
    local h_skills = getTrans("starting_skills", lang, "ui") or "Starting Skills"
    local h_spells = getTrans("starting_spells", lang, "ui") or "Starting Spells"
    
    -- ... (reste de la logique de requête Cargo identique) ...
    
    -- Construction du tableau (5 colonnes au lieu de 7)
    local html = {'{| class="wikitable sortable" style="width:100%"'}
    table.insert(html, string.format('! %s !! %s !! %s !! %s !! %s', 
        h_name, h_class, h_spec, h_skills, h_spells))
    
    for _, h in ipairs(heroes) do
        -- ... (récupération des variables name, file_name, class_name, spec_icon, spec_formatted, etc.)
        
        -- CONSTRUCTION DE LA LIGNE FUSIONNÉE
        table.insert(html, "|-")
        
        -- Colonne 1 : Portrait + Nom
        table.insert(html, string.format('| [[File:%s.png|70px|left]] [[%s/%s|%s]]', 
            file_name, file_name, lang, name))
            
        -- Colonne 2 : Classe
        table.insert(html, string.format('| [[%s/%s|%s]]', class_name_en, lang, class_name))
        
        -- Colonne 3 : Icône + Spécialisation
        table.insert(html, "| " .. spec_icon .. " " .. spec_formatted)
        
        -- Colonne 4 : Compétences
        table.insert(html, "| " .. table.concat(skills_html, "<br>"))
        
        -- Colonne 5 : Sorts
        table.insert(html, "| " .. table.concat(spells_html, "<br>"))
    end
    
    table.insert(html, "|}")
    return table.concat(html, "\n")
end