Module:Abilities/card: Difference between revisions

Jump to navigation Jump to search
m Refactored get_scalar func naming
m migrated icon functions to Abilities/icon
Line 2: Line 2:
local commonutils = require "Module:Utilities"
local commonutils = require "Module:Utilities"
local utils = require "Module:Abilities/utils"
local utils = require "Module:Abilities/utils"
local Icon = require"Module:Abilities/icon"


local p = {}
local p = {}
local data = mw.loadJsonData("Data:AbilityCards.json")
local data = mw.loadJsonData("Data:AbilityCards.json")


-- Maps attr type to an appropriate image and page link
-- Optional icon size, will be defaulted on the template
local ATTR_TYPE_ICON_MAP = require("Module:Icon/attr")
-- List of scaling type attributes
local SCALING_ICON_MAP = {
    ["spirit"] = { class = "spirit", icon = "File:Spirit scaling.png", link = "Spirit Power#Spirit Power Scaling", size = "40px" },
    ["stats_count"] = { class = "spirit", icon = "File:Spirit scaling.png", link = "Spirit Power#Spirit Power Scaling", size = "40px" },
    ["weapon_power"] = { class = "weapon", icon = "File:Weapon scaling.png", link = "Weapon Damage#Weapon Damage Scaling", size = "40px" },
    ["weapon_damage_increase"] = { class = "weapon", icon = "File:Weapon scaling.png", link = "Weapon Damage#Weapon Damage Scaling", size = "40px" },
    ["melee"] = { class = "weapon", icon = "File:Melee scaling.png", link = "Melee Damage#Abilities", size = "40px" },
    ["heavy_melee"] = { class = "weapon", icon = "File:Melee scaling.png", link = "Melee Damage#Abilities", size = "40px" },
    ["power_increase"] = { class = "boon", icon = "File:Boon scaling.png", link="Boon", size = "25px" }, -- Boon icon has to be smaller than others
    ["duration"] = { class = "default" }, -- Use "default" if the scaling is unused
}
-- get scaling icon attribute associated with a specified scale type
function p.get_scalar(frame)
    local args = frame.args
    local scaleType = args[1]
    local attribute = args[2]
    local scalingIcon = SCALING_ICON_MAP[scaleType]
    if scalingIcon then
        return scalingIcon[attribute] or "Missing scaling type in Module:Abilities/card"
    end
    return ""
end


function get_hero_key(hero_name)
function get_hero_key(hero_name)
Line 98: Line 68:
  and ability.Other.HexDuration
  and ability.Other.HexDuration
  and ability.Other.HexDuration.Value then
  and ability.Other.HexDuration.Value then
    local icon = get_icon("duration")
    local icon = Icon.getAttrIcon("duration")
    table.insert(info1_main_boxes, 1,
    table.insert(info1_main_boxes, 1,
        frame:expandTemplate{
        frame:expandTemplate{
Line 347: Line 317:
end
end
local icon = get_icon(prop.Type)
local icon = Icon.getAttrIcon(prop.Type)
local main_box
local main_box
Line 420: Line 390:
-- 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 then
if prop.Value then
local icon = get_icon(prop.Type)
local icon = Icon.getAttrIcon(prop.Type)
local alt_box = frame:expandTemplate{
local alt_box = frame:expandTemplate{
title = "Ability_card_v2/Card/AltBox",
title = "Ability_card_v2/Card/AltBox",
Line 536: Line 506:


     return description
     return description
end
p.get_attr_icon = function(frame)
local attr_type = frame.args[1]
local icon = get_icon(attr_type)
if icon == nil then
return ''
end
return string.format('[[File:%s|%s|18px|link=%s]]', icon.img or '', icon.size or '', icon.link or '')
end
function get_icon(attr_type)
local mappedAttr = ATTR_TYPE_ICON_MAP[attr_type]
local img = nil
local link = ''
local size = ''
local color = 'Grey'
if mappedAttr then
img = mappedAttr.img
link = mappedAttr.link
size = mappedAttr.size
color = mappedAttr.color or color
end
if img == nil then
return nil
end
return {img=img, link=link, color=color, size=size}
end
end