Module:SubSkillsTable: Difference between revisions

From Heroes of Might and Magic: Olden Era Official Wiki
76561198256426587 moved page Module:Akeshatest to Module:ScrollList
Tag: New redirect
 
Removed redirect to Module:ScrollList
Tag: Removed redirect
Line 1: Line 1:
return require [[Module:ScrollList]]
local p = {}
 
-- Fonction utilitaire pour récupérer la traduction
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"] -- ex: skill_assault
    local lang = frame.args.language or "en"
   
    -- 1. Récupération des niveaux (1, 2, 3)
    local levels = mw.ext.cargo.query("SkillLevelDef", "level, icon, offered_sub_skills", {
        where = string.format("skill_id = '%s'", skill_id),
        orderBy = "level ASC"
    })
   
    local html = {'{| class="wikitable" style="width:100%"'}
    -- En-têtes (à adapter selon ton besoin)
    table.insert(html, '! colspan=2 | Name !! colspan=6 | Description')
 
    for _, lvl in ipairs(levels) do
        local trans_name = getTrans(skill_id, "skill_level", lang, "name")
        local trans_desc = getTrans(skill_id, "skill_level", lang, "description")
       
        -- Construction de la ligne pour chaque niveau
        table.insert(html, '|- style="vertical-align:top;"')
        table.insert(html, '| style="text-align:right;" | [[File:' .. lvl.icon .. '.png|70px]]')
        table.insert(html, '| \'\'\'' .. trans_name .. '\'\'\' <br /><span style="color: #DDD;">' .. trans_desc .. '</span>')
       
        -- Ici, tu peux ajouter une logique pour afficher les sub_skills récupérés dans lvl.offered_sub_skills
        -- ...
    end
   
    table.insert(html, "|}")
    return table.concat(html, "\n")
end
 
return p

Revision as of 08:58, 6 June 2026

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

local p = {}

-- Fonction utilitaire pour récupérer la traduction
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"] -- ex: skill_assault
    local lang = frame.args.language or "en"
    
    -- 1. Récupération des niveaux (1, 2, 3)
    local levels = mw.ext.cargo.query("SkillLevelDef", "level, icon, offered_sub_skills", {
        where = string.format("skill_id = '%s'", skill_id),
        orderBy = "level ASC"
    })
    
    local html = {'{| class="wikitable" style="width:100%"'}
    -- En-têtes (à adapter selon ton besoin)
    table.insert(html, '! colspan=2 | Name !! colspan=6 | Description')

    for _, lvl in ipairs(levels) do
        local trans_name = getTrans(skill_id, "skill_level", lang, "name")
        local trans_desc = getTrans(skill_id, "skill_level", lang, "description")
        
        -- Construction de la ligne pour chaque niveau
        table.insert(html, '|- style="vertical-align:top;"')
        table.insert(html, '| style="text-align:right;" | [[File:' .. lvl.icon .. '.png|70px]]')
        table.insert(html, '| \'\'\'' .. trans_name .. '\'\'\' <br /><span style="color: #DDD;">' .. trans_desc .. '</span>')
        
        -- Ici, tu peux ajouter une logique pour afficher les sub_skills récupérés dans lvl.offered_sub_skills
        -- ...
    end
    
    table.insert(html, "|}")
    return table.concat(html, "\n")
end

return p