Module:HeroData: Difference between revisions

Jump to navigation Jump to search
Sur (talk | contribs)
m concept for get_hero_infobox
Sur (talk | contribs)
m write_hero_infobox now actually evaluates the template
Tags: Mobile edit Mobile web edit
Line 53: Line 53:
--{{#invoke:HeroData|write_hero_infobox|HERO_NAME}}--
--{{#invoke:HeroData|write_hero_infobox|HERO_NAME}}--
p.write_hero_infobox = function(frame)
p.write_hero_infobox = function(frame)
hero_name = frame.args[1]
    hero_name = frame.args[1]
hero = get_json_item(hero_name)
    hero = get_json_item(hero_name)
   
local template = "{{Infobox_hero"
    if(hero == nil) then return "Hero Not Found" end
if(hero == nil) then return "Hero Not Found" end
   
    -- Prepare the arguments for the template
for stat_name,stat_value in pairs(hero) do
    local templateArgs = {}
if (type(stat_value) == "table") then --catches SpiritScaling, LevelScaling, BoundedAbilities, etc.
   
local a=1
    for stat_name, stat_value in pairs(hero) do
else
        if (type(stat_value) ~= "table") then -- skips complex nested tables
template = template .. "|" .. stat_name .. "=" .. stat_value
            templateArgs[stat_name] = stat_value
end
        end
template = template .. "<br>" --temporary, used for illustration/debugging, won't be in final function
    end
end
   
    -- Use expandTemplate to evaluate the Infobox_hero template
template = template .. "}}"
    local templateTitle = mw.title.new("Template:Infobox_hero")
    local expandedTemplate = mw.getCurrentFrame():expandTemplate{ title = templateTitle, args = templateArgs }
return template
   
    return expandedTemplate
end
end