Module:Sandbox/LVL: Difference between revisionsGive feedback
Jump to navigation
Jump to search
No edit summary Tag: Manual revert |
No edit summary |
||
| Line 10: | Line 10: | ||
local hero_data_module = require('Module:HeroData') | local hero_data_module = require('Module:HeroData') | ||
local function get_nested_stat_value(hero_data, stat_key) | local function get_nested_stat_value(hero_data, stat_key, prefer_alt_fire) | ||
if prefer_alt_fire and hero_data.Weapon and hero_data.Weapon.AltFire and hero_data.Weapon.AltFire[stat_key] ~= nil then | |||
return hero_data.Weapon.AltFire[stat_key] | |||
end | |||
if hero_data[stat_key] ~= nil then | if hero_data[stat_key] ~= nil then | ||
return hero_data[stat_key] | return hero_data[stat_key] | ||
| Line 104: | Line 107: | ||
end) | end) | ||
local function build_hero_row(hero_entry, is_alt_row) | |||
local hero_key = hero_entry.key | local hero_key = hero_entry.key | ||
local hero_data = hero_entry.data | local hero_data = hero_entry.data | ||
local row_str = "" | local row_str = "" | ||
hero_name = localize(hero_key, hero_key) | local hero_name = localize(hero_key, hero_key) | ||
hero_name_en = hero_data["Name"] | local hero_name_en = hero_data["Name"] | ||
if is_alt_row then | |||
hero_name = hero_name .. " (Alt-fire)" | |||
end | |||
template_args = {[1] = hero_name_en, l1 = hero_name} | local template_args = {[1] = hero_name_en, l1 = hero_name} | ||
hero_icon = mw.getCurrentFrame():expandTemplate{ title = "Template:HeroIcon", args = template_args } | local hero_icon = mw.getCurrentFrame():expandTemplate{ title = "Template:HeroIcon", args = template_args } | ||
row_str = row_str .. | row_str = row_str .. | ||
| Line 124: | Line 129: | ||
for _, attr_key in ipairs(stats_to_include[category]) do | for _, attr_key in ipairs(stats_to_include[category]) do | ||
local base_value = get_nested_stat_value(hero_data, attr_key) | local base_value = get_nested_stat_value(hero_data, attr_key, is_alt_row) | ||
local stat_value = base_value | local stat_value = base_value | ||
local scaling_data = | local scaling_data = nil | ||
local scaling_strs = "" | local scaling_strs = "" | ||
local spirit_scale = 0 | local spirit_scale = 0 | ||
local level_scale = 0 | local level_scale = 0 | ||
if is_alt_row then | |||
scaling_data = hero_data_module.get_hero_scaling_data(hero_data, attr_key .. "AltFire") | |||
end | |||
if scaling_data == nil then | |||
scaling_data = hero_data_module.get_hero_scaling_data(hero_data, attr_key) | |||
end | |||
if scaling_data ~= nil then | if scaling_data ~= nil then | ||
| Line 172: | Line 184: | ||
local hit_once = "false" | local hit_once = "false" | ||
if (attr_key == "DPS" or attr_key == "SustainedDPS") | if (attr_key == "DPS" or attr_key == "SustainedDPS") then | ||
and hero_data.Weapon | if not is_alt_row then | ||
and hero_data.Weapon.HitOnceAcrossAllBullets | if hero_data.Weapon and hero_data.Weapon.HitOnceAcrossAllBullets then | ||
hit_once = "true" | |||
end | |||
else | |||
if hero_data.Weapon and hero_data.Weapon.AltFire and hero_data.Weapon.AltFire.HitOnceAcrossAllBullets then | |||
hit_once = "true" | |||
end | |||
end | |||
end | end | ||
| Line 196: | Line 213: | ||
end | end | ||
return "<tr>" .. row_str .. "</tr>" | |||
end | |||
-- Build table body rows | |||
for _, hero_entry in ipairs(sorted_heroes) do | |||
body_str = body_str .. build_hero_row(hero_entry, false) | |||
if hero_entry.data.Weapon and hero_entry.data.Weapon.AltFire then | |||
body_str = body_str .. build_hero_row(hero_entry, true) | |||
end | |||
end | end | ||
| Line 208: | Line 234: | ||
for _, attr_key in ipairs(stats_to_include[category]) do | for _, attr_key in ipairs(stats_to_include[category]) do | ||
local scaling_data = hero_data_module.get_hero_scaling_data(hero_data, attr_key) | local scaling_data = hero_data_module.get_hero_scaling_data(hero_data, attr_key) | ||
if scaling_data ~= nil and next(scaling_data) ~= nil then | local alt_scaling_data = nil | ||
if hero_data.Weapon and hero_data.Weapon.AltFire then | |||
alt_scaling_data = hero_data_module.get_hero_scaling_data(hero_data, attr_key .. "AltFire") | |||
end | |||
local has_scaling = (scaling_data ~= nil and next(scaling_data) ~= nil) | |||
local has_alt_scaling = (alt_scaling_data ~= nil and next(alt_scaling_data) ~= nil) | |||
if has_scaling or has_alt_scaling then | |||
stats_with_any_scaling[attr_key] = true | stats_with_any_scaling[attr_key] = true | ||
local has_spirit = false | local has_spirit = false | ||
local has_level = false | local has_level = false | ||
for _, scaling_type in pairs(scaling_data) do | if has_scaling then | ||
if scaling_type == "Spirit" then has_spirit = true end | for _, scaling_type in pairs(scaling_data) do | ||
if scaling_type == "Spirit" then has_spirit = true end | |||
if scaling_type == "Level" then has_level = true end | |||
end | |||
end | |||
if has_alt_scaling then | |||
for _, scaling_type in pairs(alt_scaling_data) do | |||
if scaling_type == "Spirit" then has_spirit = true end | |||
if scaling_type == "Level" then has_level = true end | |||
end | |||
end | end | ||
if has_spirit and has_level then | if has_spirit and has_level then | ||