Module:HeroData: Difference between revisionsGive feedback
Gammaton32 (talk | contribs) No edit summary |
Sort hero comparison table alphabetically; minor code cleanup |
||
| Line 569: | Line 569: | ||
local row_str = "" | local row_str = "" | ||
local body_str = "" | local body_str = "" | ||
local template_title = "" | local template_title = "" | ||
local template_args = {} | local template_args = {} | ||
local hero_icon | local hero_icon | ||
-- Add hero comp stats to | -- Add hero comp stats to | ||
| Line 622: | Line 618: | ||
} | } | ||
} | } | ||
-- Collect and sort heroes alphabetically by name | |||
local sorted_heroes = {} | |||
for hero_key, hero_data in pairs(heroes_data) do | |||
if not hero_data["InDevelopment"] and not hero_data["IsDisabled"] then | |||
table.insert(sorted_heroes, {key = hero_key, data = hero_data}) | |||
end | |||
end | |||
table.sort(sorted_heroes, function(a, b) | |||
return (a.data["Name"] or a.key) < (b.data["Name"] or b.key) | |||
end) | |||
-- Iterate heroes | -- Iterate heroes | ||
for | for _, hero_entry in ipairs(sorted_heroes) do | ||
-- | local hero_key = hero_entry.key | ||
local hero_data = hero_entry.data | |||
row_str = "" | |||
-- Retrieve hero's localized name | |||
hero_name = localize(hero_key, hero_key) | |||
-- Retrieve hero's english name, used for hero icon | |||
hero_name_en = hero_data["Name"] | |||
-- Expand hero icon | |||
template_title = "Template:HeroIcon" | |||
template_args[1] = hero_name_en | |||
template_args[2] = hero_name | |||
hero_icon = mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args } | |||
-- First column in each row is hero name | |||
row_str = row_str .. "<td>" .. hero_icon .. "</td>" | |||
-- Consecutive columns are then stats | |||
-- Iterate categories | |||
for _, category in ipairs(attribute_orders["category_order"]) do | |||
category_attrs = attributes_data[category] | |||
-- | -- Iterate attributes within the category | ||
if (stats_to_include[category] ~= nil) then | |||
for _, attr_key in ipairs(stats_to_include[category]) do | |||
--Retrieve the stats value from hero data | |||
stat_value = get_nested_stat_value(hero_data, attr_key) | |||
-- Retrieve scaling val and str if it scales | |||
local scaling_data = p.get_hero_scaling_data(hero_data, attr_key) | |||
local scaling_strs = "" | |||
if (scaling_data ~= nil) then | |||
for scaling_value, scaling_type in pairs(scaling_data) do | |||
local scaling_str = p.write_scalar_str(scaling_value, scaling_type) | |||
if (scaling_str ~= "") then scaling_str = " " .. scaling_str end | |||
if (scaling_str ~= nil) then | |||
scaling_strs = scaling_strs .. scaling_str | |||
end | |||
-- Scale the stat value | |||
if (scaling_type == "Spirit") then | |||
stat_value = stat_value + (spirit_power * scaling_value) | |||
elseif (scaling_type == "Level") then | |||
if attr_key == 'TechResist' or attr_key == 'BulletResist' then | |||
-- each PI for resists is multiplicative | |||
stat_value = (stat_value/100 + 1 - (1-scaling_value/100)^power_increases)*100 | |||
else | |||
stat_value = stat_value + (power_increases * scaling_value) | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
if (not display_scaling_icons) then scaling_strs = "" end | |||
-- Convert from boolean to string, or round it | |||
if (type(stat_value)) == 'boolean' then | |||
stat_value = tostring(stat_value) | |||
else | |||
stat_value = util_module.round_to_sig_fig(stat_value, 3) | |||
end | |||
-- Add it to the row | |||
row_str = row_str .. "<td>" .. stat_value .. scaling_strs .. "</td>" | |||
end | end | ||
end | end | ||
end | end | ||
-- Add row to the body | |||
row_str = "<tr>" .. row_str .. "</tr>" | |||
body_str = body_str .. row_str | |||
end | end | ||