Module:HeroData: Difference between revisions

Jump to navigation Jump to search
added melee resist and bullet lifesteal to attributes table
LVL (talk | contribs)
Added stat detection for scaling/boons; suppressed scaling error messages; fixed icon alignment.
Line 198: Line 198:
local scaling_data = hero_data[scaling_type .. "Scaling"]
local scaling_data = hero_data[scaling_type .. "Scaling"]
if scaling_data == nil then return scaling_type .. "Scaling data not found for hero" .. hero_key end
if scaling_data == nil then return "" end
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 "" end


--round
--round
Line 217: Line 217:


return scaling_str
return scaling_str
end
-- Check if a hero has a stat (Base, Boons, or Spirit Scaling)
-- Returns "true" if found, nil if not (for #if templates)
p.hero_has_stat = function(frame)
    local hero_key = frame.args[1]
    local stat_key = frame.args[2]
    if (hero_key == nil) then return nil end
   
    local hero_data = heroes_data[hero_key]
    if (hero_data == nil) then hero_data = p.get_json_item(hero_key) end
    if (hero_data == nil) then return nil end
    -- 1. Check Base Value
    -- We allow 0 if it's explicitly set, but usually we filter 0 for hiding.
    -- However, for resists, 0 usually means "hide", so we check ~= 0.
    local val = hero_data[stat_key]
    if (val ~= nil and val ~= 0) then return "true" end
    -- 2. Check Level Scaling (Boons)
    if (hero_data["LevelScaling"] ~= nil and hero_data["LevelScaling"][stat_key] ~= nil and hero_data["LevelScaling"][stat_key] ~= 0) then
        return "true"
    end
    -- 3. Check Spirit Scaling
    if (hero_data["SpiritScaling"] ~= nil and hero_data["SpiritScaling"][stat_key] ~= nil and hero_data["SpiritScaling"][stat_key] ~= 0) then
        return "true"
    end
    return nil
end
end


Line 224: Line 255:
local scaling_abbrevs = {Spirit = "Ss", Level = "PI"}
local scaling_abbrevs = {Spirit = "Ss", Level = "PI"}
-- Return blank if it doesnt scale
-- Return blank if it doesnt scale
if (scaling_value == 0) then return "" end
if (scaling_value == 0) then return "" end
Line 230: Line 261:
scaling_value = util_module.round_to_sig_fig(scaling_value, 3)
scaling_value = util_module.round_to_sig_fig(scaling_value, 3)
--The hero has a scaling value with this stat
--The hero has a scaling value with this stat
local template_title = "Template:" .. scaling_abbrevs[scaling_type] --scaling type's abbreviation
local template_title = "Template:" .. scaling_abbrevs[scaling_type]
local template_args = {}
local template_args = {}
template_args["1"] = scaling_value --store in 1st arg for {{{1}}} to grab it from {{SS}} or {{LS}} template
template_args["1"] = scaling_value
local template_call = mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
local template_call = mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
return template_call
   
return template_call:gsub("\n", ""):gsub("\r", "")
end
end