Editing Module:Abilities/utilsGive feedback
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 1: | Line 1: | ||
local p = {} | local p = {} | ||
local lang = require"Module:Lang" | local lang = require"Module:Lang" | ||
local data = mw.loadJsonData("Data:AbilityCards.json") | local data = mw.loadJsonData("Data:AbilityCards.json") | ||
-- returns the table of a specific item | -- returns the table of a specific item | ||
function p.get_ability_card_data( | function p.get_ability_card_data(hero_name, ability_num) | ||
local hero_key = get_hero_key(hero_name) | |||
if(hero_key == nil) then return nil end | if(hero_key == nil) then return nil end | ||
return data[hero_key][tonumber(ability_num)] | return data[hero_key][tonumber(ability_num)] | ||
end | end | ||
function | function get_hero_key(hero_name) | ||
for i, hero in pairs(data) do | for i, hero in pairs(data) do | ||
if hero["Name"] == hero_name then | if hero["Name"] == hero_name then | ||
| Line 19: | Line 18: | ||
end | end | ||
return nil | return nil | ||
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 | function p.format_value_with_prepost(key, value, frame) | ||
if (value == nil) then return nil end | if (value == nil) then return nil end | ||
local prefix = lang. | local prefix = lang._get_string(string.format("%s_prefix",key)) | ||
local postfix = lang. | local postfix = lang._get_string(string.format("%s_postfix",key)) | ||
-- Default pre/post fix to empty string, as they may not exist | -- Default pre/post fix to empty string, as they may not exist | ||
| Line 60: | Line 32: | ||
-- If string ends with 'm', then set the postfix to 'm' and remove it | -- If string ends with 'm', then set the postfix to 'm' and remove it | ||
if | if utils.string_endswith(tostring(value), 'm') then | ||
value = tonumber(value:sub(1, -2)) | value = tonumber(value:sub(1, -2)) | ||
postfix = 'm' | postfix = 'm' | ||
end | end | ||
| Line 74: | Line 40: | ||
if value < 0 then | if value < 0 then | ||
prefix = '-' | prefix = '-' | ||
else | else | ||
prefix = '+' | |||
end | |||
-- if no prefix on positive value, add a '+' | |||
else | |||
if value > 0 then | |||
prefix = '+' | prefix = '+' | ||
end | end | ||
end | end | ||
| Line 94: | Line 55: | ||
prefix..value, | prefix..value, | ||
postfix, | postfix, | ||
uom_style = 'font-size: | uom_style = 'font-size: 12px;' | ||
} | } | ||
} | } | ||
return value_and_uom | return value_and_uom | ||
end | end | ||
return p | return p | ||