Module:HeroData: Difference between revisions

Jump to navigation Jump to search
Sur (talk | contribs)
m bugfixes
Sur (talk | contribs)
m utilize display_regions
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
   
    -- Attributes to include in the infobox call
    local infobox_attributes = {
    Weapon = {"DPS", "ClipSize", "RoundsPerSecond", "ReloadTime"},
    Vitality = {"MaxHealth", "BulletArmorDamageReduction", "TechArmorDamageReduction", "MaxMoveSpeed"}
    }
      
      
     -- Declarations and initializations
     -- Declarations and initializations
Line 99: Line 93:
     local label
     local label
     local postfix
     local postfix
      
     local shouldDisplay
     local template_args = {}
     local template_args = {}
      
      
     -- Iterate attribute categories
     -- Iterate attribute categories
     for category, stats in pairs(infobox_attributes) do
     for category, stats in pairs(attributes_data) do
-- Iterate stats
-- Iterate stats
for _, stat_name in ipairs(stats) do
for stat_name, stat_data in pairs(stats) do
attribute_data = attributes_data[category]
-- Confirm its meant to be displayed in hero infobox
if (attribute_data == nil) then return "Category " .. category .. " in infobox_attributes is not in Data:AttributeData" end
shouldDisplay = stat_data['display_regions']['hero_infobox']
stat_data = attribute_data[stat_name]
if (shouldDisplay ~= nil) then
if (stat_data == nil) then return "Attribute " .. stat_name .. " in infobox_attributes is not in Data:AttributeData" end
-- gets the stat's value
attribute_data = attributes_data[category]
stat_value = hero_data[stat_name]
if (attribute_data == nil) then return "Category " .. category .. " in infobox_attributes is not in Data:AttributeData" end
if (stat_value == nil) then
stat_data = attribute_data[stat_name]
stat_value = 0 --default to 0 if not present
if (stat_data == nil) then return "Attribute " .. stat_name .. " in infobox_attributes is not in Data:AttributeData" end
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
--Round value to 3 significant figures
template_args[stat_name] = stat_value .. postfix
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
Line 169: Line 166:
if (hero_data == nil) then return "Hero Not Found in AttrData" end
if (hero_data == nil) then return "Hero Not Found in AttrData" end
local category_data = attribute_module.get_category_data()
local category_data = attribute_module.get_category_data()
local should_display
for _, category in ipairs(attributes_data["_category_order"]) do
for _, category in ipairs(attributes_data["_category_order"]) do
Line 182: Line 180:
stat_data = stats[stat_name]
stat_data = stats[stat_name]
-- gets the stat's value if it has that stat, default to 0 if not
-- Confirm its meant to be displayed in hero statbox
stat_value = hero_data[stat_name]
should_display = stat_data['display_regions']['hero_statbox']
if (stat_value == nil) then
if (should_display ~= nil) then
stat_value = 0 --default to 0 if not present
end
-- gets the stat's value if it has that stat, default to 0 if not
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
-- Check if icon file exists, and if not, don't use any image
image_file_name = 'File:AttributeIcon' .. stat_name .. '.png'
image_file_name = util_module.get_image_file(image_file_name)
-- Add an empty cell following some stats to align them correctly as seen in game
if (stats_to_add_blank_after[stat_name]) then
extra_blank_cell = " ," --prefixed space is needed
else
extra_blank_cell = ""
end
-- Add the scaling str if it scales
local scalar_str = p.get_hero_scalar_str(hero_data, stat_name)
-- Set cell value as "Icon StatvaluePostfix Statname Scaling,"
-- If icon file already exists, set it to #REDIRECT to the duplicate file page
cell_value = image_file_name .. " " .. stat_value  .. postfix .. " " .. label .. " " .. scalar_str .. "," .. extra_blank_cell
--Round value to 3 significant figures
cell_values = cell_values .. cell_value --add value to values list
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
-- Check if icon file exists, and if not, don't use any image
image_file_name = 'File:AttributeIcon' .. stat_name .. '.png'
image_file_name = util_module.get_image_file(image_file_name)
-- Add an empty cell following some stats to align them correctly as seen in game
if (stats_to_add_blank_after[stat_name]) then
extra_blank_cell = " ," --prefixed space is needed
else
extra_blank_cell = ""
end
-- Add the scaling str if it scales
local scalar_str = p.get_hero_scalar_str(hero_data, stat_name)
-- Set cell value as "Icon StatvaluePostfix Statname Scaling,"
-- If icon file already exists, set it to #REDIRECT to the duplicate file page
cell_value = image_file_name .. " " .. stat_value  .. postfix .. " " .. label .. " " .. scalar_str .. "," .. extra_blank_cell
cell_values = cell_values .. cell_value --add value to values list
end
end
template_args["cell_values"] = cell_values
template_args["cell_values"] = cell_values