Module:HeroData: Difference between revisions

Jump to navigation Jump to search
No edit summary
rounding function for get_hero_scalar
Line 139: Line 139:


--If the hero scales with the stat, it returns {{Ss|value}} or {{Ls|value}}, else blank string
--If the hero scales with the stat, it returns {{Ss|value}} or {{Ls|value}}, else blank string
--{{#invoke:HeroData|get_hero_scalar|HERO_NAME|SCALING_TYPE|STAT_NAME}}--
--{{#invoke:HeroData|get_hero_scalar|HERO_NAME|SCALING_TYPE|STAT_NAME|sig_figs_or_localize}}--
p.get_hero_scalar = function(frame)
p.get_hero_scalar = function(frame)
local hero_key = frame.args[1]
local hero_key = frame.args[1]
Line 154: Line 154:
local scaling_value = scaling_data[hero_stat_key]
local scaling_value = scaling_data[hero_stat_key]
if scaling_value == nil then return scaling_type .. "Scaling data does not have key " .. hero_stat_key .. " for hero " .. hero_key end
if scaling_value == nil then return scaling_type .. "Scaling data does not have key " .. hero_stat_key .. " for hero " .. hero_key end
--round
if (sig_figs_or_localize ~= nil and tonumber(sig_figs_or_localize) ~= nil) then
scaling_value = util_module.round_to_sig_fig(var_value, sig_figs_or_localize)
if (scaling_value == nil) then return "get_hero_var() error with rounding" end
end
--localize
if (sig_figs_or_localize == "true") then
return lang_module.get_string(scaling_value)
end
local scaling_str = p.write_scalar_str(scaling_value, scaling_type)
local scaling_str = p.write_scalar_str(scaling_value, scaling_type)
if (scaling_str ~= "") then scaling_str = " " .. scaling_str end
if (scaling_str ~= "") then scaling_str = " " .. scaling_str end
return scaling_str
return scaling_str
end
end