Module:HeroData: Difference between revisions
m write_hero_comparison_table initial |
m write_hero_comparison_table save |
||
Line 354: | Line 354: | ||
if (spirit_power == nil) then spirit_power = 0 end | if (spirit_power == nil) then spirit_power = 0 end | ||
-- | -- Initializations and declarations | ||
local headers = {} | local headers = {} | ||
local row_str = "" | local row_str = "" | ||
local body_str = "" | local body_str = "" | ||
for | |||
-- Iterate heroes | |||
for hero_key, hero_data in pairs(heroes_data) do | |||
--Add the row's stats | --Add the row's stats | ||
row_str = "" | row_str = "" | ||
-- Retrieve hero's name | |||
hero_name = lang_module._get_string(hero_key) | |||
-- First column in each row is hero name | -- First column in each row is hero name | ||
row_str = row_str .. "<td>" .. | row_str = row_str .. "<td>" .. hero_name .. "</td>" | ||
-- Consecutive columns are then stats | -- Consecutive columns are then stats | ||
for | -- Iterate categories | ||
row_str = row_str .. "<td>" .. | for category, category_attrs in pairs(attributes_data) do | ||
-- Iterate attributes within the category | |||
for attr_key, attr_data in pairs(category_attrs) do | |||
-- Add the localized attribute to the headers hash list | |||
attr_localized = lang_module._get_string(attr_data["label"]) | |||
-- Default to attr_key if unlocalizable | |||
if (attr_localized == nil) then attr_localized = attr_key end | |||
headers[attr_localized] = true | |||
--Retrieve the stats value from hero data | |||
stat_value = hero_data[attr_key] | |||
if (stat_value == nil) then stat_value = 0 end | |||
-- 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 | ||
-- Add row to the body | |||
row_str = "<tr>" .. row_str .. "</tr>" | row_str = "<tr>" .. row_str .. "</tr>" | ||
body_str = body_str .. row_str | body_str = body_str .. row_str | ||
end | end | ||
-- First header is Hero | |||
local headers_str = "<th>" .. "Hero" .. "</th>" | |||
-- Turn headers list to string | |||
for header, _ in pairs(headers) do | |||
headers_str = headers_str .. "<th>" .. header .. "</th>" | |||
end | |||
headers_str = "<tr>" .. headers_str .. "</tr>" | |||