Module:HeroDataParser/ru: Difference between revisions
From Heroes of Might and Magic: Olden Era Official Wiki
Created page with "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..." |
No edit summary Tag: Manual revert |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 24: | Line 24: | ||
local hero = findHero(frame.args[1]) | local hero = findHero(frame.args[1]) | ||
return hero and hero.class or '' | 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 | end | ||
| Line 29: | Line 34: | ||
local hero = findHero(frame.args[1]) | local hero = findHero(frame.args[1]) | ||
return hero and hero.specialty or '' | 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 | end | ||
| Line 35: | Line 45: | ||
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 or nil | 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 | end | ||
return nil | return nil | ||
| Line 43: | Line 61: | ||
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 or nil | 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 | end | ||
return nil | return nil | ||
| Line 50: | Line 76: | ||
local hero = findHero(frame.args[1]) | local hero = findHero(frame.args[1]) | ||
return hero and hero.spell or nil | 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 | end | ||
| Line 60: | Line 91: | ||
for _, hero in ipairs(json.heroes) do | for _, hero in ipairs(json.heroes) do | ||
if hero.faction == faction then | if hero.faction == faction then | ||
-- Build a HeroTableLine call for each hero | -- Build a HeroTableLine/ru call for each hero | ||
table.insert(result, string.format('{{HeroTableLine|%s}}', hero.name)) | table.insert(result, string.format('{{HeroTableLine/ru|%s|%s}}', hero.name, hero.name_ru)) | ||
end | end | ||
end | end | ||
| Line 78: | Line 109: | ||
for _, hero in ipairs(json.heroes) do | for _, hero in ipairs(json.heroes) do | ||
if hero.class == className then | if hero.class == className then | ||
-- Build a HeroTableLine call for each hero | -- Build a HeroTableLine/ru call for each hero | ||
table.insert(result, string.format('{{HeroTableLine|%s}}', hero.name)) | table.insert(result, string.format('{{HeroTableLine/ru|%s|%s}}', hero.name, hero.name_ru)) | ||
end | end | ||
end | end | ||
Latest revision as of 23:31, 3 November 2025
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


