Module:SubSkillsTable
From Heroes of Might and Magic: Olden Era Official Wiki
Documentation for this module may be created at Module:SubSkillsTable/doc
local p = {}
local function getTrans(target_id, type, lang, field)
field = field or "name"
local res = mw.ext.cargo.query("Translation", field, {
where = string.format("target_id = '%s' AND type = '%s' AND language = '%s'", target_id, type, lang),
limit = 1
})
return (res and #res > 0) and res[1][field] or ""
end
function p.display(frame)
local skill_id = frame.args["id"] or frame.args[1]
if not skill_id then return "ID requis" end
local lang = frame.args.language or "en"
local levels = mw.ext.cargo.query("SkillLevel", "level, icon, name_sid", {
where = string.format("skill_id = '%s'", skill_id),
orderBy = "level ASC"
})
if not levels or #levels == 0 then return "Aucun niveau trouvé pour cet ID." end
local html = {'{| class="wikitable" style="width:100%"'}
table.insert(html, '! colspan=2 | Name !! colspan=6 | Description')
for _, lvl in ipairs(levels) do
-- Affiche la valeur pour debug
local trans_name = getTrans(lvl.name_sid, "skill_level", lang, "name")
-- Attention : vérifie si le type est bien "skill_level" et non "skill"
local trans_name = getTrans(skill_id, "skill_level", lang, "name")
local trans_desc = getTrans(skill_id, "skill_level", lang, "description")
local icon_name = (lvl.icon and lvl.icon ~= "") and lvl.icon or "Placeholder"
table.insert(html, '|- style="vertical-align:top;"')
table.insert(html, '| style="text-align:right;" | [[File:' .. icon_name .. '.png|70px]]')
table.insert(html, '| \'\'\'' .. trans_name .. '\'\'\' <br /><span style="color: #DDD;">' .. trans_desc .. '</span>')
end
table.insert(html, "|}")
return table.concat(html, "\n")
end
return p


