Module:HeroDataParser/ru
From Heroes of Might and Magic: Olden Era Official Wiki
Documentation for this module may be created at Module:HeroDataParser/ru/doc
local p = {}
local heroDataCache = nil
local function getHeroData()
if not heroDataCache then
local content = mw.title.new('Data:HeroData/ru.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_ru(frame)
local hero = findHero(frame.args[1])
return hero and hero.class_ru or ''
end
function p.getSpecialty(frame)
local hero = findHero(frame.args[1])
return hero and hero.specialty or ''
end
function p.getSpecialty_ru(frame)
local hero = findHero(frame.args[1])
return hero and hero.specialty_ru 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_ru(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_ru 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_ru(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_ru 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_ru(frame)
local hero = findHero(frame.args[1])
return hero and hero.spell_ru 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_ru))
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_ru))
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


