Module:HeroData: Difference between revisions

Jump to navigation Jump to search
Sur (talk | contribs)
m write_hero_comparison_table fully functioning version
Sur (talk | contribs)
m hero comparison; stats colored by category
Line 355: Line 355:
-- Initializations and declarations
-- Initializations and declarations
local headers = {}
local row_str = ""
local row_str = ""
local body_str = ""
local body_str = ""
local first_hero = true
-- Iterate heroes
-- Iterate heroes
Line 379: Line 376:
-- Iterate attributes within the category
-- Iterate attributes within the category
for _, attr_key in ipairs(attribute_orders[category]["attribute_order"]) do
for _, attr_key in ipairs(attribute_orders[category]["attribute_order"]) do
attr_data = category_attrs[attr_key]
attr_data = category_attrs[attr_key]
-- If its the first iteration, add the attribute to the list of headers
if (first_hero) then
-- Localize, fallback to attr_key
attr_localized = lang_module._get_string(attr_data["label"])
if (attr_localized == nil) then attr_localized = attr_key end
headers[#headers+1] = attr_localized
end
--Retrieve the stats value from hero data
--Retrieve the stats value from hero data
stat_value = hero_data[attr_key]
stat_value = hero_data[attr_key]
Line 411: Line 399:
-- First header is Hero
-- First header is Hero
local headers_str = "<th>" .. "Hero" .. "</th>"
local headers_str = "<th>" .. "Hero" .. "</th>"
local header_style = ""
local category_data = attribute_module.get_category_data()
-- Turn headers list to string
-- Iterate stats again for displaying headers with their respective color
for index, header in ipairs(headers) do
for _, category in ipairs(attribute_orders["category_order"]) do
headers_str = headers_str .. "<th>" .. header .. "</th>"
category_attrs = attributes_data[category]
category_rgb = category_data[category]["rgb"]
-- Iterate attributes within the category
for _, attr_key in ipairs(attribute_orders[category]["attribute_order"]) do
attr_data = category_attrs[attr_key]
-- Localize, fallback to attr_key
attr_localized = lang_module._get_string(attr_data["label"])
if (attr_localized == nil) then attr_localized = attr_key end
header_style = ' style="background-color: ' .. "rgb(" .. category_rgb .. ') ;"'
headers_str = headers_str .. "<th" .. header_style .. ">" .. attr_localized .. "</th>"
end
end
end
headers_str = "<tr>" .. headers_str .. "</tr>"
headers_str = "<tr>" .. headers_str .. "</tr>"


return '<table class="wikitable sortable">' .. headers_str .. body_str .. "</table>"
return '<table class="wikitable sortable">' .. headers_str .. body_str .. "</table>"