Module:HeroData: Difference between revisions

Sur (talk | contribs)
m write_hero_comparison_table save
Sur (talk | contribs)
m write_hero_comparison_table fully functioning version
Line 358: Line 358:
local row_str = ""
local row_str = ""
local body_str = ""
local body_str = ""
local first_hero = true
Line 375: Line 374:
-- Consecutive columns are then stats
-- Consecutive columns are then stats
-- Iterate categories
-- Iterate categories
for category, category_attrs in pairs(attributes_data) do
for _, category in ipairs(attribute_orders["category_order"]) do
category_attrs = attributes_data[category]
-- Iterate attributes within the category
-- Iterate attributes within the category
for attr_key, attr_data in pairs(category_attrs) do
for _, attr_key in ipairs(attribute_orders[category]["attribute_order"]) do
-- Add the localized attribute to the headers hash list
attr_data = category_attrs[attr_key]
attr_localized = lang_module._get_string(attr_data["label"])
-- Default to attr_key if unlocalizable
-- If its the first iteration, add the attribute to the list of headers
if (attr_localized == nil) then attr_localized = attr_key end
if (first_hero) then
headers[attr_localized] = true
-- 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
Line 395: Line 400:
end
end
end
end
-- Add row to the body
-- 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  
first_hero = false
end
end
Line 405: Line 413:
-- Turn headers list to string
-- Turn headers list to string
for header, _ in pairs(headers) do
for index, header in ipairs(headers) do
headers_str = headers_str .. "<th>" .. header .. "</th>"
headers_str = headers_str .. "<th>" .. header .. "</th>"
end
end