Module:Sandbox/LVL: Difference between revisionsGive feedback
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 438: | Line 438: | ||
--writes the massive hero comparison table for a specific PI and SP | --writes the massive hero comparison table for a specific PI and SP | ||
-- scaling icons are shown only if PI and SP are both 0 or both not provided | -- scaling icons are shown only if PI and SP are both 0 or both not provided | ||
--{{#invoke:HeroData|write_hero_comparison_table|POWER_INCREASES|SPIRIT_POWER}} | --{{#invoke:HeroData|write_hero_comparison_table|POWER_INCREASES|SPIRIT_POWER|sticky-header-bg=#333|sticky-cell-bg=#202020}} | ||
p.write_hero_comparison_table = function(frame) | p.write_hero_comparison_table = function(frame) | ||
local args = frame:getParent().args | |||
-- process inputs | -- process inputs | ||
local power_increases = | local power_increases = args[1] | ||
if (power_increases == nil) then power_increases = 0 end | if (power_increases == nil or power_increases == '') then power_increases = 0 end | ||
local spirit_power = | local spirit_power = args[2] | ||
if (spirit_power == nil) 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 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 | |||
local sticky_header_bg = (sticky_header_bg_arg and sticky_header_bg_arg ~= '') and sticky_header_bg_arg or '#333333' | |||
local sticky_cell_bg = (sticky_cell_bg_arg and sticky_cell_bg_arg ~= '') and sticky_cell_bg_arg or '#202122' | |||
-- Show scaling icons if power/increases/spirit power are 0/not specified | -- Show scaling icons if power/increases/spirit power are 0/not specified | ||
| Line 526: | Line 540: | ||
-- First column in each row is hero name. Make it sticky to the left for horizontal scrolling. | -- First column in each row is hero name. Make it sticky to the left for horizontal scrolling. | ||
row_str = row_str .. '<td style="position: sticky; left: 0; background-color: ' .. sticky_cell_bg .. ';">' .. hero_icon .. "</td>" | |||
row_str = row_str .. '<td style="position: sticky; left: 0; background-color: | |||
-- Consecutive columns are then stats | -- Consecutive columns are then stats | ||
| Line 594: | Line 607: | ||
-- First header is Hero. The top-left corner cell needs to be sticky in both directions. | -- First header is Hero. The top-left corner cell needs to be sticky in both directions. | ||
local headers_str = '<th style="position: sticky; top: 0; left: 0; z-index: 2; background-color: ' .. sticky_header_bg .. ';">' .. "Hero" .. "</th>" | |||
local headers_str = '<th style="position: sticky; top: 0; left: 0; z-index: 2; background-color: | local header_style | ||
local category_data = attribute_module.get_category_data() | local category_data = attribute_module.get_category_data() | ||
local postfix | local postfix | ||
| Line 611: | Line 624: | ||
["SpinDeceleration"] = "BonusFireRate_postfix" | ["SpinDeceleration"] = "BonusFireRate_postfix" | ||
} | } | ||
-- Base style for headers to avoid recreating the string in the loop | |||
local header_base_style = ' style="position: sticky; top: 0; z-index: 1; background-color: rgb(' | |||
-- Iterate stats again for displaying headers with their respective color | -- Iterate stats again for displaying headers with their respective color | ||
for _, category in ipairs(attribute_orders["category_order"]) do | for _, category in ipairs(attribute_orders["category_order"]) do | ||
category_attrs = attributes_data[category] | |||
category_rgb = category_data[category]["rgb"] | |||
-- Iterate attributes within the category | -- Iterate attributes within the category | ||
if (stats_to_include[category] ~= nil) then | if (stats_to_include[category] ~= nil) then | ||
for _, attr_key in ipairs(stats_to_include[category]) do | for _, attr_key in ipairs(stats_to_include[category]) do | ||
attr_data = category_attrs[attr_key] | |||
if (attr_data ~= nil) then | if (attr_data ~= nil) then | ||
| Line 648: | Line 660: | ||
end | end | ||
end | end | ||
-- Make header cells sticky to the top (for vertical scrolling). z-index: 1 keeps them above the body but below the corner cell. | |||
header_style = header_base_style .. category_rgb .. ');"' | |||
headers_str = headers_str .. "<th" .. header_style .. ">" .. attr_localized .. postfix .. "</th>" | headers_str = headers_str .. "<th" .. header_style .. ">" .. attr_localized .. postfix .. "</th>" | ||