Jump to content

Module:ItemLink

From Creopedia

This documentation is transcluded from Module:ItemLink/doc.

Renders an item link with Module:IconLink.

Implements Template:ItemLink.


require( 'strict' )

local iconLink = require( 'Module:IconLink' )
local getItemThumbnail = require( 'Module:Item' ).getThumbnail

local p = {}

--- Wikitext entry point for the module
---
--- @param frame mw.frame
--- @return string
function p.main( frame )
	local getArgs = require( 'Module:Arguments' ).getArgs
	return p._main( getArgs( frame ) )
end

--- Render the item link
---
--- Pass `game` to illustrate the link with that game's icon; it defaults to the
--- EvoCreo 2 artwork.
---
--- @param args table
--- @return string
function p._main( args )
	local itemName = args.text or args[1]

	if not itemName then
		error( 'No item name provided' )
	end

	local text = itemName
	local quantity = ''

	if args.quantity then
		quantity = string.format( '%s x ', tostring( args.quantity ) )
	end

	return quantity .. iconLink.main( {
		icon = getItemThumbnail( itemName, args.game ),
		link = args.link or itemName,
		text = text,
		class = 'cp-image-pixelated'
	} )
end

return p