Module:HeroData: Difference between revisions

Jump to navigation Jump to search
Sur (talk | contribs)
m utilize display_regions
Sur (talk | contribs)
m partial revert
Line 84: Line 84:
     hero_data = p.get_json_item(hero_name)
     hero_data = p.get_json_item(hero_name)
     if(hero_data == nil) then return "Hero Not Found" end
     if(hero_data == nil) then return "Hero Not Found" end
   
    local infobox_attributes = {
        Weapon = {'DPS','ClipSize','RoundsPerSecond','ReloadTime'},
        Vitality = {'MaxHealth','BulletArmorDamageReduction','TechArmorDamageReduction','MaxMoveSpeed'}
    }
      
      
     -- Declarations and initializations
     -- Declarations and initializations
Line 97: Line 102:
      
      
     -- Iterate attribute categories
     -- Iterate attribute categories
     for category, stats in pairs(attributes_data) do
     for category, stats in pairs(infobox_attributes) do
-- Iterate stats
-- Iterate stats
for stat_name, stat_data in pairs(stats) do
for _, stat_name in ipairs(stats) do
-- Confirm its meant to be displayed in hero infobox
-- Confirm its in attribute data and retrieve it
shouldDisplay = stat_data['display_regions']['hero_infobox']
attribute_data = attributes_data[category]
if (shouldDisplay ~= nil) then
if (attribute_data == nil) then return "Category " .. category .. " in infobox_attributes is not in Data:AttributeData" end
stat_data = attribute_data[stat_name]
if (stat_data == nil) then return "Attribute " .. stat_name .. " in infobox_attributes is not in Data:AttributeData" end
attribute_data = attributes_data[category]
-- gets the stat's value
if (attribute_data == nil) then return "Category " .. category .. " in infobox_attributes is not in Data:AttributeData" end
stat_value = hero_data[stat_name]
stat_data = attribute_data[stat_name]
if (stat_value == nil) then
if (stat_data == nil) then return "Attribute " .. stat_name .. " in infobox_attributes is not in Data:AttributeData" end
stat_value = 0 --default to 0 if not present
end
-- gets the stat's value
--Round value to 3 significant figures
stat_value = hero_data[stat_name]
stat_value = util_module.round_to_sig_fig(stat_value, 3)
if (stat_value == nil) then
stat_value = 0 --default to 0 if not present
-- get label and postfix
end
label = lang_module._get_string(stat_data["label"])
postfix = stat_data["postfix"]
--Round value to 3 significant figures
if (postfix == nil) then  
stat_value = util_module.round_to_sig_fig(stat_value, 3)
postfix = ""
else
-- get label and postfix
postfix = lang_module._get_string(postfix)
label = lang_module._get_string(stat_data["label"])
postfix = stat_data["postfix"]
if (postfix == nil) then  
postfix = ""
else
postfix = lang_module._get_string(postfix)
end
template_args[stat_name] = stat_value .. postfix
end
end
template_args[stat_name] = stat_value .. postfix
end
end