Module:Abilities/card: Difference between revisions

Jump to navigation Jump to search
Switched sandbox template to use the actual template
Removed unused functions
Line 266: Line 266:
-- Create the ability card
-- Create the ability card
return p.get_ability_card_from_key(found_hero_key, found_ability_num, true, notes_str, notes_source_page_name)
return p.get_ability_card_from_key(found_hero_key, found_ability_num, true, notes_str, notes_source_page_name)
end
-- Get all info sections for specified ability
--{{#invoke:AbilityData|get_ability_card|HERO_KEY|ABILITY_NUM}}--
p.get_all_info_sections = function(frame)
local hero_key = frame.args[1]
local ability_num = frame.args[2]
local ability = utils.get_ability_card_data(hero_key, ability_num)
if(ability == nil) then return "Ability Not Found" end
local output_template = ''
for info_section_num=1, 10 do
local info_section = ability['Info'..info_section_num]
-- some abilities have no info sections
if info_section == nil then break end
local info_template = frame:expandTemplate{
title = "Ability_card_v2/Card/Info section",
args = {
hero_key = hero_key,
ability_num = ability_num,
info_section_num = info_section_num,
}
}
output_template = output_template .. info_template
end
return output_template
end
end


Line 331: Line 303:
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
return frame:preprocess(lang.get_string(info_section.DescKey))
return frame:preprocess(lang.get_string(info_section.DescKey))
end
--{{#invoke:AbilityData|get_info_main|HERO_KEY|ABILITY_NUM|INFO_SECTION_INDEX}}--
p.get_info_main = function(frame)
local hero_key = frame.args[1]
local ability_num = frame.args[2]
local info_section_num = frame.args[3]
local ability = utils.get_ability_card_data(hero_key, ability_num)
if(ability == nil) then return "Ability Not Found" end
local info_section = ability['Info'..info_section_num]
-- some abilities have no info sections
if info_section == nil then return '' end
local main = info_section.Main
if main == nil then
return ''
end
local props = info_section.Main.Props
-- Concatenate multiple section boxes into a single output template
local info_box_template = ''
for k, prop in pairs(props) do
-- Exclude 0 values
if prop.Value and prop.Value ~= 0 then
local icon = get_icon(prop.Type)
section_box = frame:expandTemplate{
title = "Ability_card_v2/Card/MainBox",
args = {
title = prop.Title,
key = prop.Key,
value = prop.Value,
icon = icon.img,
icon_link = icon.link,
icon_color = icon.color,
icon_size = icon.size,
scale_value = prop.Scale and commonutils.round_to_sig_fig(prop.Scale.Value, 3),
scale_type =  prop.Scale and prop.Scale.Type
}
}
info_box_template = info_box_template .. section_box .. '\n'
end
end
return info_box_template
end
end


Line 510: Line 434:
return upgrade_boxes
return upgrade_boxes
end
--{{#invoke:AbilityData|get_info_alt|HERO_KEY|ABILITY_NUM|INFO_SECTION_INDEX}}--
p.get_info_alt = function(frame)
local hero_key = frame.args[1]
local ability_num = frame.args[2]
local info_section_num = frame.args[3]
local ability = utils.get_ability_card_data(hero_key, ability_num)
if(ability == nil) then return "Ability Not Found" end
local info_section = ability['Info'..info_section_num]
-- some abilities have no info sections
if info_section == nil then return '' end
local props = info_section.Alt
if props == nil then
return ''
end
-- Concatenate multiple section boxes into a single output template
local info_box_template = ''
for k, prop in pairs(props) do
-- Some props don't have values, as those come from upgrades
-- For now, we will ignore these and only show data for the base ability
if prop.Value and prop.Value ~= 0 then
local icon = get_icon(prop.Type)
section_box = frame:expandTemplate{
title = "Ability_card_v2/Card/AltBox",
args = {
  key = prop.Key,
  value = prop.Value,
  icon = icon.img,
  icon_link = icon.link,
  icon_color = icon.color,
    icon_size = icon.size,
  scale_value = prop.Scale and commonutils.round_to_sig_fig(prop.Scale.Value, 3),
  scale_type =  prop.Scale and prop.Scale.Type
}
}
info_box_template = info_box_template .. section_box .. '\n'
end
end
return info_box_template
end
--{{#invoke:AbilityData|get_upgrades|HERO_KEY|ABILITY_NUM}}--
p.get_upgrades = function(frame)
local hero_key = frame.args[1]
local ability_num = frame.args[2]
local ability = utils.get_ability_card_data(hero_key, ability_num)
if(ability == nil) then return "Ability Not Found" end
local props = ability.Upgrades
-- Concatenate multiple section boxes into a single output template
local upgrades_template = ''
for k, prop in pairs(props) do
local description = lang.get_string(prop.DescKey)
-- Generate a description if there is no localized string
if (description == nil or description == '') then
description = create_description(prop, frame)
end
-- Vary the font size based on the number of characters to prevent overflow
local fontsize = '1rem'
if #description > 60 and #description < 71 then
fontsize = '0.95rem'
elseif #description > 70 and #description < 91 then
fontsize = '0.875rem'
elseif #description > 90 then
fontsize = '0.8rem'
end
box = frame:expandTemplate{
title = "Ability_card_v2/Card/UpgradeBox",
args = {
  cost = UPGRADE_COST_MAP[k],
  description = frame:preprocess(description),
  scale_value = prop.Scale and commonutils.round_to_sig_fig(prop.Scale.Value, 3),
  scale_type =  prop.Scale and prop.Scale.Type,
  fontsize = fontsize
}
}
upgrades_template = upgrades_template .. box .. '\n'
end
return upgrades_template
end
end