Module:SpriteFile: Difference between revisions
No edit summary |
No edit summary |
||
| (5 intermediate revisions by the same user 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 '' ) | ||
| Line 46: | Line 55: | ||
name = 'Invicon' | name = 'Invicon' | ||
end | end | ||
local file = name .. ' ' .. | local file = '' | ||
if mod == 'Minecraft' or mod == 'minecraft' then | |||
file = name .. ' ' .. nameId .. '.png' | |||
else | |||
file = name .. ' ' .. mod .. ' ' .. nameId .. '.png' | |||
end | |||
local altText = '' | local altText = '' | ||
if link == '' then | if link == '' then | ||
altText = file .. ': Sprite image for ' .. | altText = file .. ': Sprite image for ' .. nameId .. ' in ' .. mod | ||
end | end | ||
if id == '' then | if id == '' then | ||
| Line 76: | 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 110: | 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 | ||