Module:HeroData: Difference between revisions

Sur (talk | contribs)
m hero comp; hide icons if PI/SS are 0/nil
Sur (talk | contribs)
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"}
local scaling_abbrevs = {"Ss", "Ls"}
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
scaling_value = util_module.round_to_sig_fig(scaling_value, 3)
return scaling_value, scaling_type
--The hero has a scaling value with this stat
local template_title = "Template:" .. scaling_abbrevs[index] --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
end
end
end
end
end
-- Otherwise return empty string
-- If it doesn't scale, return 0 for value and empty string for scaling type
return ""
return 0, ""
end
end