Module:SpriteFile: Difference between revisions
m Protected "Module:SpriteFile" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)) |
No edit summary |
||
| (20 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 '' | local linkPrefix = ( not link:find( '//' ) and args.linkprefix ) or '' | ||
link = linkPrefix .. link | link = linkPrefix .. link | ||
| Line 42: | Line 51: | ||
end | end | ||
local | local name = args.name or '' | ||
local altText = file .. ': Sprite image for ' .. | if name == 'InvSprite' then | ||
if | name = 'Invicon' | ||
altText = | 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 | end | ||
local sprite = mw.html.create( 'span' ):addClass( 'sprite-file' ) | local sprite = mw.html.create( 'span' ):addClass( 'sprite-file' ) | ||
| Line 53: | Line 77: | ||
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 68: | 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 102: | 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 | ||