More actions
Created page with "local p = {} local function getImage(frame, baseName) local png = 'File:' .. baseName .. '.png' local gif = 'File:' .. baseName .. '.gif' local existsPng = frame:preprocess('{{#ifexist:' .. png .. '|yes|no}}') if existsPng == 'yes' then return png end local existsGif = frame:preprocess('{{#ifexist:' .. gif .. '|yes|no}}') if existsGif == 'yes' then return gif end return nil end function p.main(frame) local args = frame:getParent().args local title = mw.titl..." Â |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local yesno = require('Module:Yesno') | |||
local function getImage(frame, baseName) | local function getImage(frame, baseName) | ||
Line 15: | Line 16: | ||
function p.main(frame) | function p.main(frame) | ||
  | |||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local title = mw.title.getCurrentTitle().text | local title = mw.title.getCurrentTitle().text |
Revision as of 07:42, 13 July 2025
Documentation for this module may be created at Module:InfoboxItem/doc
local p = {}
local yesno = require('Module:Yesno')
local function getImage(frame, baseName)
local png = 'File:' .. baseName .. '.png'
local gif = 'File:' .. baseName .. '.gif'
local existsPng = frame:preprocess('{{#ifexist:' .. png .. '|yes|no}}')
if existsPng == 'yes' then return png end
local existsGif = frame:preprocess('{{#ifexist:' .. gif .. '|yes|no}}')
if existsGif == 'yes' then return gif end
return nil
end
function p.main(frame)
local args = frame:getParent().args
local title = mw.title.getCurrentTitle().text
local name = args.name or title
local baseImageName = args.image or ('Invicon_' .. title)
local imageFile = getImage(frame, baseImageName)
local craftable = yesno(args.craftable, false)
local lootable = yesno(args.lootable, false)
local lootContainer = args.lootcontainer or 'Unknown'
local rarity = args.rarity or 'Unknown'
local rarityOutput = frame:expandTemplate{ title = 'Rarity', args = {rarity} }
-- Extract crafting table arguments
local craftArgs = {}
local hasInput = false
local hasOutput = args.Output and args.Output ~= ''
for k, v in pairs(args) do
if type(k) == "string" and mw.ustring.match(k, '^[ABC][123]$') and v and v ~= '' then
craftArgs[k] = v
hasInput = true
end
end
if hasOutput then
craftArgs["Output"] = args.Output
end
local html = mw.html.create('table')
html
:addClass('infobox')
:addClass('infobox-item')
:addClass('floatright')
:css('width', '300px')
:tag('tr')
:tag('th')
:attr('colspan', '2')
:addClass('infobox-header')
:wikitext(name)
:done()
:done()
-- Main block image
html
:tag('tr')
:tag('td')
:attr('colspan', '2')
:css('text-align', 'center')
:wikitext(imageFile and ('[[' .. imageFile .. '|center|frameless|128px]]') or 'No image available')
:done()
:done()
-- Inventory slot under image
html
:tag('tr')
:tag('td')
:attr('colspan', '2')
:css('text-align', 'center')
:wikitext(frame:expandTemplate{title = 'Inventory slot', args = {title}})
:done()
:done()
-- Crafting recipe header and grid
if hasInput and hasOutput and craftable then
html
:tag('tr')
:tag('td')
:attr('colspan', '2')
:addClass('crafting-caption')
:wikitext('Crafting Recipe')
:done()
:done()
:tag('tr')
:tag('td')
:attr('colspan', '2')
:css('text-align', 'center')
:wikitext(frame:expandTemplate{title = 'Crafting table', args = craftArgs})
:done()
:done()
end
-- Craftable, Lootable, Loot Container and Rarity
html
:tag('tr')
:tag('td'):wikitext('Can be crafted'):done()
:tag('td'):wikitext(craftable):done()
:done()
:tag('tr')
:tag('td'):wikitext('Can be looted'):done()
:tag('td'):wikitext(lootable):done()
:done()
if lootable then
html
:tag('tr')
:tag('td'):wikitext('Found in'):done()
:tag('td'):wikitext('[[' .. lootContainer .. ']]'):done()
:done()
end
html
:tag('tr')
:tag('td'):wikitext('Rarity'):done()
:tag('td'):wikitext(rarityOutput):done()
:done()
return tostring(html)
end
return p