Module:SpriteFile: Difference between revisions

Replace Module:Sprite
 
No edit summary
 
(23 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 = ''
elseif link ~= '' then
local linkPrefix = ( not link:find( '//' ) and args.linkprefix ) or ''
link = linkPrefix .. link
end
end
local scale = args.scale or default.scale
local scale = args.scale or default.scale
local height = ( args.height or args.size or default.size ) * scale
local width = ( args.width or args.size or default.size ) * scale
local width = ( args.width or args.size or default.size ) * scale
local height = ( args.height or args.size or default.size ) * scale
local size = width .. 'x' .. height .. 'px'
local size = width .. 'x' .. height .. 'px'
local file = args.name .. ' ' .. id .. '.png'
local styles = {}
if height ~= default.size then
styles[#styles + 1] = 'height:' .. height .. 'px'
end
if width ~= default.size then
styles[#styles + 1] = 'width:' .. width .. 'px'
end
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' )
sprite:node( '[[File:' .. file .. '|' .. size .. '|link=' .. link .. '|' .. ( args.title or '' ) .. '|class=pixel-image]]' )
local img = '[[File:' .. file .. '|' .. size .. '|link=' .. link .. '|alt=' .. altText .. '|class=pixel-image|' .. ( args.title or '' ) .. ']]'
sprite:node( img )
local styles = {}
local align = args.align or default.align
local align = args.align or default.align
if align ~= default.align then
if align ~= default.align then
styles[#styles + 1] = 'vertical-align:' .. align
styles[#styles + 1] = '--vertical-align:' .. align
end
end
styles[#styles + 1] = args.css
styles[#styles + 1] = args.css
Line 54: 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 59: Line 99:
if link:find( '//' ) then
if link:find( '//' ) then
spriteText = '[' .. link .. ' ' .. tostring( spriteText ) .. ']'
spriteText = '[' .. link .. ' ' .. tostring( spriteText ) .. ']'
else
spriteText = '[[' .. link .. '|' .. tostring( spriteText ) .. ']]'
end
end
-- Internal link
local linkPrefix = args.linkprefix or ''
spriteText = '[[' .. linkPrefix .. link .. '|' .. tostring( spriteText ) .. ']]'
end
end
end
end
Line 90: 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