Module:Sandbox/LVL: Difference between revisionsGive feedback
Jump to navigation
Jump to search
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 | ||
-- | -- Helper function to validate hex color code | ||
local | local function validate_color(color_str, default_color, param_name) | ||
if color_str and color_str ~= '' then | |||
-- Pattern for a 6-digit or 3-digit hex code | |||
if color_str:match("^#([0-9a-fA-F]{3})$") or color_str:match("^#([0-9a-fA-F]{6})$") then | |||
return color_str | |||
else | |||
-- Return an error for editors | |||
return '<strong class="error">Error: Invalid color format for ' .. param_name .. '. Please use a 3 or 6-digit hex code like #333 or #333333.</strong>' | |||
end | |||
end | |||
return default_color | |||
end | end | ||
local sticky_header_bg = ( | -- Allow overriding sticky background colors, trim whitespace and validate | ||
local sticky_cell_bg = ( | local sticky_header_bg = validate_color(mw.text.trim(args['sticky-header-bg'] or ''), '#333333', 'sticky-header-bg') | ||
local sticky_cell_bg = validate_color(mw.text.trim(args['sticky-cell-bg'] or ''), '#202122', 'sticky-cell-bg') | |||
-- Check if validation returned an error message | |||
if string.find(sticky_header_bg, "Error:") then return sticky_header_bg end | |||
if string.find(sticky_cell_bg, "Error:") then return sticky_cell_bg end | |||
-- 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 465: | Line 474: | ||
display_scaling_icons = true | display_scaling_icons = true | ||
end | end | ||
-- Initializations and declarations | |||
local body_rows = {} | |||
local header_cells = {} | |||
-- Add hero comp stats to | -- Add hero comp stats to | ||
| Line 475: | Line 488: | ||
} | } | ||
} | } | ||
-- Build Header | -- Build Header Cells | ||
table.insert(header_cells, '<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() | ||
local postfix_key_map = { | local postfix_key_map = { | ||
| Line 516: | Line 518: | ||
end | end | ||
local header_style = 'style="position: sticky; top: 0; z-index: 1; background-color: rgb(' .. category_rgb .. ');"' | |||
table.insert(header_cells, '<th ' .. header_style .. '>' .. attr_localized .. postfix .. '</th>') | |||
end | end | ||
end | end | ||
end | end | ||
-- Build Body | -- Build Body Rows | ||
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 530: | ||
local is_disabled = hero_data["IsDisabled"] | local is_disabled = hero_data["IsDisabled"] | ||
if (not is_disabled) then | if (not is_disabled) then | ||
local | local row_cells = {} | ||
-- Hero Icon cell | -- Hero Icon cell | ||
| Line 538: | Line 538: | ||
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(row_cells, '<td style="position: sticky; left: 0; z-index: 1; background-color: ' .. sticky_cell_bg .. ';">' .. hero_icon .. '</td>') | |||
-- Stat cells | -- Stat cells | ||
| Line 576: | Line 574: | ||
end | end | ||
table.insert(row_cells, '<td>' .. stat_value .. scaling_strs .. '</td>') | |||
end | end | ||
end | end | ||
end | end | ||
table.insert(body_rows, '<tr>' .. table.concat(row_cells) .. '</tr>') | |||
end | end | ||
end | end | ||
end | end | ||
-- Assemble the final table string | |||
local headers_str = '<thead><tr>' .. table.concat(header_cells) .. '</tr></thead>' | |||
local body_str = '<tbody>' .. table.concat(body_rows) .. '</tbody>' | |||
local table_str = '<table class="wikitable sortable" style="table-layout: auto; width: 100%;">' .. headers_str .. body_str .. '</table>' | |||
-- Final wrapper div | -- Final wrapper div | ||
return '<div style="overflow-x: auto; width: 100%;">' .. table_str .. '</div>' | |||
end | end | ||