Module:HeroData: Difference between revisionsGive feedback
Jump to navigation
Jump to search
m hero comp; hide icons if PI/SS are 0/nil |
m get_hero_scalar_str split into it and get_hero_scalar |
||
| Line 90: | Line 90: | ||
-- Scaling string meaning the expanded template {{Ss|scalar}} or {{Ls|scalar}} | -- Scaling string meaning the expanded template {{Ss|scalar}} or {{Ls|scalar}} | ||
function p.get_hero_scalar_str(hero_data, hero_stat_key) | function p.get_hero_scalar_str(hero_data, hero_stat_key) | ||
local scaling_abbrevs = {Spirit = "Ss", Level = "Ls"} | |||
local scaling_value, scaling_type = p.get_hero_scalar(hero_data, hero_stat_key) | |||
-- Return blank if it doesnt scale | |||
if (scaling_value == 0) then return "" end | |||
-- Round it | |||
scaling_value = util_module.round_to_sig_fig(scaling_value, 3) | |||
--The hero has a scaling value with this stat | |||
local template_title = "Template:" .. scaling_abbrevs[scaling_type] --scaling type's abbreviation | |||
local template_args = {} | |||
template_args["1"] = scaling_value --store in 1st arg for {{{1}}} to grab it from {{SS}} or {{LS}} template | |||
local template_call = mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args } | |||
return template_call | |||
end | |||
-- Retrieve scaling value and type of a hero's given stat, if it has scaling, else return 0 | |||
function p.get_hero_scalar(hero_data, hero_stat_key) | |||
local scaling_type_full | local scaling_type_full | ||
local scaling_data | local scaling_data | ||
local scaling_value | local scaling_value | ||
local scaling_types = {"Spirit", "Level"} | local scaling_types = {"Spirit", "Level"} | ||
for index, scaling_type in ipairs(scaling_types) do | for index, scaling_type in ipairs(scaling_types) do | ||
| Line 106: | Line 127: | ||
--If the stat scales | --If the stat scales | ||
if (scaling_value ~= nil) then | if (scaling_value ~= nil) then | ||
return scaling_value, scaling_type | |||
end | end | ||
end | end | ||
end | end | ||
-- | -- If it doesn't scale, return 0 for value and empty string for scaling type | ||
return "" | return 0, "" | ||
end | end | ||