Module:HeroData: Difference between revisions

Jump to navigation Jump to search
Sur (talk | contribs)
m Infobox_hero > User:Sur; template vars to snake case
Sur (talk | contribs)
m calling lang module
Line 88: Line 88:
     local infobox_attributes = {
     local infobox_attributes = {
     Weapon = {"DPS", "ClipSize", "RoundsPerSecond", "ReloadTime"},
     Weapon = {"DPS", "ClipSize", "RoundsPerSecond", "ReloadTime"},
     Vitality = {"MaxHealth", "BulletResist", "SpiritResist", "MoveSpeed"}
     Vitality = {"MaxHealth", "BulletResist", "SpiritResist", "MaxMoveSpeed"}
     }
     }
      
      
Line 103: Line 103:
      
      
     -- Iterate attribute categories
     -- Iterate attribute categories
     for _, category in ipairs(infobox_attributes) do
     for category, stats in pairs(infobox_attributes) do
stats = attributes_data[category]
if (stats ~= nil) then -- Ensure the category is in the hero data
-- Iterate stats
for _, stat_name in ipairs(stats) do
stat_data = attributes_data[category][stat_name]
if (stat_data == nil) then return "Attribute in infobox_attributes is not in Data:AttributeData" end
-- Iterate attributes to be called by infobox
-- gets the stat's value
for _, stat_name in ipairs(infobox_attributes[category]) do
stat_value = hero_data[stat_name]
stat_data = stats[stat_name]
if (stat_value == nil) then
stat_value = 0 --default to 0 if not present
-- gets the stat's value
end
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.call_lang(postfix)
end
template_args[stat_name] = stat_value .. postfix
--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
else
template_args[stat_name] = stat_value .. postfix
return "Error: Category not in attributes data"
end
end
Line 195: Line 190:
-- get label and postfix
-- get label and postfix
label = util_module.call_lang(stat_data["label"])
label = lang_module._get_string(stat_data["label"])
postfix = stat_data["postfix"]
postfix = stat_data["postfix"]
if (postfix == nil) then  
if (postfix == nil) then  
postfix = ""
postfix = ""
else
else
postfix = util_module.call_lang(postfix)
postfix = lang_module._get_string(postfix)
end
end