Module:HeroListByClass

From Heroes of Might and Magic: Olden Era Official Wiki

Documentation for this module may be created at Module:HeroListByClass/doc

function p.display(frame)
    local class_filter = frame.args.class_id
    local lang = frame.args.language or mw.title.getCurrentTitle().text:match("/(%a%a)$") or "en"
    
    -- INITIALISE HTML ICI, AVANT D'AJOUTER QUOI QUE CE SOIT
    local html = {'{| class="wikitable sortable" style="width:100%"'}
    
    -- Construction requête
    local where_clause = "id NOT LIKE '%campaign%' AND id NOT LIKE '%tutorial%' AND id NOT LIKE '%cm_fun%'"
    if class_filter and class_filter ~= "" then
        where_clause = where_clause .. string.format(" AND class_id = '%s'", class_filter)
    end
    
    -- Débogage
    local count_test = mw.ext.cargo.query("Hero", "COUNT(*)", {where = where_clause})
    local total = (count_test and #count_test > 0) and count_test[1]["COUNT(*)"] or 0
    table.insert(html, "<tr><td colspan='4'>DEBUG: Nombre de héros trouvés = " .. total .. "</td></tr>")
    
    local heroes = mw.ext.cargo.query("Hero", "id, name_sid, class_id, specialization_id, start_skills, start_magics", {
        where = where_clause
    })
    
    -- En-têtes (si total > 0, sinon on voit juste le debug)
    local h_name = getTrans("wiki_name", lang, "wiki") or "Name"
    local h_spec = getTrans("wiki_hero_spec", lang, "wiki") or "Specialization"
    local h_skills = getTrans("starting_skills", lang, "ui") or "Skills"
    local h_spells = getTrans("starting_spells", lang, "ui") or "Spells"
    table.insert(html, string.format('! %s !! %s !! %s !! %s', h_name, h_spec, h_skills, h_spells))
    
    for _, h in ipairs(heroes) do
        -- INITIALISE TES LISTES ICI
        local skills_html = {}
        local spells_html = {}
        
        -- ... (Insère ici tes boucles for pour skills_html et spells_html comme dans ton script précédent) ...

        -- CONSTRUCTION LIGNE
        table.insert(html, '|- style="vertical-align: middle;"')
        -- ... suite de ton code ...
    end
    
    table.insert(html, "|}")
    return table.concat(html, "\n")
end