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 -- ex: "knight"
local lang = frame.args.language or mw.title.getCurrentTitle().text:match("/(%a%a)$") or "en"
-- Table de conversion
local class_map = {
["herald"] = "magic_demon",
["warlock"] = "magic_dungeon",
["cleric"] = "magic_human",
["druid"] = "magic_nature",
["necromancer"] = "magic_undead",
["riftspeaker"] = "magic_unfrozen",
["enforcer"] = "might_demon",
["overlord"] = "might_dungeon",
["warden"] = "might_nature",
["death knight"] = "might_undead",
["oathkeeper"] = "might_unfrozen",
["knight"] = "might_human"
}
local html = {'{| class="wikitable sortable" style="width:100%"'}
-- Construction requête avec conversion
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
-- Convertir en minuscule pour être sûr que ça matche
local mapped_id = class_map[class_filter:lower()] or class_filter
where_clause = where_clause .. string.format(" AND class_id = '%s'", mapped_id)
end
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


