Module:Sandbox/LVL: Difference between revisions

LVL (talk | contribs)
No edit summary
LVL (talk | contribs)
No edit summary
Line 73: Line 73:
p.get_ability_upgrade_prop = function(frame)
p.get_ability_upgrade_prop = function(frame)
local ability_identifier = frame.args[1]
local ability_identifier = frame.args[1]
local upgrade_num_str = frame.args[2]
local upgrade_num_str = frame.args[2]
local prop = frame.args[3]
local prop             = frame.args[3]
local debug            = frame.args.debug      -- ← NEW
-- Check for missing arguments
 
if not (ability_identifier and upgrade_num_str and prop) then
if not (ability_identifier and upgrade_num_str and prop) then
return "Missing Arguments" -- Or return ""
return debug and "Missing args" or ""
end
end


-- Find the base ability data
local ability = find_json_ability(ability_identifier)
local ability = find_json_ability(ability_identifier)
if not ability then
if not ability then
return "Ability Not Found"
return debug and "Ability not found" or ""
end
end


-- Get the list of upgrades for this ability
local upgrades = ability.Upgrades
local upgrades = ability.Upgrades
if not upgrades or type(upgrades) ~= "table" then
if type(upgrades) ~= "table" then
return "No Upgrades Found"
return debug and "No upgrades" or ""
end
end


-- Convert the upgrade number from a string to an integer
local upgrade_num = tonumber(upgrade_num_str)
local upgrade_num = tonumber(upgrade_num_str)
if not upgrade_num then
if not upgrade_num or not upgrades[upgrade_num] then
return "Invalid Upgrade Number"
return debug and "Upgrade not found" or ""
end
end
 
-- Get the specific upgrade table from the list (Lua tables are 1-indexed)
local element = upgrades[upgrade_num][prop]
local upgrade = upgrades[upgrade_num]
if not upgrade or type(upgrade) ~= "table" then
return "Upgrade Not Found"
end
-- Get the desired property from the specific upgrade
local element = upgrade[prop]
if element == nil then
if element == nil then
return "" -- The property doesn't exist in this specific upgrade, which is a valid case. Return empty.
return debug and "Prop missing" or ""
end
 
-- If the property is a table (like a Damage object), return its Value field
if type(element) == "table" then
    return element.Value or ""
end
end


-- Otherwise, return the direct value
-- return the value (number or string) directly
return element
local out = type(element) == "table" and (element.Value or "") or tostring(element)
return debug and ("→"..out.."←") or out
end
end




return p
return p