Module:HeroData: Difference between revisionsGive feedback
Jump to navigation
Jump to search
m arg1 for ss/ls call renamed to 1 |
m get_hero_scalar_str more dynamic to not require spirit/level input |
||
| Line 39: | Line 39: | ||
--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_str_invoke|HERO_NAME | --{{#invoke:HeroData|get_hero_scalar_str_invoke|HERO_NAME|STAT_NAME}}-- | ||
p.get_hero_scalar_str_invoke = function(frame) | p.get_hero_scalar_str_invoke = function(frame) | ||
local hero_name = frame.args[1] | local hero_name = frame.args[1] | ||
local | local hero_stat_key = frame.args[2] | ||
return p.get_hero_scalar_str(hero_name | return p.get_hero_scalar_str(hero_name, hero_stat_key) --surely theres a better way | ||
end | end | ||
function p.get_hero_scalar_str(hero_name | function p.get_hero_scalar_str(hero_name, hero_stat_key) | ||
local hero = get_json_item(hero_name) | local hero = get_json_item(hero_name) | ||
if(hero == nil) then return "Hero Not Found" end | if(hero == nil) then return "Hero Not Found" end | ||
local scaling_type_full | |||
local | local scaling_data | ||
local scaling_value = "" | |||
scaling_types = {"Spirit", "Level"} | |||
scaling_abbrevs = {"Ss", "Ls"} | |||
-- | for index, scaling_type in ipairs(scaling_types) do | ||
scaling_type_full = scaling_type .. "Scaling" | |||
scaling_data = hero[scaling_type_full] | |||
--If the scaling data exists | |||
if (scaling_data ~= nil) then | |||
scaling_value = scaling_data[hero_stat_key] | |||
--If the stat scales | |||
if (scaling_value ~= nil) then | |||
--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"] = hero_scalar --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 | ||
-- Otherwise return empty string | |||
return scaling_value | |||
return | |||
end | end | ||