Module:Sandbox/LVL: Difference between revisionsGive feedback
No edit summary |
No edit summary |
||
| Line 447: | Line 447: | ||
if (spirit_power == nil or spirit_power == '') then spirit_power = 0 end | if (spirit_power == nil or spirit_power == '') then spirit_power = 0 end | ||
-- | -- Allow overriding sticky background colors, trim whitespace for robustness | ||
local | local sticky_header_bg_arg = args['sticky-header-bg'] | ||
if sticky_header_bg_arg then | |||
sticky_header_bg_arg = mw.text.trim(sticky_header_bg_arg) | |||
end | |||
local sticky_cell_bg_arg = args['sticky-cell-bg'] | |||
if sticky_cell_bg_arg then | |||
sticky_cell_bg_arg = mw.text.trim(sticky_cell_bg_arg) | |||
end | end | ||
local sticky_header_bg = (sticky_header_bg_arg and sticky_header_bg_arg ~= '') and sticky_header_bg_arg or '#333333' | |||
local sticky_header_bg = | local sticky_cell_bg = (sticky_cell_bg_arg and sticky_cell_bg_arg ~= '') and sticky_cell_bg_arg or '#202122' | ||
local sticky_cell_bg = | |||
-- Show scaling icons if power/increases/spirit power are 0/not specified | -- Show scaling icons if power/increases/spirit power are 0/not specified | ||
local display_scaling_icons = false | local display_scaling_icons = false | ||
| Line 474: | Line 465: | ||
display_scaling_icons = true | display_scaling_icons = true | ||
end | end | ||
-- Add hero comp stats to | -- Add hero comp stats to | ||
| Line 489: | Line 476: | ||
} | } | ||
-- Build Header | -- Build the entire HTML structure as a list of strings, then concat once at the end. | ||
table.insert( | local html_parts = {} | ||
table.insert(html_parts, '<div style="overflow-x: auto; width: 100%;">') | |||
table.insert(html_parts, '<table class="wikitable sortable" style="table-layout: auto; width: 100%;">') | |||
-- Build Header | |||
table.insert(html_parts, '<thead><tr>') | |||
table.insert(html_parts, '<th style="position: sticky; top: 0; left: 0; z-index: 2; background-color: ' .. sticky_header_bg .. ';">Hero</th>') | |||
local category_data = attribute_module.get_category_data() | local category_data = attribute_module.get_category_data() | ||
| Line 519: | Line 513: | ||
local header_style = 'style="position: sticky; top: 0; z-index: 1; background-color: rgb(' .. category_rgb .. ');"' | local header_style = 'style="position: sticky; top: 0; z-index: 1; background-color: rgb(' .. category_rgb .. ');"' | ||
table.insert( | table.insert(html_parts, '<th ' .. header_style .. '>' .. attr_localized .. postfix .. '</th>') | ||
end | end | ||
end | end | ||
end | end | ||
table.insert(html_parts, '</tr></thead>') | |||
-- Build Body | -- Build Body | ||
table.insert(html_parts, '<tbody>') | |||
for hero_key, hero_data in pairs(heroes_data) do | for hero_key, hero_data in pairs(heroes_data) do | ||
local in_development = hero_data["InDevelopment"] | local in_development = hero_data["InDevelopment"] | ||
| Line 530: | Line 526: | ||
local is_disabled = hero_data["IsDisabled"] | local is_disabled = hero_data["IsDisabled"] | ||
if (not is_disabled) then | if (not is_disabled) then | ||
table.insert(html_parts, '<tr>') | |||
-- Hero Icon cell | -- Hero Icon cell | ||
| Line 538: | Line 534: | ||
local hero_icon = frame:expandTemplate{ title = "Template:HeroIcon", args = hero_icon_args } | local hero_icon = frame:expandTemplate{ title = "Template:HeroIcon", args = hero_icon_args } | ||
table.insert( | table.insert(html_parts, '<td style="position: sticky; left: 0; z-index: 1; background-color: ' .. sticky_cell_bg .. ';">' .. hero_icon .. '</td>') | ||
-- Stat cells | -- Stat cells | ||
| Line 574: | Line 570: | ||
end | end | ||
table.insert( | table.insert(html_parts, '<td>' .. stat_value .. scaling_strs .. '</td>') | ||
end | end | ||
end | end | ||
end | end | ||
table.insert( | table.insert(html_parts, '</tr>') | ||
end | end | ||
end | end | ||
end | end | ||
table.insert(html_parts, '</tbody>') | |||
table.insert(html_parts, '</table>') | |||
table.insert(html_parts, '</div>') | |||
return table.concat(html_parts) | |||
end | end | ||