Module:HeroData: Difference between revisions

Sur (talk | contribs)
m write_hero_comparison_table initial
Sur (talk | contribs)
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
-- get all headers
-- Initializations and declarations
local headers_str = ""
local headers = {}
local headers = {}
headers[1] = "Hero"
headers[2] = "Health"
headers[3] = "DPS"
for index, header in ipairs(headers) do
headers_str = headers_str .. "<th>" .. header .. "</th>"
end
headers_str = "<tr>" .. headers_str .. "</tr>"
local row_str = ""
local row_str = ""
local body_str = ""
local body_str = ""
local heroes = {}
heroes[1] = "Abrams"
heroes[2] = "McGinnis"
heroes[3] = "Seven"
for index, hero in ipairs(heroes) do
local stats = {}
stats[1] = "Health"
stats[2] = "DPS"
-- 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>" .. hero .. "</td>"
row_str = row_str .. "<td>" .. hero_name .. "</td>"
-- Consecutive columns are then stats
-- Consecutive columns are then stats
for index, stat in ipairs(stats) do
-- Iterate categories
row_str = row_str .. "<td>" .. stat .. "</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>"
-- Add row to the body
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>"