Module:HeroDataParser/pl: Difference between revisions

From Heroes of Might and Magic: Olden Era Official Wiki
GlowikM (talk | contribs)
No edit summary
GlowikM (talk | contribs)
No edit summary
Line 26: Line 26:
end
end


function p.getClass_ru(frame)
function p.getClass_pl(frame)
     local hero = findHero(frame.args[1])
     local hero = findHero(frame.args[1])
     return hero and hero.class_ru or ''
     return hero and hero.class_pl or ''
end
end


Line 36: Line 36:
end
end


function p.getSpecialty_ru(frame)
function p.getSpecialty_pl(frame)
     local hero = findHero(frame.args[1])
     local hero = findHero(frame.args[1])
     return hero and hero.specialty_ru or ''
     return hero and hero.specialty_pl or ''
end
end


Line 49: Line 49:
end
end


function p.getSkill1_ru(frame)
function p.getSkill1_pl(frame)
     local hero = findHero(frame.args[1])
     local hero = findHero(frame.args[1])
     if hero and hero.starting_skills and hero.starting_skills[1] then
     if hero and hero.starting_skills and hero.starting_skills[1] then
         return hero.starting_skills[1].name_ru or nil
         return hero.starting_skills[1].name_pl or nil
     end
     end
     return nil
     return nil
Line 65: Line 65:
end
end


function p.getSkill2_ru(frame)
function p.getSkill2_pl(frame)
     local hero = findHero(frame.args[1])
     local hero = findHero(frame.args[1])
     if hero and hero.starting_skills and hero.starting_skills[2] then
     if hero and hero.starting_skills and hero.starting_skills[2] then
         return hero.starting_skills[2].name_ru or nil
         return hero.starting_skills[2].name_pl or nil
     end
     end
     return nil
     return nil
Line 78: Line 78:
end
end


function p.getSpell_ru(frame)
function p.getSpell_pl(frame)
     local hero = findHero(frame.args[1])
     local hero = findHero(frame.args[1])
     return hero and hero.spell_ru or nil
     return hero and hero.spell_pl or nil
end
end


Line 92: Line 92:
             if hero.faction == faction then
             if hero.faction == faction then
                 -- Build a HeroTableLine/ru call for each hero
                 -- Build a HeroTableLine/ru call for each hero
                 table.insert(result, string.format('{{HeroTableLine/ru|%s|%s}}', hero.name, hero.name_ru))
                 table.insert(result, string.format('{{HeroTableLine/ru|%s|%s}}', hero.name, hero.name_pl))
             end
             end
         end
         end
Line 110: Line 110:
             if hero.class == className then
             if hero.class == className then
                 -- Build a HeroTableLine/ru call for each hero
                 -- Build a HeroTableLine/ru call for each hero
                 table.insert(result, string.format('{{HeroTableLine/ru|%s|%s}}', hero.name, hero.name_ru))
                 table.insert(result, string.format('{{HeroTableLine/ru|%s|%s}}', hero.name, hero.name_pl))
             end
             end
         end
         end

Revision as of 21:26, 5 November 2025

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

local p = {}

local heroDataCache = nil
local function getHeroData()
    if not heroDataCache then
        local content = mw.title.new('Data:HeroData/pl.json'):getContent() or '{}'
        heroDataCache = mw.text.jsonDecode(content)
    end
    return heroDataCache
end

local function findHero(heroName)
    local json = getHeroData()
    if not json or not json.heroes then return nil end
    for _, hero in ipairs(json.heroes) do
        if hero.name == heroName then
            return hero
        end
    end
    return nil
end

function p.getClass(frame)
    local hero = findHero(frame.args[1])
    return hero and hero.class or ''
end

function p.getClass_pl(frame)
    local hero = findHero(frame.args[1])
    return hero and hero.class_pl or ''
end

function p.getSpecialty(frame)
    local hero = findHero(frame.args[1])
    return hero and hero.specialty or ''
end

function p.getSpecialty_pl(frame)
    local hero = findHero(frame.args[1])
    return hero and hero.specialty_pl or ''
end

function p.getSkill1(frame)
    local hero = findHero(frame.args[1])
    if hero and hero.starting_skills and hero.starting_skills[1] then
        return hero.starting_skills[1].name or nil
    end
    return nil
end

function p.getSkill1_pl(frame)
    local hero = findHero(frame.args[1])
    if hero and hero.starting_skills and hero.starting_skills[1] then
        return hero.starting_skills[1].name_pl or nil
    end
    return nil
end

function p.getSkill2(frame)
    local hero = findHero(frame.args[1])
    if hero and hero.starting_skills and hero.starting_skills[2] then
        return hero.starting_skills[2].name or nil
    end
    return nil
end

function p.getSkill2_pl(frame)
    local hero = findHero(frame.args[1])
    if hero and hero.starting_skills and hero.starting_skills[2] then
        return hero.starting_skills[2].name_pl or nil
    end
    return nil
end

function p.getSpell(frame)
    local hero = findHero(frame.args[1])
    return hero and hero.spell or nil
end

function p.getSpell_pl(frame)
    local hero = findHero(frame.args[1])
    return hero and hero.spell_pl or nil
end

function p.getFactionHeroes(frame)
    local faction = frame.args[1]
    local json = getHeroData()
    local result = {}

    if json and json.heroes then
        for _, hero in ipairs(json.heroes) do
            if hero.faction == faction then
                -- Build a HeroTableLine/ru call for each hero
                table.insert(result, string.format('{{HeroTableLine/ru|%s|%s}}', hero.name, hero.name_pl))
            end
        end
    end

    local wikitext = table.concat(result, '\n')
    return frame:preprocess(wikitext)
end

function p.getClassHeroes(frame)
    local className = frame.args[1]
    local json = getHeroData()
    local result = {}

    if json and json.heroes then
        for _, hero in ipairs(json.heroes) do
            if hero.class == className then
                -- Build a HeroTableLine/ru call for each hero
                table.insert(result, string.format('{{HeroTableLine/ru|%s|%s}}', hero.name, hero.name_pl))
            end
        end
    end

    local wikitext = table.concat(result, '\n')
    return frame:preprocess(wikitext)
end

function p.getStartingArmyIcons(frame)
    local hero = findHero(frame.args[1])
    if not hero or not hero.startingArmy then return '' end
    local army = hero.startingArmy
    local html = {'<div style="text-align:center;">'}
    for _, entry in ipairs(army) do
        for unit, count in pairs(entry) do
            local icon = unit .. ' icon.png'
            table.insert(html, string.format('<div style="display:inline-block;margin:4px 8px 4px 8px;vertical-align:top;text-align:center;">[[File:%s|50px|link=%s]]<br/><span style="font-size:1.1em;">%s</span><br/><span style="font-size:1.1em;">%s</span></div>', icon, unit, unit, count))
        end
    end
    table.insert(html, '</div>')
    return table.concat(html, '\n')
end

return p