Editing Module:Abilities/utils

Jump to navigation Jump to search
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 19: Line 19:
end
end
return nil
return nil
end
-- Returns the key of the hero whose ability name is passed as an argument
--{{#invoke:Abilities/utils|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
-- Normalize input for case-insensitive comparison
local normalized_input = string.lower(ability_name)
-- 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 string.lower(current_name) == normalized_input then
return hero_key
end
end
end
return "Hero Not Found"
end
end


-- Add prefix and postfix labels to a value. Eg. "32" -> "32s"
-- Add prefix and postfix labels to a value. Eg. "32" -> "32s"
function p.format_value_with_prepost(key, value, frame, exclude_plus)
function p.format_value_with_prepost(key, value, frame, exclude_plus)
if (exclude_plus == nil) then exclude_plus = false end
if (value == nil) then return nil end
if (value == nil) then return nil end
Line 77: Line 50:
prefix = '+'
prefix = '+'
end
end
end
-- if no prefix on positive value, add a '+'
else
-- Do not assign a minus sign if value is already negative
if value > 0 then
if (prefix == '-' and value < 0) then
prefix = '+'
prefix = ''
end
end
end
Line 94: Line 67:
prefix..value,  
prefix..value,  
postfix,
postfix,
uom_style = 'font-size: 0.8em; color: #9C9C9C'
uom_style = 'font-size: 12px;'
}
}
}
}
Line 102: Line 75:


function p.get_notes_source_page_name(ability_key)  
function p.get_notes_source_page_name(ability_key)  
local ability_name_en = data["Name"]
local ability_name_localized = lang.get_string(ability_key)
local ability_name_localized = lang.get_string(ability_key)
local notes_str_localized = dictionary_module.translate('Notes', nil, '')
local notes_str_localized = dictionary_module.translate('Notes', nil, '')
Line 121: Line 95:
return notes_source_page
return notes_source_page
end
-- Generic function to traverse the table
-- A parameter can be passed that is numerical, like 2; and the function will
-- first try to access the key "2", otherwise it will look for the value at index=2 (3rd value)
function p.get_value(frame)
local args = frame.args
local value = item_data
for i = 1, #args do
local key = args[i]
-- First try string key
if type(value) == "table" and value[key] ~= nil then
value = value[key]
-- Then try numeric key if string didn't work
elseif type(value) == "table" then
local num_key = tonumber(key)
if num_key and value[num_key] ~= nil then
value = value[num_key]
else
return ""
end
else
return ""
end
end
-- Return final value, convert to string if not nil
if value == nil then
return ""
else
return tostring(value)
end
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