Module:Infobox: Difference between revisions
Halve invimage group spacing |
Feel like I need an easier way to see if an image exists due to supporting the fallback individual images |
||
| Line 16: | Line 16: | ||
local imgCount = {} | local imgCount = {} | ||
local invImgCount = {} | local invImgCount = {} | ||
for k, v in pairs( args ) do | for k, v in pairs( args ) do | ||
if type( k ) == 'string' then | if type( k ) == 'string' then | ||
| Line 61: | Line 60: | ||
if #invImgCount > 0 then | if #invImgCount > 0 then | ||
table.sort( invImgCount ) | table.sort( invImgCount ) | ||
local | local slot | ||
local invIds = mw.loadData( 'Module:InvSprite/IDs' ).ids | |||
for k, v in ipairs( invImgCount ) do | for k, v in ipairs( invImgCount ) do | ||
local image = args['invimage' .. v] | local image = args['invimage' .. v] | ||
if image == 'title' then | if image == 'title' then | ||
local imageTitle = mw.title.new( 'File:Grid ' .. title .. '.png' ) | local imageExists | ||
if invIds[title] then | |||
imageExists = true | |||
else | |||
local imageTitle = mw.title.new( 'File:Grid ' .. title .. '.png' ) | |||
imageExists = imageTitle and imageTitle.exists | |||
end | |||
if imageExists then | |||
image = title | image = title | ||
else | else | ||
| Line 76: | Line 82: | ||
table.insert( invImages, '</div><div style="padding-top:.5em">' ) | table.insert( invImages, '</div><div style="padding-top:.5em">' ) | ||
elseif image then | elseif image then | ||
if not | if not slot then | ||
slot = require( 'Module:Inventory slot' ).slot | |||
end | end | ||
table.insert( invImages, | table.insert( invImages, slot{ image, link = 'none' } ) | ||
end | end | ||
end | end | ||
if | if slot and #invImages > 0 then | ||
invImages = '<div class="infobox-invimages"><div>' .. table.concat( invImages, '' ) .. '</div></div>' | invImages = '<div class="infobox-invimages"><div>' .. table.concat( invImages, '' ) .. '</div></div>' | ||
else | else | ||