Module:ItemTooltip

local cargo = mw.ext.cargo local p = {}

local template = ' ' .. ' %s' .. ' ' ..                     '' ..                      ' ' ..                      '%s' .. ' ' ..                   ' ' ..                    ' %s ' .. ' ' ..               ' '

local template_tooltip = ' %s ' .. ' ' ..                             ' %s  ' .. ' ' ..                               '%s' .. ' ' ..                           ' ' ..                         ' '

local template_item = ' %s  ' local template_recipe = ' ' .. ' %s: ' .. ' ' ..                           '%s' .. ' &#x25B6; ' .. '%s' .. ' ' ..                         '%s' .. ' '

local function compileRecipe(recipe, targetItemName) local ipm = 0 local ingredients = '' for i=1, 8, 1 do   local item = recipe["ingredient" .. i]   if item ~= nil and #item > 0 then local amount = recipe["quantity" .. i] or 1 ingredients = ingredients .. string.format(template_item, item, amount) end end local products = '' for i=1, 4, 1 do   local item = recipe["product" .. i]   if item ~= nil and #item > 0 then local amount = recipe["productCount" .. i] or 1 products = products .. string.format(template_item, item, amount) if tonumber(recipe.craftingTime) ~= nil and item == targetItemName then ipm = 60 / recipe.craftingTime * tonumber(amount) end end end local productionRate = '' if ipm > 0 then productionRate = ' Production Rate: ' .. ipm .. ' / min ' end return string.format(template_recipe,     recipe.recipeName,      ingredients,      products,      productionRate  ) end

local function getRecipes(itemName) local tables = 'crafting_recipes' local fields = 'recipeName, craftingTime, product=product1, product2, product3, product4, productCount=productCount1, productCount2, productCount3, productCount4, ingredient1, quantity1, ingredient2, quantity2, ingredient3, quantity3, ingredient4, quantity4, ingredient5, quantity5, ingredient6, quantity6, ingredient7, quantity7, ingredient8, quantity8' local args = { where = '(product="' .. itemName .. '" or product2="' .. itemName .. '" or product3="' .. itemName .. '" or product4="' .. itemName .. '") and (experimental is null or experimental=False)', orderBy = 'mainRecipe DESC, alternateRecipe ASC' } local recipes = cargo.query(tables, fields, args) local recipesList = '' for i=1, #recipes, 1 do   recipesList = recipesList .. compileRecipe(recipes[i], itemName) end return recipesList end

function p.getTooltip(frame) local itemName = frame.args.item or frame.args[1] local amount = frame.args.amount or frame.args[2] or nil local size = frame.args.size or frame.args[3] or 40 local count = amount and amount .. ' × ' or '' local tooltipHtml = string.format(template_tooltip,     itemName,      --description, -- no items table for now so no description      '',      getRecipes(itemName)  ) return string.format(template,     count,      itemName,      size,      itemName,      tooltipHtml,      itemName  ) end

return p