Module:Abilities/details table: Difference between revisions

mNo edit summary
mNo edit summary
 
(8 intermediate revisions by the same user not shown)
Line 10: Line 10:
local hero_name = frame.args[1]
local hero_name = frame.args[1]
local ability_num = frame.args[2]
local ability_num = frame.args[2]
 
local ability = utils.get_ability_card_data(hero_name, ability_num)
local hero_key = utils.get_hero_key(hero_name)
local ability = utils.get_ability_card_data(hero_key, ability_num)
if(ability == nil) then error(string.format('Ability %s#%s not found', hero_name, ability_num)) end
if(ability == nil) then error(string.format('Ability %s#%s not found', hero_name, ability_num)) end


Line 61: Line 62:
end
end


local UPGRADE_COST_MAP = {1, 2, 5}
p.get_upgrade_table = function(frame)
p.get_upgrade_table = function(frame)
local hero_name = frame.args[1]
local hero_name = frame.args[1]
Line 66: Line 68:
local upgrade_num = frame.args[3]
local upgrade_num = frame.args[3]


local ability = utils.get_ability_card_data(hero_name, ability_num)
local hero_key = utils.get_hero_key(hero_name)
local ability = utils.get_ability_card_data(hero_key, ability_num)
if(ability == nil) then error(string.format('Ability %s#%s not found', hero_name, ability_num)) end
if(ability == nil) then error(string.format('Ability %s#%s not found', hero_name, ability_num)) end


local rows = ''
local rows = '\n|-\n'
local upgrade = ability.Upgrades[tonumber(upgrade_num)]
for i, upgrade in pairs(ability.Upgrades) do
for key, value in pairs(upgrade) do
local data_rows = ''
if key ~= 'DescKey' then
local scale_type = upgrade.Scale and upgrade.Scale.Type or nil
-- track number of attributes so we can assign the correct rowspan for the upgrade cost column
local scale_value = upgrade.Scale and upgrade.Scale.Value or nil
local num_of_attrs = 0
rows = rows .. create_row(key, value, scale_type, scale_value, frame)
for key, value in pairs(upgrade) do
if key ~= 'DescKey' then
local scale_type = upgrade.Scale and upgrade.Scale.Type or nil
local scale_value = upgrade.Scale and upgrade.Scale.Value or nil
data_rows = data_rows .. create_row(key, value, scale_type, scale_value, frame, true)
num_of_attrs = num_of_attrs + 1
end
end
end
rows = rows .. string.format("\n!rowspan=%s style=\"background-color: #121212; color: #FFEFD7; text-align: center; text-wrap: nowrap;\" | [[File:Ability_point_unlock_icon.png|20px|link=Ability_Point]] '''%s'''\n", num_of_attrs, UPGRADE_COST_MAP[i])
rows = rows .. data_rows
end
end


Line 83: Line 94:
end
end


function create_row(key, value, scale_type, scale_value, frame)
-- with_plus=true will include the "+" symbol before the number, as by default it will be omiitted
function create_row(key, value, scale_type, scale_value, frame, with_plus)
if key == nil or value == nil then
if key == nil or value == nil then
return ''
return ''
end
end
local label = lang._get_string(key..'_label')
-- get localized label, if none exists, fallback to one that is based on the key
if label == nil then
local label = lang.get_string(key..'_label')
label = commonutils.add_space_before_cap(key)
if label == '' then
label = commonutils.add_space_before_cap(key)
end
end
local formatted_value = utils.format_value_with_prepost(key, value, frame)
local formatted_value = utils.format_value_with_prepost(key, value, frame, with_plus~=true)
 
local row = '|' .. label .. '||' .. formatted_value
local row = '|' .. label .. '||' .. formatted_value
Line 100: Line 114:
end
end
return '\n|-\n' .. row
return row .. '\n|-\n'
end
end