Module:HeroList

From Heroes of Might and Magic: Olden Era Official Wiki
Revision as of 14:01, 30 May 2026 by akesha.taladim (talk | contribs) (Created page with "local p = {} -- Fonction utilitaire pour récupérer les traductions en masse local function getTranslations(target_ids, lang) local results = {} if #target_ids == 0 then return results end -- On récupère les traductions dans la langue cible ET en anglais (pour fallback et fichiers) local query = mw.ext.cargo.query("Translation", "target_id, language, name", { where = string.format("target_id IN ('%s') AND language IN ('%s', 'en')", table....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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}}
Portrait Nom Classe Spécialisation Compétences Sort


{{#invoke:HeroList|display|faction=Grove|language=ja}}
Portrait Nom Classe Spécialisation Compétences Sort

local p = {}

-- Fonction utilitaire pour récupérer les traductions en masse
local function getTranslations(target_ids, lang)
    local results = {}
    if #target_ids == 0 then return results end
    
    -- On récupère les traductions dans la langue cible ET en anglais (pour fallback et fichiers)
    local query = mw.ext.cargo.query("Translation", "target_id, language, name", {
        where = string.format("target_id IN ('%s') AND language IN ('%s', 'en')", table.concat(target_ids, "','"), lang),
    })
    
    for _, row in ipairs(query) do
        if not results[row.target_id] then results[row.target_id] = {} end
        results[row.target_id][row.language] = row.name
    end
    return results
end

function p.display(frame)
    local faction = frame.args.faction
    local lang = frame.args.lang or mw.language.getContentLanguage():getCode()
    
    -- 1. Récupération des héros
    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"
    })
    
    -- 2. Préparation des IDs pour les traductions
    local sid_list = {}
    for _, h in ipairs(heroes) do
        table.insert(sid_list, h.name_sid)
        table.insert(sid_list, h.specialization_id) -- À supposer que le SID de spec soit l'ID de spec
        -- On ajoute les skills
        for skill in string.gmatch(h.start_skills or "", "([^,]+)") do
            table.insert(sid_list, skill .. "_name") -- Attention : ajuste si tes SIDs de skills sont différents
        end
    end
    
    local trans = getTranslations(sid_list, lang)
    
    -- 3. Construction du tableau
    local html = {'{| class="wikitable" style="width:100%"', '! Portrait !! Nom !! Classe !! Spécialisation !! Compétences !! Sort'}
    
    for _, h in ipairs(heroes) do
        local name = trans[h.name_sid] and (trans[h.name_sid][lang] or trans[h.name_sid]['en']) or h.id
        local name_en = trans[h.name_sid] and trans[h.name_sid]['en'] or h.id
        
        table.insert(html, "|-")
        table.insert(html, string.format('| [[File:%s.png|70px|link=%s]]', name_en, name_en))
        table.insert(html, string.format('| [[%s|%s]]', name_en, name))
        table.insert(html, string.format('| %s', h.class_id)) -- À enrichir avec le nom de classe si besoin
        table.insert(html, "| ...") -- Logique de spec et skills à finaliser
    end
    
    table.insert(html, "|}")
    return table.concat(html, "\n")
end

return p