Module:HeroData: Difference between revisionsGive feedback
m bugfixes |
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 | ||
-- 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( | for category, stats in pairs(attributes_data) do | ||
-- Iterate stats | -- Iterate stats | ||
for | for stat_name, stat_data in pairs(stats) do | ||
-- Confirm its meant to be displayed in hero infobox | |||
shouldDisplay = stat_data['display_regions']['hero_infobox'] | |||
if (shouldDisplay ~= nil) then | |||
if ( | |||
attribute_data = attributes_data[category] | |||
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 | |||
template_args[stat_name] = stat_value .. postfix | |||
end | end | ||
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 | ||
should_display = stat_data['display_regions']['hero_statbox'] | |||
if (should_display ~= nil) then | |||
-- 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 | |||
cell_values = cell_values .. cell_value --add value to values list | |||
end | end | ||
end | end | ||
template_args["cell_values"] = cell_values | template_args["cell_values"] = cell_values | ||