Editing Module:Abilities

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 24: Line 24:
end
end
-- If not found by key, search for key by ability name
-- If not found by key, loop through and search by the "Name" property as a fallback
local resource_lookup = mw.loadJsonData("Data:ResourceLookup.json")
for _, v in pairs(raw_ability_data) do
local ability_resource = resource_lookup[identifier:lower()]
if (v["Name"] == identifier) then
return v
end
end
if (ability_resource) then
return raw_ability_data[ability_resource.key]
end
-- If not found by either method, return nil
-- If not found by either method, return nil
return nil
return nil
end
end


--{{#invoke:Abilities|get_ability_name|HERO_NAME|ABILITY_NUM|lang=LANG_CODE}}--
--{{#invoke:AbilityData|get_ability_name|HERO_NAME|ABILITY_NUM|lang=LANG_CODE}}--
p.get_ability_name = function(frame)
p.get_ability_name = function(frame)
local hero_name = frame.args[1]
local hero_name = frame.args[1]
Line 49: Line 48:
end
end


return Lang.get_string(ability.Key)
return ability.Name
end
 
-- Reverse function of get_ability_name
--{{#invoke:Abilities|get_ability_number|HERO_NAME|ABILITY_NAME}}--
p.get_ability_number = function(frame)
local hero_name = frame.args[1]
local ability_name = frame.args[2]
local ui_data = data[hero_name]
if(ui_data == nil) then return "Hero Not Found" end
-- Normalize input for case-insensitive comparison
local normalized_input = string.lower(ability_name)
-- Iterate through the hero's abilities to find matching name
for ability_num, ability in pairs(ui_data) do
local current_name = Lang.get_string(ability.Key)
if string.lower(current_name) == normalized_input then
return ability_num
end
end
return "Ability Not Found"
end
end


--{{#invoke:Abilities|get_ability_prop|ability_key_or_name|prop}}--
--{{#invoke:AbilityData|get_ability_prop|ability_key_or_name|prop}}--
p.get_ability_prop = function(frame)
p.get_ability_prop = function(frame)
local ability_identifier = frame.args[1]
local ability_identifier = frame.args[1]
Line 84: Line 60:
if(ability == nil) then return "Ability Not Found" end
if(ability == nil) then return "Ability Not Found" end


-- Handle nested properties via dot notation (e.g., "MaxRage.Scale.Value")
local element = ability[prop]
local element = ability
if prop and prop ~= "" then
for segment in string.gmatch(prop, "[^%.]+") do
if type(element) ~= "table" then
return "" -- Can't traverse further
end
element = element[segment]
if element == nil then return "" end
end
end
if element == nil then return "" end
if element == nil then return "" end


Line 107: Line 72:
end
end


--{{#invoke:Abilities|get_ability_upgrade_prop|ability_key_or_name|upgrade_num|prop}}--
--{{#invoke:AbilityData|get_ability_upgrade_prop|ability_key_or_name|upgrade_num|prop}}--
-- Gets a specific property from a specific upgrade of an ability.
-- Gets a specific property from a specific upgrade of an ability.
-- @param {string} frame.args[1] - The ability's key (e.g., "ability_afterburn") or name (e.g., "Afterburn").
-- @param {string} frame.args[1] - The ability's key (e.g., "ability_afterburn") or name (e.g., "Afterburn").
Line 127: Line 92:
return "Ability Not Found"
return "Ability Not Found"
end
end
 
-- Get the list of upgrades for this ability
-- Get the list of upgrades for this ability
local upgrades = ability.Upgrades
local upgrades = ability.Upgrades
Line 148: Line 113:
-- Get the desired property from the specific upgrade
-- Get the desired property from the specific upgrade
local element = upgrade[prop]
local element = upgrade[prop]
if prop and prop ~= "" then
if element == nil then
for segment in string.gmatch(prop, "[^%.]+") do
return "" -- The property doesn't exist in this specific upgrade, which is a valid case. Return empty.
-- If upgrade is not a table, return value. If it is, check for segments
end
if type(element) ~= "table" then
 
return element or ""
-- If the property is a table (like a Damage object), return its Value field
end
if type(element) == "table" then
element = element[segment]
    return element.Value or ""
if element == nil then return "" end
end
end
end


Line 162: Line 125:
return element
return element
end
end


return p
return p
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template