Module:Abilities/card: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Ignore ability_fencer_ultimate_t3_desc key as it is not used in game |
Added status effects and support for dynamic cards |
||
| Line 20: | Line 20: | ||
move_speed = {img='Move speed.png', link='Move Speed', color = 'Green'}, | move_speed = {img='Move speed.png', link='Move Speed', color = 'Green'}, | ||
range = {img='CastRange.png', link='Ability_Range', color = 'Purple'}, | range = {img='CastRange.png', link='Ability_Range', color = 'Purple'}, | ||
radius = {img='CastRange.png', link='Ability_Range', color = 'Purple'}, | |||
tech_armor_up = {img='Spirit_Armor.png', link='Damage_Resistance', color = 'NoColor'}, | tech_armor_up = {img='Spirit_Armor.png', link='Damage_Resistance', color = 'NoColor'}, | ||
tech_damage = {img='AttributeIconTechShieldHealth.png', link='Spirit_Damage', color = 'NoColor',size = '12px'}, | tech_damage = {img='AttributeIconTechShieldHealth.png', link='Spirit_Damage', color = 'NoColor',size = '12px'}, | ||
| Line 30: | Line 31: | ||
time = {img='AttributeIconTechDuration.png', link='Ability Duration', color = 'Purple'}, | time = {img='AttributeIconTechDuration.png', link='Ability Duration', color = 'Purple'}, | ||
} | } | ||
-- TODO - replace this with utils file | |||
function utils.get_ability_card_data(hero_key, ability_num) | |||
if(hero_key == nil) then return nil end | |||
return data[hero_key][tonumber(ability_num)] | |||
end | |||
function get_hero_key(hero_name) | function get_hero_key(hero_name) | ||
| Line 136: | Line 144: | ||
title = "Ability_card_v2/Card", | title = "Ability_card_v2/Card", | ||
args = { | args = { | ||
id = hero_key .. ':' .. ability.Key, | |||
hero_key = hero_key, | hero_key = hero_key, | ||
ability_num = ability_num, | ability_num = ability_num, | ||
| Line 160: | Line 169: | ||
-- Info section #1 defined in "Info1" attribute | -- Info section #1 defined in "Info1" attribute | ||
hide_info1 = infobox_is_hidden(ability.Info1) and "true" or "false", | |||
info1_desc = info1_desc, | info1_desc = info1_desc, | ||
info1_mainbox1 = info1_main_boxes[1], | info1_mainbox1 = info1_main_boxes[1], | ||
info1_mainbox2 = info1_main_boxes[2], | info1_mainbox2 = info1_main_boxes[2], | ||
info1_mainbox3 = info1_main_boxes[3], | info1_mainbox3 = info1_main_boxes[3], | ||
info1_mainbox4 = info1_main_boxes[4], | |||
info1_mainbox5 = info1_main_boxes[5], | |||
info1_altbox1 = info1_alt_boxes[1], | info1_altbox1 = info1_alt_boxes[1], | ||
info1_altbox2 = info1_alt_boxes[2], | info1_altbox2 = info1_alt_boxes[2], | ||
| Line 172: | Line 184: | ||
-- Info section #2 defined in "Info2" attribute | -- Info section #2 defined in "Info2" attribute | ||
hide_info2 = infobox_is_hidden(ability.Info2) and "true" or "false", | |||
info2_desc = info2_desc, | info2_desc = info2_desc, | ||
info2_mainbox1 = info2_main_boxes[1], | info2_mainbox1 = info2_main_boxes[1], | ||
info2_mainbox2 = info2_main_boxes[2], | info2_mainbox2 = info2_main_boxes[2], | ||
info2_mainbox3 = info2_main_boxes[3], | info2_mainbox3 = info2_main_boxes[3], | ||
info2_mainbox4 = info2_main_boxes[4], | |||
info2_mainbox5 = info2_main_boxes[5], | |||
info2_altbox1 = info2_alt_boxes[1], | info2_altbox1 = info2_alt_boxes[1], | ||
info2_altbox2 = info2_alt_boxes[2], | info2_altbox2 = info2_alt_boxes[2], | ||
| Line 184: | Line 199: | ||
-- Info section #3 defined in "Info3" attribute | -- Info section #3 defined in "Info3" attribute | ||
hide_info3 = infobox_is_hidden(ability.Info3) and "true" or "false", | |||
info3_desc = info3_desc, | info3_desc = info3_desc, | ||
info3_mainbox1 = info3_main_boxes[1], | info3_mainbox1 = info3_main_boxes[1], | ||
info3_mainbox2 = info3_main_boxes[2], | info3_mainbox2 = info3_main_boxes[2], | ||
info3_mainbox3 = info3_main_boxes[3], | info3_mainbox3 = info3_main_boxes[3], | ||
info3_mainbox4 = info3_main_boxes[4], | |||
info3_mainbox5 = info3_main_boxes[5], | |||
info3_altbox1 = info3_alt_boxes[1], | info3_altbox1 = info3_alt_boxes[1], | ||
info3_altbox2 = info3_alt_boxes[2], | info3_altbox2 = info3_alt_boxes[2], | ||
| Line 205: | Line 223: | ||
} | } | ||
} | } | ||
end | |||
function infobox_is_hidden(infobox) | |||
if infobox == nil then | |||
return false | |||
end | |||
return infobox.RequiresUpgradeIndex ~= nil | |||
end | end | ||
| Line 237: | Line 263: | ||
local ability = utils.get_ability_card_data(hero_key, ability_num) | local ability = utils.get_ability_card_data(hero_key, ability_num) | ||
if(ability == nil) then return | if(ability == nil) then return {} end -- return empty table, not string | ||
local info_section = ability['Info'..info_section_num] | local info_section = ability['Info'..info_section_num] | ||
| Line 268: | Line 294: | ||
function get_main_boxes(hero_key, ability_num, info_section_num) | function get_main_boxes(hero_key, ability_num, info_section_num) | ||
local ability = utils.get_ability_card_data(hero_key, ability_num) | local ability = utils.get_ability_card_data(hero_key, ability_num) | ||
if(ability == nil) then return | if(ability == nil) then return "Ability Not Found" end | ||
local info_section = ability['Info'..info_section_num] | local info_section = ability['Info'..info_section_num] | ||
-- some abilities have no info sections | -- some abilities have no info sections | ||
if info_section == nil then return | if info_section == nil then return '' end | ||
local main = info_section.Main | local main = info_section.Main | ||
| Line 290: | Line 316: | ||
end | end | ||
end | end | ||
local main_boxes = {} | local main_boxes = {} | ||
| Line 300: | Line 327: | ||
end | end | ||
local icon = get_icon(prop.Type) | |||
if value | |||
local main_box | |||
if prop.StatusEffect then | |||
main_box = frame:expandTemplate{ | |||
title = "Ability_card_v2/Card/StatusBox", | |||
args = { | |||
title = prop.Title, | |||
key = prop.Key, | |||
value = value, | |||
status_effect = prop.StatusEffect, | |||
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, | |||
-- allow nil value here as some status effects don't have a value but should not be hidden | |||
hide = value == 0 and "true" or "false", | |||
} | |||
} | |||
else | |||
main_box = frame:expandTemplate{ | |||
title = "Ability_card_v2/Card/MainBox", | title = "Ability_card_v2/Card/MainBox", | ||
args = { | args = { | ||
title = prop.Title, | title = prop.Title, | ||
key = prop.Key, | key = prop.Key, | ||
value = | value = value, | ||
icon = icon.img, | icon = icon.img, | ||
icon_link = icon.link, | icon_link = icon.link, | ||
| Line 314: | Line 360: | ||
icon_size = icon.size, | icon_size = icon.size, | ||
scale_value = prop.Scale and commonutils.round_to_sig_fig(prop.Scale.Value, 3), | scale_value = prop.Scale and commonutils.round_to_sig_fig(prop.Scale.Value, 3), | ||
scale_type = prop.Scale and prop.Scale.Type | scale_type = prop.Scale and prop.Scale.Type, | ||
hide = (value == nil or value == 0) and "true" or "false", | |||
} | } | ||
} | } | ||
end | end | ||
table.insert(main_boxes, main_box) | |||
end | end | ||
| Line 352: | Line 399: | ||
-- Some props don't have values, as those come from upgrades | -- 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 | -- For now, we will ignore these and only show data for the base ability | ||
if prop.Value | if prop.Value then | ||
local icon = get_icon(prop.Type) | local icon = get_icon(prop.Type) | ||
local alt_box = frame:expandTemplate{ | local alt_box = frame:expandTemplate{ | ||
title = "Ability_card_v2/Card/AltBox", | title = "Ability_card_v2/Card/AltBox", | ||
args = { | 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, | |||
hide = prop.Value == 0 and "true" or "false", | |||
} | } | ||
} | } | ||
| Line 418: | Line 466: | ||
title = "Ability_card_v2/Card/UpgradeBox", | title = "Ability_card_v2/Card/UpgradeBox", | ||
args = { | args = { | ||
index = k, | |||
cost = UPGRADE_COST_MAP[k], | |||
description = frame:preprocess(description), | |||
scale_value = upgrade.Scale and commonutils.round_to_sig_fig(upgrade.Scale.Value, 3), | |||
scale_type = upgrade.Scale and upgrade.Scale.Type, | |||
fontsize = fontsize | |||
} | } | ||
} | } | ||
| Line 430: | Line 479: | ||
return upgrade_boxes | return upgrade_boxes | ||
end | end | ||
function create_description(prop, frame) | function create_description(prop, frame) | ||
| Line 463: | Line 513: | ||
end | end | ||
end | end | ||
return description | return description | ||
end | end | ||
| Line 485: | Line 535: | ||
size = mappedAttr.size | size = mappedAttr.size | ||
color = mappedAttr.color or color | color = mappedAttr.color or color | ||
end | end | ||
return {img=img, link=link, color=color, size=size} | return {img=img, link=link, color=color, size=size} | ||
| Line 564: | Line 614: | ||
return mw.getCurrentFrame():expandTemplate{ | return mw.getCurrentFrame():expandTemplate{ | ||
title = " | title = "Ability card v2/Card", | ||
args = { | args = { | ||
hero_key = hero_key, | hero_key = hero_key, | ||
| Line 585: | Line 635: | ||
num_of_charges = ability.AbilityCharges and ability.AbilityCharges.Value, | num_of_charges = ability.AbilityCharges and ability.AbilityCharges.Value, | ||
notes = notes, | notes = notes, | ||
notes_source_page = notes_source_page | notes_source_page = notes_source_page, | ||
} | } | ||
} | } | ||