Module:AbilityInteraction: Difference between revisions

From The Deadlock Wiki
Jump to navigation Jump to search
Vergir (talk | contribs)
Use American spelling in comments per the style guide (with help from vergir-bot LLM)
Vergir (talk | contribs)
m Add several interactions. Update comments
Line 1: Line 1:
-- Renders a standard interaction box for the interactions tab of {{AbilitySection}}.
-- Entry point: {{#invoke:AbilityInteraction|box}}, via Template:AbilityInteraction.
--
-- Presentation for each interaction lives in REGISTRY below. Call sites pick an
-- interaction by name and supply body text only; nothing else is customizable.
-- Anything bespoke should use {{IconBox}} directly rather than growing parameters here.
--
-- To add an interaction, add a REGISTRY entry:
-- To add an interaction, add a REGISTRY entry:
--  aliases  = other names resolving to this entry; assumed not to overlap
--  aliases  = other names resolving to this entry; assumed not to overlap
Line 12: Line 5:
--  iconfile = image file name, without the File: prefix
--  iconfile = image file name, without the File: prefix
--  link    = wiki page name, or a full URL
--  link    = wiki page name, or a full URL
local p = {}
local getArgs = require('Module:Arguments').getArgs


local REGISTRY = {
local REGISTRY = {
['ability duration'] = {
aliases  = { 'duration', 'duration extender' },
title    = 'Ability Duration',
type    = 'positive',
iconfile = 'Duration Extender.png',
link    = 'Ability Duration',
},
['ability range'] = {
aliases  = { 'range', 'greater expansion' },
title    = 'Ability Range',
type    = 'positive',
iconfile = 'Greater Expansion.png',
link    = 'Ability Range',
},
['debuff resist'] = {
['debuff resist'] = {
aliases  = { 'debuff reducer' },
aliases  = { 'debuff reducer' },
Line 32: Line 36:
link    = 'Dispel Magic',
link    = 'Dispel Magic',
},
},
['unstoppable'] = {
['heroic aura'] = {
aliases  = {},
title    = 'Heroic Aura',
type    = 'positive',
iconfile = 'Heroic Aura.png',
link    = 'Heroic Aura',
},
['indomitable'] = {
aliases  = {},
title    = 'Indomitable',
type    = 'negative',
iconfile = 'Indomitable.png',
link    = 'Indomitable',
},
['interrupt'] = {
aliases  = { 'knockdown', 'stun' },
title    = 'Interrupt',
type    = 'negative',
iconfile = 'Knockdown.png',
link    = 'Knockdown',
},
['monster rounds'] = {
aliases  = {},
aliases  = {},
title    = 'Unstoppable',
title    = 'Monster Rounds',
type    = 'negative',
type    = 'negative',
iconfile = 'Unstoppable.png',
iconfile = 'Monster Rounds.png',
link    = 'Unstoppable',
link    = 'Monster Rounds',
},
},
['slowing hex'] = {
['slowing hex'] = {
Line 46: Line 71:
link    = 'Slowing Hex',
link    = 'Slowing Hex',
},
},
['indomitable'] = {
['unstoppable'] = {
aliases  = {},
aliases  = {},
title    = 'Indomitable',
title    = 'Unstoppable',
type    = 'negative',
type    = 'negative',
iconfile = 'Indomitable.png',
iconfile = 'Unstoppable.png',
link    = 'Indomitable',
link    = 'Unstoppable',
},
},
}
}


-- Lookup index of aliases plus canonical keys, built once.
local p = {}
-- Canonical keys are registered last so they always win.
local getArgs = require('Module:Arguments').getArgs
 
local index = {}
local index = {}
for _, entry in pairs(REGISTRY) do
for _, entry in pairs(REGISTRY) do
Line 106: Line 132:
end
end


-- Registry table for the documentation page. Not used in article space.
-- A function to be used on the Template Doc page to list all available Interactions
function p.list(frame)
function p.list(frame)
local keys = {}
local keys = {}

Revision as of 15:39, 15 July 2026

Documentation for this module may be created at Module:AbilityInteraction/doc

-- To add an interaction, add a REGISTRY entry:
--   aliases  = other names resolving to this entry; assumed not to overlap
--   title    = header text
--   type     = positive | negative | info
--   iconfile = image file name, without the File: prefix
--   link     = wiki page name, or a full URL

local REGISTRY = {
	
	['ability duration'] = {
		aliases  = { 'duration', 'duration extender' },
		title    = 'Ability Duration',
		type     = 'positive',
		iconfile = 'Duration Extender.png',
		link     = 'Ability Duration',
	},
	['ability range'] = {
		aliases  = { 'range', 'greater expansion' },
		title    = 'Ability Range',
		type     = 'positive',
		iconfile = 'Greater Expansion.png',
		link     = 'Ability Range',
	},
	['debuff resist'] = {
		aliases  = { 'debuff reducer' },
		title    = 'Debuff Resist',
		type     = 'negative',
		iconfile = 'Debuff Reducer.png',
		link     = 'Debuff Resist',
	},
	['dispel'] = {
		aliases  = { 'dispel magic', 'purge', 'cleanse' },
		title    = 'Dispel',
		type     = 'negative',
		iconfile = 'Dispel Magic.png',
		link     = 'Dispel Magic',
	},
	['heroic aura'] = {
		aliases  = {},
		title    = 'Heroic Aura',
		type     = 'positive',
		iconfile = 'Heroic Aura.png',
		link     = 'Heroic Aura',
	},
	['indomitable'] = {
		aliases  = {},
		title    = 'Indomitable',
		type     = 'negative',
		iconfile = 'Indomitable.png',
		link     = 'Indomitable',
	},
	['interrupt'] = {
		aliases  = { 'knockdown', 'stun' },
		title    = 'Interrupt',
		type     = 'negative',
		iconfile = 'Knockdown.png',
		link     = 'Knockdown',
	},
	['monster rounds'] = {
		aliases  = {},
		title    = 'Monster Rounds',
		type     = 'negative',
		iconfile = 'Monster Rounds.png',
		link     = 'Monster Rounds',
	},
	['slowing hex'] = {
		aliases  = {},
		title    = 'Slowing Hex',
		type     = 'info',
		iconfile = 'Slowing Hex.png',
		link     = 'Slowing Hex',
	},
	['unstoppable'] = {
		aliases  = {},
		title    = 'Unstoppable',
		type     = 'negative',
		iconfile = 'Unstoppable.png',
		link     = 'Unstoppable',
	},
}

local p = {}
local getArgs = require('Module:Arguments').getArgs

local index = {}
for _, entry in pairs(REGISTRY) do
	for _, alias in ipairs(entry.aliases or {}) do
		index[alias] = entry
	end
end
for key, entry in pairs(REGISTRY) do
	index[key] = entry
end

local function err(msg)
	return '<strong class="error">AbilityInteraction: ' .. mw.text.nowiki(msg) .. '</strong>'
end

function p.box(frame)
	local args = getArgs(frame)

	local state = mw.ustring.lower(mw.text.trim(args.state or ''))
	local key   = mw.ustring.lower(mw.text.trim(args.interaction or ''))

	if key == '' then
		return err('no interaction specified')
	end

	local entry = index[key]
	if entry == nil then
		return err('unknown interaction "' .. key .. '"')
	end

	-- A disabled box means the interaction does not apply, so it carries no
	-- valence; the neutral header overrides the registry type.
	local box_type = entry.type
	if state == 'disabled' then
		box_type = 'info'
	end

	return frame:expandTemplate{
		title = 'IconBox',
		args  = {
			title    = entry.title,
			type     = box_type,
			iconfile = entry.iconfile,
			link     = entry.link,
			state    = state,
			text     = args.text or '',
		},
	}
end

-- A function to be used on the Template Doc page to list all available Interactions
function p.list(frame)
	local keys = {}
	for key in pairs(REGISTRY) do
		table.insert(keys, key)
	end
	table.sort(keys)

	local out = { '{| class="wikitable"', '! Interaction !! Aliases !! Type !! Example' }
	for _, key in ipairs(keys) do
		local entry = REGISTRY[key]
		local aliases = {}
		for _, alias in ipairs(entry.aliases or {}) do
			table.insert(aliases, '<code>' .. alias .. '</code>')
		end
		table.insert(out, '|-')
		table.insert(out, '| <code>' .. key .. '</code>')
		table.insert(out, '| ' .. (#aliases > 0 and table.concat(aliases, ', ') or '—'))
		table.insert(out, '| ' .. entry.type)
		table.insert(out, '| ' .. frame:expandTemplate{
			title = 'AbilityInteraction',
			args  = { interaction = key, text = 'Example text.' },
		})
	end
	table.insert(out, '|}')
	return table.concat(out, '\n')
end

return p