Module:ItemTooltip
Jump to navigation
Jump to search
Documentation for this module may be created at Module:ItemTooltip/doc
local p = {}
local data = require("Module:Items/Data")
local items = data.items
--- Gets the table entry for an item or equipment.
-- @function GetItemOrEquipment
-- @param {string} item_name Item name
-- @return {table} Item database entry
-- @local
function GetItemOrEquipment(item_name)
assert(item_name ~= nil, 'Error: Name missing. 1st parameter is required.')
local item = items[item_name]
assert(item ~= nil, 'Error: Incorrect name "' .. item_name .. '". Check capitalization.')
return item
end
--- Gets the item rarity.
-- @function p.GetRarity
-- @param {table} frame Frame object w/ first argument being the item name and 2nd argument being
-- to use simple form of rarity (default false)
-- @return {string} Item rarity name
function p.GetRarity(frame)
local item_name = frame.args[1]
local simple_form = frame.args[2] or false
local item = GetItemOrEquipment(item_name)
if type(item) == 'string' then
return item
end
return item.Rarity
end
--- Gets the item icon.
-- @function p.GetIcon
-- @param {table} frame Frame object w/ first argument being the item name
-- @param[opt] {table} item Item database entry
-- @return {string} Item icon
function p.GetIcon(frame, item)
local item_name = frame.args[1]
item = item or GetItemOrEquipment(item_name)
if type(item) == 'string' then
return item
else
return item.Icon
end
end
--- Gets the item description.
-- @function p.GetDescription
-- @param {table} frame Frame object w/ first argument being the item name
-- @param[opt] {table} item Item database entry
-- @return {string} Item description
function p.GetDescription(frame, item)
local item_name = frame.args[1]
item = item or GetItemOrEquipment(item_name)
if type(item) == 'string' then
return item
else
return item.Desc and frame:preprocess(item.Desc:gsub("\r\n", "<br>")) or ""
end
end
--- Gets the item pickup quote.
-- @function p.GetPickup
-- @param {table} frame Frame object w/ first argument being the item name
-- @param[opt] {table} item Item database entry
-- @return {string} Item pickup quote
function p.GetQuote(frame, item)
local item_name = frame.args[1]
item = item or GetItemOrEquipment(item_name)
if type(item) == 'string' then
return item
else
return item.Pickup
end
end
--- Gets the item cooldown.
-- @function p.GetCooldown
-- @param {table} frame Frame object w/ first argument being the item name and 2nd argument being
-- to use simple form of rarity (default false)
-- @return {string} Item cooldown
function p.GetCooldown(frame)
local item_name = frame.args[1]
local simple_form = frame.args[2] or false
local item = GetItemOrEquipment(item_name)
return item.Cooldown and (item.Cooldown .. "s CD") or ""
end
-- GetTooltip()
local tooltip_template = '<span class="tooltip-block">' ..
'<span class="tooltip-icon">' ..
'<span>[[File:%s|48x48px]]</span>' ..
'</span>' ..
'<span class="tooltip-text">' ..
'%s<span class="cooldown">%s</span><span style="color:#959494;">%s</span><br><span class="makeshift-hr"></span>%s' ..
'</span>' ..
'</span>'
--- Gets the item's tooltip.
-- @function p.GetTooltip
-- @param {table} frame Frame object w/ first argument being the item name
-- @return {string} Wikitext of tooltip
function p.GetTooltip(frame)
local item_name = frame.args[1]
local item = GetItemOrEquipment(item_name)
if type(item) == 'string' then
return item
end
local icon = p.GetIcon(frame, item)
local quote = p.GetQuote(frame, item)
local desc = p.GetDescription(frame, item)
local cooldown = p.GetCooldown(frame, item)
return string.format(tooltip_template,
icon,
item_name,
cooldown,
quote == '' and "" or ("<br>" .. quote),
desc
)
end
return p
--</nowiki>