Module:SubSkillsTable: Difference between revisions
From Heroes of Might and Magic: Olden Era Official Wiki
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local function getTrans(target_id, type, lang, field) | -- Fonction utilitaire pour récupérer la traduction en filtrant par variant | ||
local function getTrans(target_id, type, lang, field, variant) | |||
local query_where = string.format("target_id = '%s' AND type = '%s' AND language = '%s'", target_id, type, lang) | |||
if variant then | |||
query_where = query_where .. string.format(" AND variant = '%s'", variant) | |||
end | |||
local res = mw.ext.cargo.query("Translation", field, { | local res = mw.ext.cargo.query("Translation", field, { | ||
where = | where = query_where, | ||
limit = 1 | limit = 1 | ||
}) | }) | ||
| Line 16: | Line 21: | ||
local lang = frame.args.language or "en" | local lang = frame.args.language or "en" | ||
local levels = mw.ext.cargo.query("SkillLevel", "level, icon, | -- Récupération des niveaux | ||
local levels = mw.ext.cargo.query("SkillLevel", "level, icon, offered_sub_skills", { | |||
where = string.format("skill_id = '%s'", skill_id), | where = string.format("skill_id = '%s'", skill_id), | ||
orderBy = "level ASC" | orderBy = "level ASC" | ||
}) | }) | ||
if not levels or #levels == 0 then return "Aucun niveau trouvé | if not levels or #levels == 0 then return "Aucun niveau trouvé." end | ||
local html = {'{| class="wikitable" style="width:100%"'} | local html = {'{| class="wikitable" style="width:100%"'} | ||
table.insert(html, '! colspan=2 | | table.insert(html, '! colspan=2 | Nom !! colspan=6 | Description') | ||
for _, lvl in ipairs(levels) do | for _, lvl in ipairs(levels) do | ||
-- On récupère la traduction en passant le numéro de niveau comme variant | |||
local trans_name = getTrans(skill_id, "skill_level", lang, "name", lvl.level) | |||
local trans_desc = getTrans(skill_id, "skill_level", lang, "description", lvl.level) | |||
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" | local icon_name = (lvl.icon and lvl.icon ~= "") and lvl.icon or "Placeholder" | ||
table.insert(html, '|- style="vertical-align:top;"') | table.insert(html, '|- style="vertical-align:top;"') | ||
table.insert(html, '| style="text-align:right;" | [[File:' .. icon_name .. '.png|70px]]') | table.insert(html, '| style="text-align:right; border-right:0px;" | [[File:' .. icon_name .. '.png|70px]]') | ||
table.insert(html, '| \'\'\'' .. trans_name .. '\'\'\' <br /><span style="color: #DDD;">' .. trans_desc .. '</span>') | table.insert(html, '| style="border-left:0px;" | \'\'\'' .. trans_name .. '\'\'\' <br /><span style="color: #DDD;">' .. trans_desc .. '</span>') | ||
-- Ici, tu pourrais ajouter une autre boucle pour itérer sur lvl.offered_sub_skills | |||
-- en faisant une requête dans la table "SubSkill" pour chaque ID trouvé. | |||
end | end | ||
Revision as of 09:15, 6 June 2026
Documentation for this module may be created at Module:SubSkillsTable/doc
local p = {}
-- Fonction utilitaire pour récupérer la traduction en filtrant par variant
local function getTrans(target_id, type, lang, field, variant)
local query_where = string.format("target_id = '%s' AND type = '%s' AND language = '%s'", target_id, type, lang)
if variant then
query_where = query_where .. string.format(" AND variant = '%s'", variant)
end
local res = mw.ext.cargo.query("Translation", field, {
where = query_where,
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"
-- Récupération des niveaux
local levels = mw.ext.cargo.query("SkillLevel", "level, icon, offered_sub_skills", {
where = string.format("skill_id = '%s'", skill_id),
orderBy = "level ASC"
})
if not levels or #levels == 0 then return "Aucun niveau trouvé." end
local html = {'{| class="wikitable" style="width:100%"'}
table.insert(html, '! colspan=2 | Nom !! colspan=6 | Description')
for _, lvl in ipairs(levels) do
-- On récupère la traduction en passant le numéro de niveau comme variant
local trans_name = getTrans(skill_id, "skill_level", lang, "name", lvl.level)
local trans_desc = getTrans(skill_id, "skill_level", lang, "description", lvl.level)
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; border-right:0px;" | [[File:' .. icon_name .. '.png|70px]]')
table.insert(html, '| style="border-left:0px;" | \'\'\'' .. trans_name .. '\'\'\' <br /><span style="color: #DDD;">' .. trans_desc .. '</span>')
-- Ici, tu pourrais ajouter une autre boucle pour itérer sur lvl.offered_sub_skills
-- en faisant une requête dans la table "SubSkill" pour chaque ID trouvé.
end
table.insert(html, "|}")
return table.concat(html, "\n")
end
return p


