No edit summary
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 2: Line 2:


function p.render(frame)
function p.render(frame)
   local args = frame.args
   local args = frame:getParent().args


   local filesParam = args[1] or ""
   local itemParam = args.item or ""
   local linkTarget = args[2]
   local linkParam = args.link or ""
   local tooltip = args[3]
   local tooltipParam = args.tooltip
  local amountParam = args.amount or ""


   local output = {}
   local output = {}


   -- Split by comma
   -- Split items by semicolon
   for filename in string.gmatch(filesParam, '([^,]+)') do
   for filename in string.gmatch(itemParam, '([^;]+)') do
     filename = filename:gsub("^%s*(.-)%s*$", "%1") -- trim spaces
     filename = filename:gsub("^%s*(.-)%s*$", "%1") -- trim spaces


Line 18: Line 19:
     end
     end


     local imgTag
     local imgTag = string.format('[[File:%s|link=%s]]', filename, linkParam)
    if linkTarget and linkTarget ~= "" then
      imgTag = string.format('[[File:%s|link=%s]]', filename, linkTarget)
    else
      imgTag = string.format('[[File:%s]]', filename)
    end
     table.insert(output, imgTag)
     table.insert(output, imgTag)
   end
   end


   local tooltipText = tooltip or filesParam
  local itemContainer = '<div class="image-sequence" style="width:32px;"><div class="image-sequence-group">' .. table.concat(output, "") .. '</div></div>'
   if tooltip then
 
  local amountSpan = ""
  if amountParam ~= "" then
    amountSpan = '<span class="item-slot-count">' .. amountParam .. '</span>'
  end
 
   local tooltipText = tooltipParam or (args.item or "")
   if not tooltipText or tooltipText == "" then
    tooltipText = ""
  end
 
  local result = '<div class="item-slot">' .. itemContainer
 
  if amountSpan ~= "" then
    result = result .. amountSpan
  end
 
  if tooltipText ~= "" then
     result = result .. '<span class="item-tooltip">' .. tooltipText .. '</span>'
     result = result .. '<span class="item-tooltip">' .. tooltipText .. '</span>'
   end
   end


   return '<div class="item-slot">' .. result .. '</div>'
   result = result .. '</div>'
 
  return result
end
end


return p
return p

Latest revision as of 07:03, 27 November 2025

Documentation for this module may be created at Module:ItemSlot/doc

local p = {}

function p.render(frame)
  local args = frame:getParent().args

  local itemParam = args.item or ""
  local linkParam = args.link or ""
  local tooltipParam = args.tooltip
  local amountParam = args.amount or ""

  local output = {}

  -- Split items by semicolon
  for filename in string.gmatch(itemParam, '([^;]+)') do
    filename = filename:gsub("^%s*(.-)%s*$", "%1") -- trim spaces

    if not filename:lower():match("%.png$") then
      filename = filename .. ".png"
    end

    local imgTag = string.format('[[File:%s|link=%s]]', filename, linkParam)
    table.insert(output, imgTag)
  end

  local itemContainer = '<div class="image-sequence" style="width:32px;"><div class="image-sequence-group">' .. table.concat(output, "") .. '</div></div>'

  local amountSpan = ""
  if amountParam ~= "" then
    amountSpan = '<span class="item-slot-count">' .. amountParam .. '</span>'
  end

  local tooltipText = tooltipParam or (args.item or "")
  if not tooltipText or tooltipText == "" then
    tooltipText = ""
  end

  local result = '<div class="item-slot">' .. itemContainer

  if amountSpan ~= "" then
    result = result .. amountSpan
  end

  if tooltipText ~= "" then
    result = result .. '<span class="item-tooltip">' .. tooltipText .. '</span>'
  end

  result = result .. '</div>'

  return result
end

return p