Module:Aicon: Difference between revisions

From Downtime Wiki
MC>Anterdc99
mNo edit summary
 
m 1 revision imported
 
(No difference)

Latest revision as of 04:45, 25 April 2025

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

local p = {}

local invIcon = require( 'Module:Inventory icon' ).icon

function p.aIcon( icon, background, state, link, file )
	local f = mw.getCurrentFrame()

	local argIcon = icon or 'Grass Block'
	local argBackground = background or 'plain'
	local argState = state or 'raw'
	local argLink = link or ''

	if ( argBackground ~= 'oval' ) and ( argBackground ~= 'fancy' ) and ( argBackground ~= 'plain-mini' ) then
		argBackground = 'plain'
	end
	if argState ~= 'worn' then
		argState = 'raw'
	end
	if ( argBackground == 'plain-mini' ) and ( argState ~= 'raw' ) then
		argState = 'raw'
	end

	local iconBackground = '[[File:Advancement-' .. argBackground .. '-' .. argState .. '.png|link=' .. argLink .. '|class=pixel-image]]'
	local iconContent
	if file and file ~= '' then
		iconContent = '[[File:' .. file .. '|link=' .. argLink .. '|32px|class=pixel-image]]'
	else
		iconContent = invIcon{ argIcon, link = argLink }
	end

	local outputContent = f:extensionTag{ name = 'span', content = iconContent, args = { class = 'module-Aicon-content' } }
	local outputBackground = f:extensionTag{ name = 'span', content = iconBackground .. outputContent, args = { class = 'plainlinks module-Aicon-background' } }

	return require( 'Module:TSLoader' ).call( 'Module:Aicon/styles.css' ) .. outputBackground
end

function p.main( f )
	local args = f
	local frame = mw.getCurrentFrame()
	if f == frame then
		args = require( 'Module:ProcessArgs' ).merge( true )
	end

	return p.aIcon( args[ 1 ], args[ 2 ] or args.bg, args[ 3 ] or args.state, args.link, args.file )
end

return p