Module:Sandbox/LVL: Difference between revisions

LVL (talk | contribs)
No edit summary
LVL (talk | contribs)
No edit summary
Line 188: Line 188:
--{{#invoke:HeroData|get_hero_scalar|HERO_NAME|SCALING_TYPE|STAT_NAME|sig_figs_or_localize}}--
--{{#invoke:HeroData|get_hero_scalar|HERO_NAME|SCALING_TYPE|STAT_NAME|sig_figs_or_localize}}--
p.get_hero_scalar = function(frame)
p.get_hero_scalar = function(frame)
local hero_key = frame.args[1]
    local hero_key = frame.args[1]
local scaling_type = frame.args[2]
    local scaling_type = frame.args[2]
local hero_stat_key = frame.args[3]
    local stat_key = frame.args[3]
local sig_figs_or_localize = frame.args[4]
   
    if not hero_key or not scaling_type or not stat_key then return "" end
local hero_data = heroes_data[hero_key]
   
if(hero_data == nil) then hero_data = p.get_json_item(hero_key) end
    local hero_data = heroes_data[hero_key]
if(hero_data == nil) then return "Hero not found." end
    if not hero_data then return "" end
   
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 not scaling_data then return "" end
   
local scaling_value = scaling_data[hero_stat_key]
    local scaling_value = scaling_data[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 not scaling_value or scaling_value == 0 then return "" end
 
   
--round
    -- Round to 3 sig figs
if (sig_figs_or_localize ~= nil and tonumber(sig_figs_or_localize) ~= nil) then
    scaling_value = tonumber(string.format("%.3g", scaling_value))
scaling_value = util_module.round_to_sig_fig(scaling_value, sig_figs_or_localize)
   
if (scaling_value == nil) then return "get_hero_scalar() error with rounding" end
    -- Return template (PI for Level, Ss for Spirit)
end
    local template_name = (scaling_type == "Level") and "PI" or "Ss"
    local template_args = { ["1"] = scaling_value }
--localize
   
if (sig_figs_or_localize == "true") then
    return mw.getCurrentFrame():expandTemplate{ title = "Template:" .. template_name, args = template_args }
return lang_module.get_string(scaling_value)
end
local scaling_str = p.write_scalar_str(scaling_value, scaling_type)
 
return scaling_str
end
end


Line 275: Line 269:
      
      
     local hero_data = heroes_data[hero_key]
     local hero_data = heroes_data[hero_key]
     if hero_data == nil then hero_data = p.get_json_item(hero_key) end
     if not hero_data then return "" end
     if hero_data == nil then return "" end
   
    -- Check base value (direct, not nested)
    local base_value = hero_data[stat_key]
     if base_value and tonumber(base_value) and tonumber(base_value) ~= 0 then
        return "1"
    end
      
      
     -- Check base value (uses existing helper function)
     -- Check LevelScaling (direct)
     local base_value = get_nested_stat_value(hero_data, stat_key)
     if hero_data.LevelScaling and hero_data.LevelScaling[stat_key] and hero_data.LevelScaling[stat_key] ~= 0 then
    if base_value ~= 0 then
         return "1"
         return "1" --Truthy value for #if
     end
     end
      
      
     -- Check scaling data (both Level and Spirit scaling)
     -- Check SpiritScaling (direct)
     local scaling_data = p.get_hero_scaling_data(hero_data, stat_key)
     if hero_data.SpiritScaling and hero_data.SpiritScaling[stat_key] and hero_data.SpiritScaling[stat_key] ~= 0 then
    if scaling_data ~= nil and next(scaling_data) ~= nil then
         return "1"
         return "1" --Has scaling data
     end
     end
      
      
     return "" --Falsy value for #if
     return ""
end
end