Module:HeroData: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Remove unused write_infobox and write_stat_infoboxes functions |
Change hero comparison table to allow for users to input boons and spirit power so it'll update live. |
||
| Line 263: | Line 263: | ||
-- Retrieve scaling string of a hero's given stat, if it has scaling, else return blank | -- Retrieve scaling string of a hero's given stat, if it has scaling, else return blank | ||
-- Scaling string meaning the expanded template {{Ss|scalar}} or {{Ls|scalar}} | -- Scaling string meaning the expanded template {{Ss|scalar}} or {{Ls|scalar}} | ||
function p.write_scalar_str(scaling_value, scaling_type) | function p.write_scalar_str(scaling_value, scaling_type, compact) | ||
local scaling_abbrevs = {Spirit = "Ss", Level = "PI"} | local scaling_abbrevs = {Spirit = "Ss", Level = "PI"} | ||
| Line 276: | Line 276: | ||
local template_args = {} | local template_args = {} | ||
template_args["1"] = scaling_value | template_args["1"] = scaling_value | ||
if compact then template_args["compact"] = "yes" end | |||
local template_call = mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args } | local template_call = mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args } | ||
| Line 322: | Line 323: | ||
--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|MAX_POWER|MAX_SPIRIT}} | ||
p.write_hero_comparison_table = function(frame) | p.write_hero_comparison_table = function(frame) | ||
-- process inputs | -- process inputs (convert to numbers) | ||
local power_increases = frame.args[1] | local power_increases = tonumber(frame.args[1]) or 0 | ||
local spirit_power = tonumber(frame.args[2]) or 0 | |||
local | local max_power = tonumber(frame.args[3]) or 25 | ||
local max_spirit = tonumber(frame.args[4]) or 500 | |||
-- 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 400: | Line 401: | ||
end) | end) | ||
-- Iterate heroes | |||
for _, hero_entry in ipairs(sorted_heroes) do | for _, hero_entry in ipairs(sorted_heroes) do | ||
local hero_key = hero_entry.key | local hero_key = hero_entry.key | ||
| Line 433: | Line 434: | ||
--Retrieve the stats value from hero data | --Retrieve the stats value from hero data | ||
local base_value = get_nested_stat_value(hero_data, attr_key) | |||
local stat_value = base_value | |||
-- Retrieve scaling val and str if it scales | -- Retrieve scaling val and str if it scales | ||
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 = "" | ||
local spirit_scale = 0 | |||
local level_scale = 0 | |||
if (scaling_data ~= nil) then | if (scaling_data ~= nil) then | ||
for scaling_val, scaling_type in pairs(scaling_data) do | |||
local scaling_str = p.write_scalar_str(scaling_val, scaling_type, true) | |||
if (scaling_str ~= "") then scaling_str = " " .. scaling_str end | |||
if (scaling_str ~= nil) then | |||
scaling_strs = scaling_strs .. scaling_str | |||
end | |||
-- Track scaling values for data attributes | |||
if (scaling_type == "Spirit") then | if (scaling_type == "Spirit") then | ||
spirit_scale = scaling_val | |||
stat_value = stat_value + (spirit_power * scaling_val) | |||
elseif (scaling_type == "Level") then | elseif (scaling_type == "Level") then | ||
level_scale = scaling_val | |||
stat_value = stat_value + (power_increases * scaling_val) | |||
end | end | ||
end | |||
end | |||
-- TechPower gains 1:1 with user-input Spirit Power (only if not already defined) | |||
if attr_key == 'TechPower' and spirit_scale == 0 then | |||
spirit_scale = 1.0 | |||
stat_value = stat_value + (spirit_power * spirit_scale) | |||
end | end | ||
-- Calculate innate TechPower scaling for this hero | |||
local innate_spirit_scale = (hero_data["LevelScaling"] and hero_data["LevelScaling"]["TechPower"]) or 0 | |||
-- Hide scaling icons if not at base values | |||
if (not display_scaling_icons) then scaling_strs = "" end | if (not display_scaling_icons) then scaling_strs = "" end | ||
-- Convert from boolean to string, or round it | -- Convert from boolean to string, or round it | ||
if (type(stat_value)) == 'boolean' then | if (type(stat_value)) == 'boolean' then | ||
stat_value = tostring(stat_value) | |||
else | else | ||
stat_value = util_module.round_to_sig_fig(stat_value, 3) | |||
end | end | ||
-- Keep numeric value in its own span, scaling HTML as sibling | |||
local cell_inner = string.format( | |||
'<span class="stat-num">%s</span><span class="stat-scaling">%s</span>', | |||
stat_value, | |||
scaling_strs | |||
) | |||
-- At the point where you build data_attrs for DPS/SustainedDPS cells | |||
local hit_once = "false" | |||
if (attr_key == 'DPS' or attr_key == 'SustainedDPS') and hero_data.Weapon and hero_data.Weapon.HitOnceAcrossAllBullets then | |||
hit_once = "true" | |||
end | |||
local data_attrs = string.format( | |||
'data-stat-name="%s" data-base="%s" data-spirit-scale="%s" data-level-scale="%s" data-innate-spirit-scale="%s" data-sort-value="%s" data-hit-once="%s"', | |||
attr_key, | |||
tostring(type(base_value) == "number" and util_module.round_to_sig_fig(base_value, 3) or base_value), | |||
tonumber(spirit_scale) or 0, | |||
(attr_key == "TechPower") and "0" or (tonumber(level_scale) or 0), | |||
innate_spirit_scale or 0, | |||
stat_value, | |||
hit_once | |||
) | |||
-- Add it to the row | -- Add it to the row | ||
row_str = row_str .. | row_str = row_str .. string.format('<td style="white-space: nowrap;" %s>%s</td>', data_attrs, cell_inner) | ||
end | end | ||
end | end | ||
| Line 541: | Line 579: | ||
headers_str = "<tr>" .. headers_str .. "</tr>" | headers_str = "<tr>" .. headers_str .. "</tr>" | ||
local table_str = '< | -- Wrap table in container with data attributes for JS | ||
local table_str = string.format( | |||
return | '<div id="hero-comparison-container" data-max-power="%s" data-max-spirit="%s">' .. | ||
'<div style="overflow: auto; max-height: 70vh; width: 100%%;">' .. | |||
'<table class="wikitable sortable" style="table-layout: auto; width: 100%%;" id="hero-comparison-table">%s%s</table>' .. | |||
'</div></div>', | |||
max_power, | |||
max_spirit, | |||
headers_str, | |||
body_str | |||
) | |||
return table_str | |||
end | end | ||