| Latest revision |
Your text |
| Line 2: |
Line 2: |
| local commonutils = require "Module:Utilities" | | local commonutils = require "Module:Utilities" |
| local lang = require"Module:Lang" | | local lang = require"Module:Lang" |
| local dictionary_module = require("Module:Dictionary")
| |
|
| |
|
| local data = mw.loadJsonData("Data:AbilityCards.json") | | local data = mw.loadJsonData("Data:AbilityCards.json") |
| Line 19: |
Line 18: |
| 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 63: |
Line 35: |
| value = tonumber(value:sub(1, -2)) | | value = tonumber(value:sub(1, -2)) |
| postfix = 'm' | | postfix = 'm' |
| end
| |
|
| |
| -- If string ends with 's', then set the postfix to 's' and remove it
| |
| if commonutils.string_endswith(tostring(value), 's') then
| |
| value = tonumber(value:sub(1, -2))
| |
| postfix = 's'
| |
| end | | end |
| | | |
| Line 77: |
Line 43: |
| 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 60: |
| prefix..value, | | prefix..value, |
| postfix, | | postfix, |
| uom_style = 'font-size: 0.8em; color: #9C9C9C' | | uom_style = 'font-size: 12px;' |
| } | | } |
| } | | } |
|
| |
|
| return value_and_uom | | return value_and_uom |
| end
| |
|
| |
| function p.get_notes_source_page_name(ability_key)
| |
| local ability_name_localized = lang.get_string(ability_key)
| |
| local notes_str_localized = dictionary_module.translate('Notes', nil, '')
| |
|
| |
| --Determine notes link
| |
| local notes_source_page
| |
| local notes_untranslated_msg = ''
| |
| -- if either "Notes" string or ability_name is not able to be localized,
| |
| -- use an english link instead, as transcluded content relies on it
| |
| if (ability_name_localized == '') or (notes_str_localized == '') then
| |
| notes_source_page = ability_name_en .. '/' .. dictionary_module.translate('Notes', 'en', '')
| |
| if notes_str_localized=='' then
| |
| notes_untranslated_msg = '<br>' .. dictionary_module.translate('NotesNeedsTranslation') .. ' [[Template:Translate]]' .. "<br>"
| |
| end
| |
| else
| |
| notes_source_page = ability_name_localized .. '/' .. notes_str_localized
| |
| end
| |
| notes_source_page = "User:Sur/" .. notes_source_page --temp
| |
|
| |
| return notes_source_page
| |
| end | | end |
|
| |
|
| return p | | return p |