Module:Abilities/icon

From The Deadlock Wiki
Revision as of 21:21, 29 May 2026 by Gammaton32 (talk | contribs) (Hide range scaling)
Jump to navigation Jump to search

Overview

Icon related functions for ability cards

Usage

Template:AbilityIcon

Submodules

Abilities - Simple functions. Eg. getting ability name

Abilities/utils - Common internal functions that are shared amongst any Abilities/ modules

Abilities/card - Generates hero ability cards

Abilities/icon - Functions for retrieving ability and attribute icon data

Abilities/details table (WIP) - Generates details table to show raw ability data


local p = {}

-- 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")

function getAttrIcon(attrType)
	local mappedAttr = ATTR_TYPE_ICON_MAP[attrType]

	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

function p.getAttrIcon(attrType)
	return getAttrIcon(attrType)
end

function p.getAttrIconFile(frame)
    local args = frame.args
    local attrType = args[1]
    
	local attr_type = frame.args[1]
	local icon = getAttrIcon(attr_type)
	if icon == nil then
		return ''	
	end

	return string.format('[[File:%s|%s|link=%s]]', icon.img or '', icon.size or '18px', icon.link or '')
end

-- List of scaling type attributes
local SCALING_ICON_MAP = {
    ["spirit"] = { class = "spirit", icon = "File:Spirit scaling.png", link = "Spirit Power#Spirit Power Scaling", size = "28px" },
    ["stats_count"] = { class = "spirit", icon = "File:Spirit scaling.png", link = "Spirit Power#Spirit Power Scaling", size = "28px" }, -- Mina Rake
    ["weapon_power"] = { class = "weapon", icon = "File:Weapon scaling.png", link = "Weapon Damage#Weapon Damage Scaling", size = "28px" }, -- Paradox Carbine
    ["weapon_damage_increase"] = { class = "weapon", icon = "File:Weapon scaling.png", link = "Weapon Damage#Weapon Damage Scaling", size = "28px" },
    ["melee"] = { class = "melee", icon = "File:Melee scaling.png", link = "Melee Damage#Abilities", size = "28px" },
    ["heavy_melee"] = { class = "melee", icon = "File:Melee scaling.png", link = "Melee Damage#Abilities", size = "28px" },
    ["power_increase"] = { class = "boon", icon = "File:Boon scaling.png", link = "Boon", size = "16px" }, -- Boon icon has to be smaller than others
    ["duration"] = { class = "default" }, -- Use "default" if the scaling is unused
    ["range"] = { class = "default" },
}

function getScalarIcon(scaleType)
	return SCALING_ICON_MAP[scaleType]
end


-- get scaling icon attribute associated with a specified scale type
function p.getScalarIconAttr(frame)
    local args = frame.args

    local scaleType = args[1] 
    local attribute = args[2]
	
	local icon = getScalarIcon(scaleType, attribute)
	if icon == nil then return '' end
	return icon[attribute] or ''
end

-- get scaling icon wikitext file associated with a specified scale type
function p.getScalarIconFile(frame)
    local args = frame.args
    local scaleType = args[1] 
    local size = args[2] 

	local icon = getScalarIcon(scaleType)
    if not icon then
        return frame:preprocess(string.format('{{Tooltip|?|Missing scaling type icon "%s" in Module:Abilities/icon}}', scaleType))
    end

	if icon.class == "default" then
		return ''
	end
	
	if not size or size == '' then
		size = icon.size
	end
	
    return string.format(
        '[[%s|link=%s|%s]]',
        icon.icon,
        icon.link,
        size
    )
end

return p