Module:Sandbox/LVL: Difference between revisionsGive feedback
No edit summary |
No edit summary |
||
| Line 465: | Line 465: | ||
display_scaling_icons = true | display_scaling_icons = true | ||
end | end | ||
-- Add hero comp stats to | -- Add hero comp stats to | ||
local stats_to_include = { | local stats_to_include = { | ||
Weapon = { | Weapon = { | ||
"DPS", | "DPS", "SustainedDPS", "BulletDamage", "RoundsPerSecond", "FireRate", "ClipSize", "ReloadTime", "ReloadDelay", "BulletsPerShot", "BulletsPerBurst", "BurstInterShotInterval", "LightMeleeDamage", "HeavyMeleeDamage", "ReloadSingle", "BulletSpeed", "BulletGravityScale", "FalloffStartRange", "FalloffEndRange", "BonusAttackRange", "RoundsPerSecondAtMaxSpin", "SpinAcceleration", "SpinDeceleration" | ||
}, | }, | ||
Vitality = { | Vitality = { | ||
"MaxHealth", | "MaxHealth", "BaseHealthRegen", "BulletResist", "TechResist", "CritDamageReceivedScale", "MaxMoveSpeed", "SprintSpeed", "StaminaCooldown", "Stamina" | ||
} | } | ||
} | } | ||
-- Use mw.html builder to construct the table safely | |||
local table = mw.html.create('table') | |||
:addClass('wikitable sortable') | |||
:cssText('table-layout: auto; width: 100%;') | |||
-- | -- Build Header | ||
local thead = table:tag('thead') | |||
local header_row = thead:tag('tr') | |||
-- Top-left corner cell | |||
header_row:tag('th') | |||
:cssText('position: sticky; top: 0; left: 0; z-index: 2; background-color: ' .. sticky_header_bg .. ';') | |||
:wikitext('Hero') | |||
local category_data = attribute_module.get_category_data() | |||
local postfix_key_map = { | |||
["ReloadDelay"] = "StatDesc_ReloadTime_postfix", ["BulletsPerShot"] = "", ["BulletsPerBurst"] = "", ["BurstInterShotInterval"] = "StatDesc_ReloadTime_postfix", ["ReloadSingle"] = "", ["BonusAttackRange"] = "StatDesc_WeaponRangeFalloffMax_postfix", ["SustainedDPS"] = "DPS_postfix", ["RoundsPerSecondAtMaxSpin"] = "", ["SpinAcceleration"] = "BonusFireRate_postfix", ["SpinDeceleration"] = "BonusFireRate_postfix" | |||
} | |||
for _, category in ipairs(attribute_orders["category_order"]) do | |||
local category_attrs = attributes_data[category] | |||
local category_rgb = category_data[category]["rgb"] | |||
if (stats_to_include[category] ~= nil) then | |||
for _, attr_key in ipairs(stats_to_include[category]) do | |||
local attr_data = category_attrs[attr_key] | |||
local attr_localized, postfix | |||
if (attr_data ~= nil) then | |||
attr_localized = lang_module.get_string(attr_data["label"]) | |||
if (attr_localized == nil or attr_localized == "") then attr_localized = util_module.add_space_before_cap(attr_key) end | |||
postfix = lang_module.get_string(attr_data["postfix"]) | |||
if (postfix == nil or postfix == "") then postfix = "" else postfix = " (" .. postfix .. ")" end | |||
else | |||
attr_localized = dictionary_module.translate(attr_key) | |||
postfix = lang_module.get_string(postfix_key_map[attr_key]) | |||
if postfix == nil then return "attr_key " .. attr_key .. " must be added to postfix_key_map" end | |||
if postfix ~= "" then postfix = " (" .. postfix .. ")" end | |||
end | |||
header_row:tag('th') | |||
:cssText('position: sticky; top: 0; z-index: 1; background-color: rgb(' .. category_rgb .. ');') | |||
:wikitext(attr_localized .. postfix) | |||
end | |||
end | |||
end | |||
-- Build Body | |||
local tbody = table:tag('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"] | |||
if (not in_development) then | if (not in_development) then | ||
is_disabled = hero_data["IsDisabled"] | local is_disabled = hero_data["IsDisabled"] | ||
if (not is_disabled) then | if (not is_disabled) then | ||
local body_row = tbody:tag('tr') | |||
local | -- Hero Icon cell | ||
local hero_name = localize(hero_key, hero_key) | |||
local hero_name_en = hero_data["Name"] | |||
local hero_icon_args = { [1] = hero_name_en, [2] = hero_name } | |||
local hero_icon = frame:expandTemplate{ title = "Template:HeroIcon", args = hero_icon_args } | |||
body_row:tag('td') | |||
:cssText('position: sticky; left: 0; z-index: 1; background-color: ' .. sticky_cell_bg .. ';') | |||
:wikitext(hero_icon) | |||
-- Stat cells | |||
-- | |||
for _, category in ipairs(attribute_orders["category_order"]) do | for _, category in ipairs(attribute_orders["category_order"]) do | ||
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 | ||
local stat_value = hero_data[attr_key] | |||
if (stat_value == nil) then stat_value = 0 end | if (stat_value == nil) then stat_value = 0 end | ||
local scaling_data = p.get_hero_scaling_data(hero_data, attr_key) | local scaling_data = p.get_hero_scaling_data(hero_data, attr_key) | ||
local scaling_strs = "" | local scaling_strs = "" | ||
if (scaling_data ~= nil) then | if (scaling_data ~= nil) then | ||
for | for scaling_val, scaling_type in pairs(scaling_data) do | ||
local scaling_str = p.write_scalar_str( | local scaling_str = p.write_scalar_str(scaling_val, scaling_type) | ||
if (scaling_str ~= "") then scaling_str = " " .. scaling_str end | if (scaling_str ~= "") then scaling_str = " " .. scaling_str end | ||
if (scaling_str ~= nil) then | if (scaling_str ~= nil) then scaling_strs = scaling_strs .. scaling_str end | ||
if (scaling_type == "Spirit") then | if (scaling_type == "Spirit") then | ||
stat_value = stat_value + (spirit_power * | stat_value = stat_value + (spirit_power * scaling_val) | ||
elseif (scaling_type == "Level") then | elseif (scaling_type == "Level") then | ||
if attr_key == 'TechResist' or attr_key == 'BulletResist' then | if attr_key == 'TechResist' or attr_key == 'BulletResist' then | ||
stat_value = (stat_value/100 + 1 - (1-scaling_val/100)^power_increases)*100 | |||
stat_value = (stat_value/100 + 1 - (1- | |||
else | else | ||
stat_value = stat_value + (power_increases * | stat_value = stat_value + (power_increases * scaling_val) | ||
end | end | ||
end | end | ||
| Line 579: | Line 570: | ||
if (not display_scaling_icons) then scaling_strs = "" end | if (not display_scaling_icons) then scaling_strs = "" end | ||
if (type(stat_value)) == 'boolean' then | if (type(stat_value)) == 'boolean' then | ||
stat_value = tostring(stat_value) | stat_value = tostring(stat_value) | ||
| Line 588: | Line 576: | ||
end | end | ||
body_row:tag('td'):wikitext(stat_value .. scaling_strs) | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
-- Final wrapper div | |||
local | local div = mw.html.create('div') | ||
return | :cssText('overflow-x: auto; width: 100%;') | ||
:node(table) | |||
return tostring(div) | |||
end | end | ||