Module:SpriteFile: Difference between revisions

m 10 revisions imported
added ability to use .gif files for Item Sprites
Line 17: Line 17:
local id = mw.text.trim( tostring( args[1] or '' ) )
local id = mw.text.trim( tostring( args[1] or '' ) )
if not args.keepcase then
id = mw.ustring.lower( id ):gsub( '[%s%+]', '-' )
local useGif = id:match("\\gif$")
    if useGif then
    id = id:gsub("\\gif$", "")
end
end
Line 43: Line 45:
local name = args.name
local name = args.name
if name == 'InvSprite' then
name = 'Invicon'
local fileExtension = useGif and '.gif' or '.png'
end
    local file = name .. ' ' .. id .. fileExtension
local file = name .. ' ' .. id .. '.png'
    local altText = file .. ': Sprite image for ' .. id .. ' in Minecraft'
local altText = file .. ': Sprite image for ' .. id .. ' in Minecraft'
    if link ~= '' then
if link ~= '' then
        altText = altText .. ' linking to ' .. link
altText = altText .. ' linking to ' .. link
    end
end
    if id == '' then
if id == '' then
        file = 'Grid Unknown.png'
file = 'Grid Unknown.png'
        altText = 'Unknown sprite image'
altText = 'Unknown sprite image'
    end
end
local sprite = mw.html.create( 'span' ):addClass( 'sprite-file' )
local sprite = mw.html.create( 'span' ):addClass( 'sprite-file' )
local img = '[[File:' .. file .. '|' .. size .. '|link=' .. link .. '|alt=' .. altText .. '|class=pixel-image|' .. ( args.title or '' ) .. ']]'
local img = '[[File:' .. file .. '|' .. size .. '|link=' .. link .. '|alt=' .. altText .. '|class=pixel-image|' .. ( args.title or '' ) .. ']]'
Line 105: Line 106:
local link = args[1]
local link = args[1]
link = link and link:gsub("\\gif$", "")
if args[1] and not args.id then
if args[1] and not args.id then
link = args[1]:match( '^(.-)%+' ) or args[1]
        link = link:match('^(.-)%+') or link
end
    end
local text
 
if not args.notext then
    local text
text = args.text or args[2] or link
    if not args.notext then
end
        text = args.text or args[2] or link
    end
args[1] = args.id or args[1]
args[1] = args.id or args[1]
args.link = args.link or link
    args.link = args.link or link
args.text = text
    args.text = text
 
return p.sprite( args )
    return p.sprite(args)
end
end


return p
return p