Module:Item ID

From Artifact Wiki
Jump to: navigation, search

Documentation for Module:Item ID [edit] [edit doc]

Info Icon.png See also: Item ID template.

This module provides a item's category without the need of aditional arguments. It is retrieved from the Cargo table 'Items', defined in the Item Infobox template.

Preview


Item ID template:
Blink Dagger

Blink Dagger

This item is not in the database yet.
You can view or create the page here.
Description BG.png
[refresh card]

Usage


{{#invoke:Item ID|main}}

local cargo = mw.ext.cargo
local getArgs = require( 'Module:Arguments' ).main
local getIcon = require( 'Module:Icon').getIcon
local getItemCard = require('Module:Card/Item').getCard
local p = {}


function p.main( frame )
	local args = getArgs()
	return p._main( args )
end


function p._main( args )
	local name = args[1]
	local size = args[2]
	
	return p.getItemID(name, size)
end
	
function p.getItemID(name, size)
	local category = ''
	local icon = ''

	local cargoOutput = p.getCargo(name)

	-- When available, the category gets set to the one found in the database.
	if(cargoOutput ~= nil) then
		-- Category Icons
		if(not p.isempty(cargoOutput['itemType'])) then
			category = cargoOutput['itemType']
			icon = getIcon(category, size or '20px', name, name, "true") .. ' '
		end
	end
  
	-- Formatting the link
	local formattedLink = string.format('[[%s|<span class="item_text" style="font-weight: bold;">%s</span>]]', name, name)



	
	-- The item ID (icon + link).
	local itemID = string.format('<span class="image-link">%s%s</span>', icon, formattedLink)
	
	local itemCard = getItemCard(name, 175)
	
	return string.format([=[<div class="tooltip" style=""> %s <div class="tooltipbox" style="width: 174px; top: 100&#x25;; left: 105&#x25;;> %s </div></div>]=],
		itemID, itemCard or '')
end


-- Retrieves the category from the item through the cargo database (defined via the Item Infobox template).
function p.getCargo(name)
  return cargo.query('cards', 'itemType', { where='cards.type="Item" AND cards.title="' .. name .. '"'})[1]
end

function p.isempty(s)
  return s == nil or s == ''
end

return p