Module:Abilities: Difference between revisionsGive feedback
Added dot notation support for nested properties in get_ability_prop |
added get_ability_number, corrected example calls for functions in comments |
||
| Line 36: | Line 36: | ||
end | end | ||
--{{#invoke: | --{{#invoke:Abilities|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 52: | Line 52: | ||
end | end | ||
--{{#invoke: | -- 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 | |||
-- 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 current_name == ability_name then | |||
return ability_num | |||
end | |||
end | |||
return "Ability Not Found" | |||
end | |||
--{{#invoke:Abilities|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 104: | ||
end | end | ||
--{{#invoke: | --{{#invoke:Abilities|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 136: | Line 156: | ||
-- Otherwise, return the direct value | -- Otherwise, return the direct value | ||
return element | return element | ||
end | |||
--{{#invoke:Abilities|find_hero_by_ability|ABILITY_NAME}}-- | |||
p.find_hero_by_ability = function(frame) | |||
local ability_name = frame.args[1] | |||
if not ability_name or ability_name == "" then | |||
return "Missing Ability Name" | |||
end | |||
-- Iterate through all heroes in the data | |||
for hero_key, ui_data in pairs(data) do | |||
-- Check each ability for this hero | |||
for ability_num, ability in pairs(ui_data) do | |||
local current_name = Lang.get_string(ability.Key) | |||
if current_name == ability_name then | |||
return hero_key | |||
end | |||
end | |||
end | |||
return "Hero Not Found" | |||
end | end | ||
return p | return p | ||