Module:Abilities/icon: Difference between revisions

From The Deadlock Wiki
Jump to navigation Jump to search
mNo edit summary
Expose isDisplayedScale so callers can tell hidden stat-category scalings from real coefficients (with help from vergir-bot LLM)
 
(10 intermediate revisions by 3 users not shown)
Line 41: Line 41:
end
end


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


-- List of scaling type attributes
-- List of scaling type attributes
local SCALING_ICON_MAP = {
local SCALING_ICON_MAP = {
     ["spirit"] = { class = "spirit", icon = "File:Spirit scaling.png", link = "Spirit Power#Spirit Power Scaling", size = "40px" },
     ["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 = "40px" },
     ["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 = "40px" },
     ["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 = "40px" },
     ["weapon_damage_increase"] = { class = "weapon", icon = "File:Weapon scaling.png", link = "Weapon Damage#Weapon Damage Scaling", size = "28px" },
     ["melee"] = { class = "weapon", icon = "File:Melee scaling.png", link = "Melee Damage#Abilities", size = "40px" },
     ["melee"] = { class = "melee", icon = "File:Melee scaling.png", link = "Melee Damage#Abilities", size = "28px" },
     ["heavy_melee"] = { class = "weapon", icon = "File:Melee scaling.png", link = "Melee Damage#Abilities", size = "40px" },
     ["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 = "25px" }, -- Boon icon has to be smaller than others
     ["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
    -- Use "default" if the scaling is unused.
    -- The types below are stat-category markers rather than coefficients: they
    -- always carry a value of 1 and only flag which ability stats are affected
    -- by Ability Duration, Ability Cooldown, Ability Range, Healing and charge
    -- bonuses. There is no meaningful number to show, so they stay hidden.
     ["duration"] = { class = "default" },
    ["range"] = { class = "default" },
    ["radius"] = { class = "default" },
    ["cooldown"] = { class = "default" },
    ["charge_cooldown"] = { class = "default" },
    ["max_charges"] = { class = "default" },
    ["healing"] = { class = "default" },
}
}


function getScalarIcon(scaleType)
function getScalarIcon(scaleType)
return SCALING_ICON_MAP[scaleType]
return SCALING_ICON_MAP[scaleType]
end
-- Whether a scale type produces a visible badge.
-- False only for types explicitly mapped as "default". Unknown types count as
-- displayed, so they still surface through the missing-icon warning below
-- instead of being silently dropped.
function p.isDisplayedScale(scaleType)
local icon = getScalarIcon(scaleType)
return icon == nil or icon.class ~= "default"
end
end


Line 69: Line 89:
local icon = getScalarIcon(scaleType, attribute)
local icon = getScalarIcon(scaleType, attribute)
return icon[attribute] or 'Missing scaling attribute ' .. attribute .. ' for type ' .. scaleType
if icon == nil then return '' end
return icon[attribute] or ''
end
end


Line 76: Line 97:
     local args = frame.args
     local args = frame.args
     local scaleType = args[1]  
     local scaleType = args[1]  
    local size = args[2]


local icon = getScalarIcon(scaleType)
local icon = getScalarIcon(scaleType)
Line 84: Line 106:
if icon.class == "default" then
if icon.class == "default" then
return ''
return ''
end
if not size or size == '' then
size = icon.size
end
end
Line 90: Line 116:
         icon.icon,
         icon.icon,
         icon.link,
         icon.link,
         icon.size
         size
     )
     )
end
end


return p
return p

Latest revision as of 21:29, 26 July 2026

Overview

[edit source]

Icon related functions for ability cards

Template:AbilityIcon

Submodules

[edit source]

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
    -- Use "default" if the scaling is unused.
    -- The types below are stat-category markers rather than coefficients: they
    -- always carry a value of 1 and only flag which ability stats are affected
    -- by Ability Duration, Ability Cooldown, Ability Range, Healing and charge
    -- bonuses. There is no meaningful number to show, so they stay hidden.
    ["duration"] = { class = "default" },
    ["range"] = { class = "default" },
    ["radius"] = { class = "default" },
    ["cooldown"] = { class = "default" },
    ["charge_cooldown"] = { class = "default" },
    ["max_charges"] = { class = "default" },
    ["healing"] = { class = "default" },
}

function getScalarIcon(scaleType)
	return SCALING_ICON_MAP[scaleType]
end

-- Whether a scale type produces a visible badge.
-- False only for types explicitly mapped as "default". Unknown types count as
-- displayed, so they still surface through the missing-icon warning below
-- instead of being silently dropped.
function p.isDisplayedScale(scaleType)
	local icon = getScalarIcon(scaleType)
	return icon == nil or icon.class ~= "default"
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