Module:Abilities: Difference between revisionsGive feedback
removed find_hero_by_ability, function already exists in Module:Abilities/utils |
mNo edit summary Tag: Undo |
||
| (7 intermediate revisions by 3 users not shown) | |||
| Line 60: | Line 60: | ||
local ui_data = data[hero_name] | local ui_data = data[hero_name] | ||
if(ui_data == nil) then return "Hero Not Found" end | 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 | -- Iterate through the hero's abilities to find matching name | ||
for ability_num, ability in pairs(ui_data) do | for ability_num, ability in pairs(ui_data) do | ||
local current_name = Lang.get_string(ability.Key) | local current_name = Lang.get_string(ability.Key) | ||
if current_name == | if string.lower(current_name) == normalized_input then | ||
return ability_num | return ability_num | ||
end | end | ||
| Line 124: | Line 127: | ||
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 145: | Line 148: | ||
-- 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 | if prop and prop ~= "" then | ||
for segment in string.gmatch(prop, "[^%.]+") do | |||
-- If upgrade is not a table, return value. If it is, check for segments | |||
if type(element) ~= "table" then | |||
return element or "" | |||
end | |||
element = element[segment] | |||
if element == nil then return "" end | |||
end | |||
end | end | ||