Module:HeroData: Difference between revisions

Sur (talk | contribs)
m exclude stats that are always 0
Sur (talk | contribs)
m exclude heroes in development or disabled
Line 75: Line 75:
return element
return element
end
end




Line 353: Line 350:
local spirit_power = frame.args[2]
local spirit_power = frame.args[2]
if (spirit_power == nil) then spirit_power = 0 end
if (spirit_power == nil) then spirit_power = 0 end
local in_development
local is_disabled
-- Initializations and declarations
-- Initializations and declarations
Line 382: Line 382:
-- Iterate heroes
-- Iterate heroes
for hero_key, hero_data in pairs(heroes_data) do
for hero_key, hero_data in pairs(heroes_data) do
--Add the row's stats
-- Ensure they are not in development and they are an active hero
row_str = ""
in_development = hero_data["inDevelopment"]
is_disabled = hero_data["isDisabled"]
-- Retrieve hero's name
if (not in_development and not is_disabled) then
hero_name = lang_module._get_string(hero_key)
--Add the row's stats
-- First column in each row is hero name
row_str = ""
row_str = row_str .. "<td>" .. hero_name .. "</td>"
-- Retrieve hero's name
-- Consecutive columns are then stats
hero_name = lang_module._get_string(hero_key)
-- Iterate categories
for _, category in ipairs(attribute_orders["category_order"]) do
-- First column in each row is hero name
category_attrs = attributes_data[category]
row_str = row_str .. "<td>" .. hero_name .. "</td>"
-- Iterate attributes within the category
-- Consecutive columns are then stats
for _, attr_key in ipairs(attribute_orders[category]["attribute_order"]) do
-- Iterate categories
if (stats_to_exclude[attr_key] == nil) then
for _, category in ipairs(attribute_orders["category_order"]) do
attr_data = category_attrs[attr_key]
category_attrs = attributes_data[category]
--Retrieve the stats value from hero data
stat_value = hero_data[attr_key]
-- Iterate attributes within the category
if (stat_value == nil) then stat_value = 0 end
for _, attr_key in ipairs(attribute_orders[category]["attribute_order"]) do
if (stats_to_exclude[attr_key] == nil) then
-- Round it
attr_data = category_attrs[attr_key]
stat_value = util_module.round_to_sig_fig(stat_value, 3)
--Retrieve the stats value from hero data
stat_value = hero_data[attr_key]
-- Add it to the row
if (stat_value == nil) then stat_value = 0 end
row_str = row_str .. "<td>" .. stat_value .. "</td>"
-- Round it
stat_value = util_module.round_to_sig_fig(stat_value, 3)
-- Add it to the row
row_str = row_str .. "<td>" .. stat_value .. "</td>"
end
end
end
end
end
-- Add row to the body
row_str = "<tr>" .. row_str .. "</tr>"
body_str = body_str .. row_str
first_hero = false
end
end
-- Add row to the body
row_str = "<tr>" .. row_str .. "</tr>"
body_str = body_str .. row_str
first_hero = false
end
end