Module:HeroData: Difference between revisions

Sur (talk | contribs)
m nul>nil typo
Sur (talk | contribs)
m get_hero_scalar_str slightly reworked
Line 38: Line 38:
end
end


--If the hero scales with the stat, it returns {{Ss|value}} or {{Ls|value}}, else blank string
--{{#invoke:HeroData|get_hero_scalar|HERO_NAME|SPIRIT_OR_LEVEL|STAT_NAME}}--
--{{#invoke:HeroData|get_hero_scalar|HERO_NAME|SPIRIT_OR_LEVEL|STAT_NAME}}--
p.get_hero_scalar = function(frame)
p.get_hero_scalar_str_invoke = function(frame)
local hero_name = frame.args[1]
local hero_name = frame.args[1]
local spirit_or_level = frame.args[2]
local spirit_or_level = frame.args[2]
local hero_stat_key = frame.args[3]
local hero_stat_key = frame.args[3]
return p.get_hero_scalar_str(hero_name, spirit_or_level, hero_stat_key) --surely theres a better way
end
function p.get_hero_scalar_str(hero_name, spirit_or_level, hero_stat_key)
--Ensure spirit or level is chosen
--Ensure spirit or level is chosen
if(not (spirit_or_level == "Spirit" or spirit_or_level == "Level")) then return "SPIRIT_OR_LEVEL must be 'Spirit' or 'Level'" end
if(not (spirit_or_level == "Spirit" or spirit_or_level == "Level")) then return "SPIRIT_OR_LEVEL must be 'Spirit' or 'Level'" end
local scaling_str = spirit_or_level .. "Scaling" --i.e. SpiritScaling or LevelScaling
local spirit_or_level_full = spirit_or_level .. "Scaling" --i.e. SpiritScaling or LevelScaling
local hero = get_json_item(hero_name)
local hero = get_json_item(hero_name)
Line 53: Line 58:
--Retrieve scaling data
--Retrieve scaling data
local hero_scaling = hero[scaling_str]
local hero_scaling_data = hero[spirit_or_level_full]
if(hero_scaling == nil) then return "" end
if(hero_scaling_data == nil) then return "" end
--Retrieve scaling value
--Retrieve scaling value
local hero_scalar = hero_scaling[hero_stat_key]
local hero_scalar = hero_scaling_data[hero_stat_key]
if(hero_scalar == nil) then return "" end
if(hero_scalar == nil) then return "" end
return hero_scalar
--The hero has a scaling value with this stat
local template_title = "Template:"
if (spirit_or_level == "Spirit") then
template_title = template_title .. "Ss"
else
template_title = template_title .. "Ls"
end
local template_args = {}
template_args["arg1"] = hero_scalar
local template_call = mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
return template_call
end
end