Module:HeroData: Difference between revisionsGive feedback
m utilize display_regions |
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( | for category, stats in pairs(infobox_attributes) do | ||
-- Iterate stats | -- Iterate stats | ||
for stat_name | for _, stat_name in ipairs(stats) do | ||
-- Confirm its | -- Confirm its in attribute data and retrieve it | ||
attribute_data = attributes_data[category] | |||
if ( | 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 | |||
-- gets the stat's value | |||
stat_value = hero_data[stat_name] | |||
if (stat_value == nil) then | |||
stat_value = 0 --default to 0 if not present | |||
end | |||
--Round value to 3 significant figures | |||
stat_value = util_module.round_to_sig_fig(stat_value, 3) | |||
-- get label and 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 | end | ||
template_args[stat_name] = stat_value .. postfix | |||
end | end | ||