Module:SpriteFile: Difference between revisions
added ability to use .gif files for Item Sprites |
No edit summary |
||
| (12 intermediate revisions by 3 users not shown) | |||
| Line 18: | Line 18: | ||
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%+]', '-' ) | |||
end | end | ||
local mod = id:match( '([^:%]]+):' ) or "Minecraft" | |||
local nameStart = ( id:find( ':' ) or id:find( '%]' ) or 0 ) + 1 | |||
if nameStart - 1 == #id then | |||
nameStart = 1 | |||
end | |||
local nameId = id:sub( nameStart, ( id:find( '[,%[]', nameStart ) or 0 ) - 1 ) | |||
local link = ( args.link or '' ) | local link = ( args.link or '' ) | ||
| Line 44: | Line 51: | ||
end | end | ||
local name = args.name | local name = args.name or '' | ||
if name == 'InvSprite' then | |||
name = 'Invicon' | |||
end | |||
local file = '' | |||
if mod == 'Minecraft' or mod == 'minecraft' then | |||
file = name .. ' ' .. nameId .. '.png' | |||
else | |||
file = name .. ' ' .. mod .. ' ' .. nameId .. '.png' | |||
end | |||
local altText = '' | |||
if link == '' then | |||
altText = file .. ': Sprite image for ' .. nameId .. ' in ' .. mod | |||
end | |||
if id == '' then | |||
file = 'Grid Unknown.png' | |||
altText = 'Unknown sprite image' | |||
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 77: | Line 92: | ||
if args.title then | if args.title then | ||
spriteText:attr( 'title', args.title ) | spriteText:attr( 'title', args.title ) | ||
else | |||
spriteText:attr( 'title', nameId ) | |||
end | end | ||
if link ~= '' then | if link ~= '' then | ||
| Line 106: | Line 123: | ||
local link = args[1] | local link = args[1] | ||
if args[1] and not args.id then | if args[1] and not args.id then | ||
link = args[1]:match( '^(.-)%+' ) or args[1] | |||
end | |||
local text | |||
if not args.notext then | |||
text = args.text or args[2] or '' | |||
if text == '' then | |||
local nameStart = (link:find( ':' ) or 0 ) + 1 | |||
if nameStart - 1 == #link then | |||
nameStart = 1 | |||
end | |||
text = link:sub( nameStart, ( link:find( '[,%[]', nameStart ) or 0 ) - 1 ) | |||
end | |||
end | |||
args[1] = args.id or args[1] | args[1] = args.id or args[1] | ||
args.link = args.link or link | |||
args.text = text | |||
return p.sprite( args ) | |||
end | end | ||
return p | return p | ||