Module:SpriteFile: Difference between revisions

mNo edit summary
No edit summary
 
(16 intermediate revisions by 4 users not shown)
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
if not args.keepcase then
id = mw.ustring.lower( id ):gsub( '[%s%+]', '-' )
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 '' )
if mw.ustring.lower( link ) == 'none' then
if mw.ustring.lower( link ) == 'none' then
link = ''
link = ''
else
elseif link ~= '' then
local linkPrefix = ( not link:find( '//' ) and args.linkprefix ) or ''
local linkPrefix = ( not link:find( '//' ) and args.linkprefix ) or ''
link = linkPrefix .. link
link = linkPrefix .. link
Line 42: Line 51:
end
end
local name = args.name
local name = args.name or ''
if name == 'InvSprite' then
if name == 'InvSprite' then
name = 'Invicon'
name = 'Invicon'
end
end
local file = name .. ' ' .. id .. '.png'
local file = ''
local altText = file .. ': Sprite image for ' .. id .. ' in Minecraft'
if link ~= '' then
if mod == 'Minecraft' or mod == 'minecraft' then
altText = altText .. ' linking to ' .. link
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
end
local sprite = mw.html.create( 'span' ):addClass( 'sprite-file' )
local sprite = mw.html.create( 'span' ):addClass( 'sprite-file' )
Line 72: 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 128:
local text
local text
if not args.notext then
if not args.notext then
text = args.text or args[2] or link
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
end