Module:HeroListByClass
From Heroes of Might and Magic: Olden Era Official Wiki
Documentation for this module may be created at Module:HeroListByClass/doc
local p = {}
-- 1. Fonction utilitaire (déclarée AVANT)
local function getTrans(target_id, lang, type_force, field)
field = field or "name"
if not target_id or target_id == "" then return nil end
local types = type_force and {type_force} or {"wiki", "ui", "hero", "hero_class", "skill", "spell", "hero_specialization"}
for _, t in ipairs(types) do
local query = mw.ext.cargo.query("Translation", field, {
where = string.format("target_id = '%s' AND language = '%s' AND type = '%s'", target_id, lang, t),
limit = 1
})
if query and #query > 0 then return query[1][field] end
end
return nil
end
-- 2. Fonction exportée
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"
local html = {'{| class="wikitable sortable" style="width:100%"'}
-- Construction requête de test simplifiée
local where_clause = "1=1" -- Cette condition est toujours vraie
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
})
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
-- (Insère ici tes boucles de construction de skills_html et spells_html)
-- ...
table.insert(html, '|- style="vertical-align: middle;"')
-- (La suite de ta construction de ligne...)
end
table.insert(html, "|}")
return table.concat(html, "\n")
end
return p


