Module:ItemTooltip

-- local p = {}

local all_items = mw.loadData("Module:Items/Data").items local all_equipment = mw.loadData("Module:Equipment/Data").equipment

GetItemOrEquipment -- returns item object (table) or string with error function GetItemOrEquipment(item_name) if item_name == nil then return ' Error: Name missing. 1st parameter is required. ' end local item = all_items[item_name] or all_equipment[item_name] if item == nil then return ' Error: Incorrect name. Check capitalization. ' else return item end end

GetRarity 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 local rarity = item.Rarity if simple_form and rarity == 'Elite Equipment' then rarity = 'Equipment' elseif simple_form and rarity == 'Lunar Equipment' then rarity = 'Lunar' end return rarity end

GetDescription 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 frame:preprocess(item.Desc:gsub("\r\n", " ")) end end

GetQuote 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 frame:preprocess(item.Quote) end end

local GetItemBox local itembox_template = ' ' ..  ..                           ' ' ..                               ..                            ' ' ..                          ' '

local function GetItemBox(frame, name, size) frame.args[1] = name frame.args[2] = 'simple' local rarity = p.GetRarity(frame) local itemSize = math.floor(size * 0.9375) local offset = (size - itemSize) / 2 return string.format(itembox_template,     rarity,      size,      name,      offset,      offset,      name,      itemSize,      name  ) end

GetTooltip local tooltip_template = ' ' .. ' ' ..                             ' %s ' .. '%s' .. ' ' ..                           ' ' ..                              '%s%s' .. ' ' ..                         ' '

function p.GetTooltip(frame) local item_name = frame.args[1] local item = GetItemOrEquipment(item_name) if type(item) == 'string' then return item end local item_box = GetItemBox(frame, item_name, 48) local quote = p.GetQuote(frame, item) local desc = p.GetDescription(frame, item) local cooldown = item.Cooldown and string.format(' %ss ', item.Cooldown) or '' local style = '' local function strip(txt) return txt:gsub('(.-) ', '%1'):gsub('+', '') end -- remove tags and + sign if strip(quote) == strip(desc) then quote = '' style = 'align-self: center;' else quote = string.format('%s ', quote) end return string.format(tooltip_template,   item_box,    cooldown,    style,    quote,    desc  ) end

return p --