Module:Abilities/card: Difference between revisionsGive feedback
mNo edit summary |
m Created initial function for using new "manual" ability card template |
||
| Line 121: | Line 121: | ||
local hero_key = get_hero_key(hero_name) | local hero_key = get_hero_key(hero_name) | ||
if (hero_key == nil) then return 'Hero with name' .. hero_name .. 'not found' end | |||
return get_ability_card_test(hero_key, ability_num, add_link, notes) | return get_ability_card_test(hero_key, ability_num, add_link, notes) | ||
| Line 146: | Line 147: | ||
end | end | ||
end | end | ||
local main_boxes = get_main_boxes(hero_key, ability_num, 1) | |||
local alt_boxes = get_alt_boxes(hero_key, ability_num, 1) | |||
local upgrades = get_upgrade_boxes(hero_key, ability_num) | |||
return mw.getCurrentFrame():expandTemplate{ | return mw.getCurrentFrame():expandTemplate{ | ||
title = "Ability card v2/ | title = "User:Saag/Sandbox/Ability card v2/manual card", | ||
args = { | args = { | ||
name = 'Some Ability', | |||
icon = 'Catalyst.png', | |||
name = | range = 99, | ||
radius = 99, | |||
icon = | duration = 99, | ||
num_of_charges = 99, | |||
radius = | charge_cooldown = 99, | ||
cooldown = 99, | |||
duration = 99, | |||
info1_desc = 'This ability does something', | |||
duration = | info1_mainbox1 = main_boxes[1], | ||
info1_mainbox2 = main_boxes[2], | |||
info1_mainbox3 = main_boxes[3], | |||
info1_altbox1 = alt_boxes[1], | |||
info1_altbox2 = alt_boxes[2], | |||
upgrade1 = upgrades[1], | |||
upgrade2 = upgrades[2], | |||
upgrade3 = upgrades[3] | |||
} | } | ||
} | } | ||
end | end | ||
| Line 323: | Line 326: | ||
return info_box_template | return info_box_template | ||
end | |||
function get_main_boxes(hero_key, ability_num, info_section_num) | |||
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 frame = mw.getCurrentFrame() | |||
local props = info_section.Main.Props | |||
local main_boxes = {} | |||
for k, prop in pairs(props) do | |||
-- Exclude 0 values | |||
if prop.Value and prop.Value ~= 0 then | |||
local icon = get_icon(prop.Type) | |||
local main_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 | |||
} | |||
} | |||
table.insert(main_boxes, main_box) | |||
end | |||
end | |||
return main_boxes | |||
end | |||
function get_alt_boxes(hero_key, ability_num, info_section_num) | |||
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 | |||
local frame = mw.getCurrentFrame() | |||
local alt_boxes = {} | |||
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) | |||
local alt_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 | |||
} | |||
} | |||
table.insert(alt_boxes, alt_box) | |||
end | |||
end | |||
return alt_boxes | |||
end | |||
local UPGRADE_COST_MAP = {1, 2, 5} | |||
function get_upgrade_boxes(hero_key, ability_num) | |||
local ability = utils.get_ability_card_data(hero_key, ability_num) | |||
if(ability == nil) then return "Ability Not Found" end | |||
local frame = mw.getCurrentFrame() | |||
local props = ability.Upgrades | |||
local upgrade_boxes = {} | |||
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 | |||
local upgrade_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 | |||
} | |||
} | |||
table.insert(upgrade_boxes, upgrade_box) | |||
end | |||
return upgrade_boxes | |||
end | end | ||
| Line 371: | Line 505: | ||
end | end | ||
--{{#invoke:AbilityData|get_upgrades|HERO_KEY|ABILITY_NUM}}-- | --{{#invoke:AbilityData|get_upgrades|HERO_KEY|ABILITY_NUM}}-- | ||
p.get_upgrades = function(frame) | p.get_upgrades = function(frame) | ||